├── .github
├── FUNDING.yml
└── ISSUE_TEMPLATE.md
├── art
├── settings.png
├── context-menu.png
├── formatting.png
├── light-bulb.png
├── quick-info.png
├── validation.png
├── classification.png
├── suppress_error.png
├── csharp-analyzers.png
├── suppress-comment.png
├── editor-context-menu.png
├── navigation-dropdown.png
├── snippets-expansion.png
├── suppress-errorlist.png
├── value-intellisense.png
├── inheritance-visualizer.png
├── keyword-intellisense.png
├── snippets-context-menu.png
├── validation-duplicates.png
└── validation-duplicates-parent.png
├── src
├── Resources
│ ├── Icon.png
│ └── ButtonIcon.png
├── source.extension.ico
├── icons.pkgdef
├── Formatting
│ ├── FormattingType.cs
│ ├── FormatterOptions.cs
│ └── FormatterCommand.cs
├── Schema
│ ├── Category.cs
│ ├── Value.cs
│ ├── Severity.cs
│ ├── EditorConfig-schema.json
│ ├── Keyword.cs
│ └── SchemaCatalog.cs
├── Validation
│ ├── NamingStyles
│ │ ├── ModifierKind.cs
│ │ ├── NamingStyle.cs
│ │ ├── Accessibility.cs
│ │ ├── NamingStyleRules.cs
│ │ ├── SerializableNamingRule.cs
│ │ ├── NamingRule.cs
│ │ ├── SymbolKindOrTypeKind.cs
│ │ ├── ReportDiagnostic.cs
│ │ ├── NamingStylePreferences.cs
│ │ └── SymbolSpecification.cs
│ ├── ErrorCategory.cs
│ ├── Tagger
│ │ ├── ErrorTaggerProvider.cs
│ │ ├── ErrorFormatDefinition.cs
│ │ └── ErrorTagger.cs
│ ├── Error.cs
│ ├── ErrorList
│ │ ├── SinkManager.cs
│ │ ├── DisplayError.cs
│ │ ├── ErrorList.cs
│ │ └── TableEntriesSnapshot.cs
│ ├── Commands
│ │ └── SuppressError.cs
│ ├── ValidationOptions.cs
│ └── ErrorCatalog.cs
├── LanguageService
│ ├── Colorizer.cs
│ ├── ContentTypes.cs
│ ├── Source.cs
│ └── LanguageService.cs
├── Shared
│ ├── Extensions.cs
│ ├── ITooltip.cs
│ ├── Telemetry.cs
│ ├── EditorTooltip.xaml
│ ├── EditorTooltip.xaml.cs
│ ├── JoinableTaskFactoryExtensions.cs
│ └── TextViewUtil.cs
├── Commands
│ ├── BaseCommand.cs
│ ├── HideDefaultCommands.cs
│ ├── OpenSettings.cs
│ ├── NavigateToParent.cs
│ ├── F1Help.cs
│ └── CreateEditorConfigFileAnyCode.cs
├── Constants.cs
├── Outlining
│ ├── OutliningTaggerProvider.cs
│ └── OutliningTagger.cs
├── BraceCompletion
│ ├── BraceCompletionContext.cs
│ ├── BraceMatchingTaggerProvider.cs
│ └── BraceCompletionContextProvider.cs
├── Classifier
│ ├── EditorConfigProvider.cs
│ └── EditorConfigClassifier.cs
├── SignatureHelp
│ ├── SignatureHelpSourceProvider.cs
│ ├── SectionParameter.cs
│ ├── SectionSignatureHelpSource.cs
│ └── SignatureHelpController.cs
├── SuggestedActions
│ ├── SuggestedActionsSourceProvider.cs
│ ├── SuppressErrorAction.cs
│ ├── AddMissingRulesActionCSharp.cs
│ ├── AddMissingRulesActionDotNet.cs
│ ├── AddMissingRulesActionVB.cs
│ ├── SortAllPropertiesAction.cs
│ ├── DeleteSectionAction.cs
│ ├── RemoveDuplicatePropertiesAction.cs
│ ├── BaseSuggestedAction.cs
│ ├── SortPropertiesAction.cs
│ ├── AddMissingRulesActionAll.cs
│ └── SuggestedActionsSource.cs
├── Monikers.imagemanifest
├── QuickInfo
│ ├── EditorConfigQuickInfoSourceProvider.cs
│ ├── EditorConfigQuickInfoControllerProvider.cs
│ ├── EditorConfigQuickInfoController.cs
│ └── EditorConfigQuickInfo.cs
├── Properties
│ └── AssemblyInfo.cs
├── CodeExpansions
│ └── Snippets
│ │ ├── basicdocument.snippet
│ │ ├── dotnetstyle.snippet
│ │ └── csharpstyle.snippet
├── source.extension.cs
├── Completion
│ ├── CompletionSourceProvider.cs
│ ├── CompletionElementProvider.cs
│ └── CompletionOptions.cs
├── Parser
│ ├── Section.cs
│ ├── Property.cs
│ ├── EditorConfigDocumentInheritance.cs
│ ├── ParseItem.cs
│ └── EditorConfigDocument.cs
├── DragDrop
│ ├── EditorConfigDropHandlerProvider.cs
│ └── EditorConfigDropHandler.cs
├── ProvideBraceCompletionAttribute.cs
├── Adornments
│ └── InheritanceAdornmentProvider.cs
├── source.extension.vsixmanifest
├── CommandTable.cs
└── EditorConfigPackage.cs
├── Directory.Build.props
├── lib
├── Microsoft.VisualStudio.Telemetry.dll
├── Microsoft.VisualStudio.Text.Internal.dll
├── Microsoft.VisualStudio.Platform.VSEditor.dll
└── Microsoft.VisualStudio.Platform.VSEditor.Interop.dll
├── .gitignore
├── Test
└── EditorConfigTest
│ ├── Helpers
│ ├── Extensions.cs
│ ├── Samples.cs
│ └── Mef.cs
│ ├── ValidationTest.cs
│ ├── app.config
│ ├── ParseItemTest.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── CompletionTest.cs
│ ├── DocumentTest.cs
│ └── EditorConfigTest.csproj
├── .gitattributes
├── LICENSE
├── appveyor.yml
├── THIRD-PARTY-NOTICES.txt
├── EditorConfig.sln
└── .editorconfig
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: madskristensen
4 |
--------------------------------------------------------------------------------
/art/settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/settings.png
--------------------------------------------------------------------------------
/art/context-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/context-menu.png
--------------------------------------------------------------------------------
/art/formatting.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/formatting.png
--------------------------------------------------------------------------------
/art/light-bulb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/light-bulb.png
--------------------------------------------------------------------------------
/art/quick-info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/quick-info.png
--------------------------------------------------------------------------------
/art/validation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/validation.png
--------------------------------------------------------------------------------
/art/classification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/classification.png
--------------------------------------------------------------------------------
/art/suppress_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/suppress_error.png
--------------------------------------------------------------------------------
/src/Resources/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/src/Resources/Icon.png
--------------------------------------------------------------------------------
/art/csharp-analyzers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/csharp-analyzers.png
--------------------------------------------------------------------------------
/art/suppress-comment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/suppress-comment.png
--------------------------------------------------------------------------------
/src/source.extension.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/src/source.extension.ico
--------------------------------------------------------------------------------
/art/editor-context-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/editor-context-menu.png
--------------------------------------------------------------------------------
/art/navigation-dropdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/navigation-dropdown.png
--------------------------------------------------------------------------------
/art/snippets-expansion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/snippets-expansion.png
--------------------------------------------------------------------------------
/art/suppress-errorlist.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/suppress-errorlist.png
--------------------------------------------------------------------------------
/art/value-intellisense.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/value-intellisense.png
--------------------------------------------------------------------------------
/art/inheritance-visualizer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/inheritance-visualizer.png
--------------------------------------------------------------------------------
/art/keyword-intellisense.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/keyword-intellisense.png
--------------------------------------------------------------------------------
/art/snippets-context-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/snippets-context-menu.png
--------------------------------------------------------------------------------
/art/validation-duplicates.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/validation-duplicates.png
--------------------------------------------------------------------------------
/src/Resources/ButtonIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/src/Resources/ButtonIcon.png
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | 7.3
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/icons.pkgdef:
--------------------------------------------------------------------------------
1 |
2 | [$RootKey$\ShellFileAssociations\.editorconfig]
3 | "DefaultIconMoniker"="666770e6-562f-46d7-a555-3a0cdffe94d2:1"
--------------------------------------------------------------------------------
/art/validation-duplicates-parent.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/art/validation-duplicates-parent.png
--------------------------------------------------------------------------------
/lib/Microsoft.VisualStudio.Telemetry.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/lib/Microsoft.VisualStudio.Telemetry.dll
--------------------------------------------------------------------------------
/lib/Microsoft.VisualStudio.Text.Internal.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/lib/Microsoft.VisualStudio.Text.Internal.dll
--------------------------------------------------------------------------------
/lib/Microsoft.VisualStudio.Platform.VSEditor.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/lib/Microsoft.VisualStudio.Platform.VSEditor.dll
--------------------------------------------------------------------------------
/lib/Microsoft.VisualStudio.Platform.VSEditor.Interop.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/master/lib/Microsoft.VisualStudio.Platform.VSEditor.Interop.dll
--------------------------------------------------------------------------------
/src/Formatting/FormattingType.cs:
--------------------------------------------------------------------------------
1 | namespace EditorConfig
2 | {
3 | public enum FormattingType
4 | {
5 | None,
6 | Section,
7 | Document
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Schema/Category.cs:
--------------------------------------------------------------------------------
1 | namespace EditorConfig
2 | {
3 | public enum Category
4 | {
5 | None,
6 | Standard,
7 | CSharp,
8 | DotNet,
9 | VisualBasic
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Validation/NamingStyles/ModifierKind.cs:
--------------------------------------------------------------------------------
1 | namespace EditorConfig.Validation.NamingStyles
2 | {
3 | public enum ModifierKind
4 | {
5 | IsAbstract,
6 | IsStatic,
7 | IsAsync,
8 | IsReadOnly,
9 | IsConst,
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Validation/ErrorCategory.cs:
--------------------------------------------------------------------------------
1 | namespace EditorConfig
2 | {
3 | /// The error type determines how the error is represented in the Error List.
4 | public enum ErrorCategory
5 | {
6 | Error,
7 | Warning,
8 | Suggestion,
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Validation/NamingStyles/NamingStyle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace EditorConfig.Validation.NamingStyles
4 | {
5 | internal readonly struct NamingStyle
6 | {
7 | public NamingStyle(Guid id)
8 | {
9 | ID = id;
10 | }
11 |
12 | public Guid ID { get; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Validation/NamingStyles/Accessibility.cs:
--------------------------------------------------------------------------------
1 | namespace EditorConfig.Validation.NamingStyles
2 | {
3 | public enum Accessibility
4 | {
5 | NotApplicable,
6 | Private,
7 | ProtectedAndInternal,
8 | Protected,
9 | Internal,
10 | ProtectedOrInternal,
11 | Public,
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | packages
2 |
3 | # User files
4 | *.suo
5 | *.user
6 | *.sln.docstates
7 | .vs/
8 |
9 | # Build results
10 | [Dd]ebug/
11 | [Rr]elease/
12 | x64/
13 | [Bb]in/
14 | [Oo]bj/
15 |
16 | # MSTest test Results
17 | [Tt]est[Rr]esult*/
18 | [Bb]uild[Ll]og.*
19 |
20 | # NCrunch
21 | *.ncrunchsolution
22 | *.ncrunchproject
23 | _NCrunch_WebCompiler
--------------------------------------------------------------------------------
/src/LanguageService/Colorizer.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Package;
2 | using Microsoft.VisualStudio.TextManager.Interop;
3 |
4 | namespace EditorConfig
5 | {
6 | public class EditorConfigColorizer : Colorizer
7 | {
8 | public EditorConfigColorizer(LanguageService svc, IVsTextLines buffer, IScanner scanner) :
9 | base(svc, buffer, scanner)
10 | { }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Shared/Extensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace EditorConfig
4 | {
5 | public static class Extensions
6 | {
7 | /// Performs a OrdinalIgnoreCase comparison between two strings.
8 | public static bool Is(this string a, string b)
9 | {
10 | return string.Equals(a, b, StringComparison.OrdinalIgnoreCase);
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/LanguageService/ContentTypes.cs:
--------------------------------------------------------------------------------
1 | //using System.ComponentModel.Composition;
2 | //using Microsoft.VisualStudio.Utilities;
3 |
4 | //namespace EditorConfig
5 | //{
6 | // public class ContentTypes
7 | // {
8 | // [Export(typeof(ContentTypes))]
9 | // [Name(Constants.LanguageName)]
10 | // [BaseDefinition("text")]
11 | // public ContentTypes IEditorConfigContentType { get; set; }
12 | // }
13 | //}
14 |
--------------------------------------------------------------------------------
/src/Validation/NamingStyles/NamingStyleRules.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Immutable;
2 |
3 | namespace EditorConfig.Validation.NamingStyles
4 | {
5 | internal readonly struct NamingStyleRules
6 | {
7 | public NamingStyleRules(ImmutableArray namingRules)
8 | {
9 | NamingRules = namingRules;
10 | }
11 |
12 | public ImmutableArray NamingRules { get; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Test/EditorConfigTest/Helpers/Extensions.cs:
--------------------------------------------------------------------------------
1 | using EditorConfig;
2 | using System.Threading.Tasks;
3 |
4 | namespace EditorConfigTest
5 | {
6 | public static class Extensions
7 | {
8 | public static async Task WaitForParsingComplete(this EditorConfigDocument document)
9 | {
10 | while (document.IsParsing)
11 | {
12 | await Task.Delay(2);
13 | }
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### Installed product versions
2 | - Visual Studio: [example 2015 Professional]
3 | - This extension: [example 1.1.21]
4 |
5 | ### Description
6 | Replace this text with a short description
7 |
8 | ### Steps to recreate
9 | 1. Replace this
10 | 2. text with
11 | 3. the steps
12 | 4. to recreate
13 |
14 | ### Current behavior
15 | Explain what it's doing and why it's wrong
16 |
17 | ### Expected behavior
18 | Explain what it should be doing after it's fixed.
--------------------------------------------------------------------------------
/src/Commands/BaseCommand.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.OLE.Interop;
2 | using System;
3 |
4 | namespace EditorConfig
5 | {
6 | abstract class BaseCommand : IOleCommandTarget
7 | {
8 | public IOleCommandTarget Next { get; set; }
9 |
10 | public abstract int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut);
11 |
12 | public abstract int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Constants.cs:
--------------------------------------------------------------------------------
1 | namespace EditorConfig
2 | {
3 | public class Constants
4 | {
5 | public const string LanguageName = "EditorConfig";
6 | public const string FileName = ".editorconfig";
7 | public const string Homepage = "http://editorconfig.org";
8 | public const string DefaultFileContent = "[*]\r\nend_of_line = crlf\r\n\r\n[*.xml]\r\nindent_style = space";
9 | public const string HelpLink = "https://github.com/madskristensen/EditorConfigLanguage/wiki/Error-codes#{0}";
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2016 Mads Kristensen
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
--------------------------------------------------------------------------------
/src/Shared/ITooltip.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Imaging.Interop;
2 |
3 | namespace EditorConfig
4 | {
5 | public interface ITooltip
6 | {
7 | /// The name to display in bold letters in the tooltip.
8 | string Name { get; }
9 |
10 | /// The description of the tooltip.
11 | string Description { get; }
12 |
13 | /// The image moniker to represent the tooltip.
14 | ImageMoniker Moniker { get; }
15 |
16 | /// True if its supported by Visual Studio.
17 | bool IsSupported { get; }
18 | }
19 | }
--------------------------------------------------------------------------------
/src/LanguageService/Source.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Package;
2 | using Microsoft.VisualStudio.TextManager.Interop;
3 |
4 | namespace EditorConfig
5 | {
6 | internal class EditorConfigSource : Source
7 | {
8 | public EditorConfigSource(LanguageService service, IVsTextLines textLines, Colorizer colorizer)
9 | : base(service, textLines, colorizer)
10 | { }
11 |
12 | public override CommentInfo GetCommentFormat()
13 | {
14 | return new CommentInfo
15 | {
16 | UseLineComments = true,
17 | LineStart = "#"
18 | };
19 | }
20 | }
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | image: Visual Studio 2017
2 |
3 | install:
4 | - ps: (new-object Net.WebClient).DownloadString("https://raw.github.com/madskristensen/ExtensionScripts/master/AppVeyor/vsix.ps1") | iex
5 |
6 | before_build:
7 | - ps: Vsix-IncrementVsixVersion | Vsix-UpdateBuildVersion
8 | - ps: Vsix-TokenReplacement src\source.extension.cs 'Version = "([0-9\\.]+)"' 'Version = "{version}"'
9 |
10 | build_script:
11 | - nuget restore -Verbosity quiet
12 | - msbuild /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /v:m
13 |
14 | test:
15 | categories:
16 | except:
17 | - MEF
18 |
19 | after_test:
20 | - ps: Vsix-PushArtifacts | Vsix-PublishToGallery
21 |
--------------------------------------------------------------------------------
/src/Outlining/OutliningTaggerProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Text;
2 | using Microsoft.VisualStudio.Text.Tagging;
3 | using Microsoft.VisualStudio.Utilities;
4 | using System.ComponentModel.Composition;
5 |
6 | namespace EditorConfig
7 | {
8 | [Export(typeof(ITaggerProvider))]
9 | [TagType(typeof(IOutliningRegionTag))]
10 | [ContentType(Constants.LanguageName)]
11 | internal sealed class OutliningTaggerProvider : ITaggerProvider
12 | {
13 | public ITagger CreateTagger(ITextBuffer buffer) where T : ITag
14 | {
15 | return buffer.Properties.GetOrCreateSingletonProperty(() => new OutliningTagger(buffer)) as ITagger;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Validation/NamingStyles/SerializableNamingRule.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace EditorConfig.Validation.NamingStyles
4 | {
5 | internal sealed class SerializableNamingRule
6 | {
7 | public string Name;
8 | public Guid SymbolSpecificationID;
9 | public Guid NamingStyleID;
10 | public ReportDiagnostic EnforcementLevel;
11 |
12 | public NamingRule GetRule(NamingStylePreferences info)
13 | {
14 | return new NamingRule(
15 | Name,
16 | info.GetSymbolSpecification(SymbolSpecificationID),
17 | info.GetNamingStyle(NamingStyleID),
18 | EnforcementLevel);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/BraceCompletion/BraceCompletionContext.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.Composition;
2 | using Microsoft.VisualStudio.Text.BraceCompletion;
3 |
4 | namespace EditorConfig
5 | {
6 | [Export(typeof(IBraceCompletionContext))]
7 | internal class BraceCompletionContext : IBraceCompletionContext
8 | {
9 | public bool AllowOverType(IBraceCompletionSession session)
10 | {
11 | return true;
12 | }
13 |
14 | public void Finish(IBraceCompletionSession session)
15 | {
16 | }
17 |
18 | public void OnReturn(IBraceCompletionSession session)
19 | {
20 | }
21 |
22 | public void Start(IBraceCompletionSession session)
23 | {
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Validation/NamingStyles/NamingRule.cs:
--------------------------------------------------------------------------------
1 | namespace EditorConfig.Validation.NamingStyles
2 | {
3 | internal readonly struct NamingRule
4 | {
5 | public readonly string Name;
6 | public readonly SymbolSpecification SymbolSpecification;
7 | public readonly NamingStyle NamingStyle;
8 | public readonly ReportDiagnostic EnforcementLevel;
9 |
10 | public NamingRule(string name, SymbolSpecification symbolSpecification, NamingStyle namingStyle, ReportDiagnostic enforcementLevel)
11 | {
12 | Name = name;
13 | SymbolSpecification = symbolSpecification;
14 | NamingStyle = namingStyle;
15 | EnforcementLevel = enforcementLevel;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Validation/NamingStyles/SymbolKindOrTypeKind.cs:
--------------------------------------------------------------------------------
1 | namespace EditorConfig.Validation.NamingStyles
2 | {
3 | internal enum SymbolKindOrTypeKind
4 | {
5 | #region Symbol kinds
6 |
7 | Namespace,
8 | Event,
9 | Field,
10 | Local,
11 | Method,
12 | Parameter,
13 | Property,
14 |
15 | #endregion
16 |
17 | #region Type kinds
18 |
19 | Class,
20 | Delegate,
21 | Enum,
22 | Interface,
23 | Module,
24 | Pointer,
25 | Struct,
26 | TypeParameter,
27 |
28 | #endregion
29 |
30 | #region Method kinds
31 |
32 | Ordinary,
33 | LocalFunction,
34 |
35 | #endregion
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Classifier/EditorConfigProvider.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.Composition;
2 | using Microsoft.VisualStudio.Text;
3 | using Microsoft.VisualStudio.Text.Classification;
4 | using Microsoft.VisualStudio.Utilities;
5 |
6 | namespace EditorConfig
7 | {
8 | [Export(typeof(IClassifierProvider))]
9 | [ContentType(Constants.LanguageName)]
10 | internal class EditorConfigProvider : IClassifierProvider
11 | {
12 | [Import]
13 | private IClassificationTypeRegistryService ClassificationRegistry { get; set; }
14 |
15 | public IClassifier GetClassifier(ITextBuffer buffer)
16 | {
17 | return buffer.Properties.GetOrCreateSingletonProperty(() => new EditorConfigClassifier(ClassificationRegistry, buffer));
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/SignatureHelp/SignatureHelpSourceProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Language.Intellisense;
2 | using Microsoft.VisualStudio.Text;
3 | using Microsoft.VisualStudio.Utilities;
4 | using System.ComponentModel.Composition;
5 |
6 | namespace EditorConfig
7 | {
8 | [Export(typeof(ISignatureHelpSourceProvider))]
9 | [Name("EditorConfig section Signature Help Source")]
10 | [ContentType(Constants.LanguageName)]
11 | [Order(Before = "default")]
12 | internal class SectionSignatureHelpSourceProvider : ISignatureHelpSourceProvider
13 | {
14 | public ISignatureHelpSource TryCreateSignatureHelpSource(ITextBuffer textBuffer)
15 | {
16 | return textBuffer.Properties.GetOrCreateSingletonProperty(() => new SectionSignatureHelpSource(textBuffer));
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/SuggestedActions/SuggestedActionsSourceProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Language.Intellisense;
2 | using Microsoft.VisualStudio.Text;
3 | using Microsoft.VisualStudio.Text.Editor;
4 | using Microsoft.VisualStudio.Utilities;
5 | using System.ComponentModel.Composition;
6 |
7 | namespace EditorConfig
8 | {
9 | [Export(typeof(ISuggestedActionsSourceProvider))]
10 | [Name("Editor Config Suggested Actions")]
11 | [ContentType(Constants.LanguageName)]
12 | class SuggestedActionsSourceProvider : ISuggestedActionsSourceProvider
13 | {
14 | public ISuggestedActionsSource CreateSuggestedActionsSource(ITextView textView, ITextBuffer buffer)
15 | {
16 | return textView.Properties.GetOrCreateSingletonProperty(() => new SuggestedActionsSource(textView, buffer));
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Monikers.imagemanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Test/EditorConfigTest/Helpers/Samples.cs:
--------------------------------------------------------------------------------
1 | namespace EditorConfigTest
2 | {
3 | public class Samples
4 | {
5 | public const string OneSectionStandard = @"root = true
6 |
7 | # comment
8 | [*.cs]
9 | indent_style = space
10 | indent_size = 4
11 | end_of_line = crlf
12 | insert_final_newline = true";
13 |
14 | public const string MultipleValuesSection = @"[*.cs]
15 | csharp_new_line_before_open_brace = accessors, indexers";
16 |
17 | public const string SeveritySimple = @"[*.cs]
18 | dotnet_style_qualification_for_event = true";
19 |
20 | public const string Suppression = @"# Suppress: EC101 EC102";
21 |
22 | public const string NamingRules = @"[*.cs]
23 | dotnet_naming_rule.foo.severity = warning
24 | dotnet_naming_rule.foo.symbols = fooSymbolsTitle
25 | dotnet_naming_rule.foo.style = fooStyleTitle";
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/QuickInfo/EditorConfigQuickInfoSourceProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Language.Intellisense;
2 | using Microsoft.VisualStudio.Text;
3 | using Microsoft.VisualStudio.Text.Classification;
4 | using Microsoft.VisualStudio.Utilities;
5 | using System.ComponentModel.Composition;
6 |
7 | namespace EditorConfig
8 | {
9 | [Export(typeof(IQuickInfoSourceProvider))]
10 | [Name("EditorConfig QuickInfo Source")]
11 | [Order(Before = "Default Quick Info Presenter")]
12 | [ContentType(Constants.LanguageName)]
13 | internal class EditorConfigQuickInfoSourceProvider : IQuickInfoSourceProvider
14 | {
15 | public IQuickInfoSource TryCreateQuickInfoSource(ITextBuffer textBuffer)
16 | {
17 | return textBuffer.Properties.GetOrCreateSingletonProperty(() => new EditorConfigQuickInfo(textBuffer));
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using EditorConfig;
2 | using Microsoft.VisualStudio.Shell;
3 | using System;
4 | using System.Reflection;
5 | using System.Runtime.CompilerServices;
6 | using System.Runtime.InteropServices;
7 |
8 | [assembly: AssemblyTitle(Vsix.Name)]
9 | [assembly: AssemblyDescription(Vsix.Description)]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany(Vsix.Author)]
12 | [assembly: AssemblyProduct(Vsix.Name)]
13 | [assembly: AssemblyCopyright(Vsix.Author)]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 | [assembly: ProvideCodeBase(AssemblyName = "EditorConfig")]
17 |
18 | [assembly: InternalsVisibleTo("EditorConfigTest")]
19 |
20 | [assembly: ComVisible(false)]
21 | [assembly: CLSCompliant(false)]
22 |
23 | [assembly: AssemblyVersion(Vsix.Version)]
24 | [assembly: AssemblyFileVersion(Vsix.Version)]
25 |
--------------------------------------------------------------------------------
/src/Validation/Tagger/ErrorTaggerProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Text;
2 | using Microsoft.VisualStudio.Text.Editor;
3 | using Microsoft.VisualStudio.Text.Tagging;
4 | using Microsoft.VisualStudio.Utilities;
5 | using System.ComponentModel.Composition;
6 |
7 | namespace EditorConfig
8 | {
9 | [Export(typeof(ITaggerProvider))]
10 | [ContentType(Constants.LanguageName)]
11 | [TagType(typeof(ErrorTag))]
12 | class ErrorTaggerProvider : ITaggerProvider
13 | {
14 | public ITagger CreateTagger(ITextBuffer buffer) where T : ITag
15 | {
16 | if (buffer.Properties.TryGetProperty(typeof(IWpfTextView), out IWpfTextView view))
17 | {
18 | return buffer.Properties.GetOrCreateSingletonProperty(() => new ErrorTagger(view)) as ITagger;
19 | }
20 |
21 | return null;
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/src/CodeExpansions/Snippets/basicdocument.snippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Basic document
6 | basicdocument
7 | Code snippet for a basic .editorconfig document
8 | Mads Kristensen
9 |
10 | Expansion
11 |
12 |
13 |
14 |
15 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Test/EditorConfigTest/ValidationTest.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using System.Threading.Tasks;
3 | using EditorConfig;
4 | using Microsoft.VisualStudio.TestTools.UnitTesting;
5 | using Microsoft.VisualStudio.Text;
6 |
7 | namespace EditorConfigTest
8 | {
9 | [TestClass]
10 | public class ValidationTest
11 | {
12 | //[TestMethod, TestCategory("MEF")]
13 | //public async Task ValidateSeverity()
14 | //{
15 | // EditorConfigPackage.ValidationOptions = new ValidationOptions();
16 | // ITextBuffer buffer = Mef.CreateTextBuffer(Samples.SeveritySimple);
17 | // var doc = EditorConfigDocument.FromTextBuffer(buffer);
18 | // var validator = EditorConfigValidator.FromDocument(doc);
19 |
20 | // await validator.RequestValidationAsync(true);
21 |
22 | // await Task.Delay(1000);
23 |
24 | // Assert.IsTrue(doc.ParseItems[2].HasErrors);
25 | //}
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/source.extension.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This file was generated by Extensibility Tools v1.10.211
4 | //
5 | // ------------------------------------------------------------------------------
6 | namespace EditorConfig
7 | {
8 | static class Vsix
9 | {
10 | public const string Id = "1209461d-57f8-46a4-814a-dbe5fecef941";
11 | public const string Name = "EditorConfig Language Service";
12 | public const string Description = @"Language service for .editorconfig files.
13 |
14 | EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs.";
15 | public const string Language = "en-US";
16 | public const string Version = "1.17";
17 | public const string Author = "Mads Kristensen";
18 | public const string Tags = "editorconfig";
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Completion/CompletionSourceProvider.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.Composition;
2 | using Microsoft.VisualStudio.Language.Intellisense;
3 | using Microsoft.VisualStudio.Text;
4 | using Microsoft.VisualStudio.Text.Classification;
5 | using Microsoft.VisualStudio.Text.Operations;
6 | using Microsoft.VisualStudio.Utilities;
7 |
8 | namespace EditorConfig
9 | {
10 | [Export(typeof(ICompletionSourceProvider))]
11 | [ContentType(Constants.LanguageName)]
12 | [Name("Editor Config")]
13 | public class EditorConfigCompletionSourceProvider : ICompletionSourceProvider
14 | {
15 | [Import]
16 | ITextStructureNavigatorSelectorService NavigatorService { get; set; }
17 |
18 | public ICompletionSource TryCreateCompletionSource(ITextBuffer textBuffer)
19 | {
20 | return textBuffer.Properties.GetOrCreateSingletonProperty(() => new EditorConfigCompletionSource(textBuffer, NavigatorService));
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Validation/NamingStyles/ReportDiagnostic.cs:
--------------------------------------------------------------------------------
1 | namespace EditorConfig.Validation.NamingStyles
2 | {
3 | internal enum ReportDiagnostic
4 | {
5 | ///
6 | /// Report a diagnostic by default.
7 | ///
8 | Default = 0,
9 |
10 | ///
11 | /// Report a diagnostic as an error.
12 | ///
13 | Error = 1,
14 |
15 | ///
16 | /// Report a diagnostic as a warning even though /warnaserror is specified.
17 | ///
18 | Warn = 2,
19 |
20 | ///
21 | /// Report a diagnostic as an info.
22 | ///
23 | Info = 3,
24 |
25 | ///
26 | /// Report a diagnostic as hidden.
27 | ///
28 | Hidden = 4,
29 |
30 | ///
31 | /// Suppress a diagnostic.
32 | ///
33 | Suppress = 5,
34 | }
35 | }
--------------------------------------------------------------------------------
/Test/EditorConfigTest/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/BraceCompletion/BraceMatchingTaggerProvider.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.Composition;
2 | using Microsoft.VisualStudio.Text;
3 | using Microsoft.VisualStudio.Text.Editor;
4 | using Microsoft.VisualStudio.Text.Tagging;
5 | using Microsoft.VisualStudio.Utilities;
6 |
7 | namespace EditorConfig
8 | {
9 | [Export(typeof(IViewTaggerProvider))]
10 | [ContentType(Constants.LanguageName)]
11 | [TagType(typeof(TextMarkerTag))]
12 | class BraceMatchingTaggerProvider : IViewTaggerProvider
13 | {
14 | public ITagger CreateTagger(ITextView textView, ITextBuffer buffer) where T : ITag
15 | {
16 | if (!EditorConfigPackage.Language.Preferences.EnableShowMatchingBrace)
17 | return null;
18 |
19 | //provide highlighting only on the top-level buffer
20 | if (textView.TextBuffer != buffer)
21 | return null;
22 |
23 | return new BraceMatchingTagger(textView, buffer) as ITagger;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Completion/CompletionElementProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Language.Intellisense;
2 | using Microsoft.VisualStudio.Utilities;
3 | using System.ComponentModel.Composition;
4 | using System.Windows;
5 |
6 | namespace EditorConfig
7 | {
8 | [Export(typeof(IUIElementProvider))]
9 | [Name("EditorConfigCompletionTooltipCustomization")]
10 | [ContentType(Constants.LanguageName)]
11 | public class CompletionElementProvider : IUIElementProvider
12 | {
13 | public UIElement GetUIElement(Completion itemToRender, ICompletionSession context, UIElementType elementType)
14 | {
15 | if (elementType == UIElementType.Tooltip &&
16 | itemToRender.Properties.TryGetProperty("item", out ITooltip item) &&
17 | !string.IsNullOrEmpty(item.Description))
18 | {
19 | return new Shared.EditorTooltip(item);
20 | }
21 |
22 | return null;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/SignatureHelp/SectionParameter.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Language.Intellisense;
2 | using Microsoft.VisualStudio.Text;
3 |
4 | namespace EditorConfig
5 | {
6 |
7 | internal class GenericParameter : IParameter
8 | {
9 | private SectionSignature _signature;
10 |
11 | public GenericParameter(SectionSignature signature)
12 | {
13 | _signature = signature;
14 | }
15 |
16 | public string Documentation
17 | {
18 | get { return null; }
19 | }
20 |
21 | public Span Locus
22 | {
23 | get { return new Span(0, _signature.PropertyName.Length); }
24 | }
25 |
26 | public string Name
27 | {
28 | get { return _signature.PropertyName; }
29 | }
30 |
31 | public Span PrettyPrintedLocus
32 | {
33 | get { return Locus; }
34 | }
35 |
36 | public ISignature Signature
37 | {
38 | get { return _signature; }
39 | }
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/Test/EditorConfigTest/ParseItemTest.cs:
--------------------------------------------------------------------------------
1 | using EditorConfig;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using Microsoft.VisualStudio.Text;
4 |
5 | namespace EditorConfigTest
6 | {
7 | [TestClass]
8 | public class ParseItemTest
9 | {
10 | [TestMethod]
11 | public void Equals()
12 | {
13 | var a = new ParseItem(default(EditorConfigDocument), ItemType.Keyword, new Span(10, 10), "a text");
14 | var b = new ParseItem(default(EditorConfigDocument), ItemType.Section, new Span(20, 10), "b text");
15 | var c = new ParseItem(default(EditorConfigDocument), ItemType.Keyword, new Span(10, 10), "a text");
16 |
17 | Assert.IsTrue(a == c);
18 | Assert.IsFalse(a != c);
19 | Assert.IsTrue(a != b);
20 | Assert.IsFalse(a == b);
21 | Assert.IsTrue(a.GetHashCode() != b.GetHashCode());
22 | Assert.IsTrue(a.Equals(a));
23 | Assert.IsTrue(a.Equals(c));
24 | Assert.IsFalse(a.Equals(b));
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Completion/CompletionOptions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell;
2 | using System.ComponentModel;
3 |
4 | namespace EditorConfig
5 | {
6 | public class CompletionOptions : DialogPage
7 | {
8 | // General
9 | private const string _intellisense = "Intellisense";
10 |
11 | [Category(_intellisense)]
12 | [DisplayName("Auto-insert delimiters")]
13 | [Description("This will automatically insert \"=\" and \":\" characters on commit.")]
14 | [DefaultValue(true)]
15 | public bool AutoInsertDelimiters { get; set; } = true;
16 |
17 | [Category(_intellisense)]
18 | [DisplayName("Show undocumented properties")]
19 | [Description("This will show undocumented properties in Intellisense.")]
20 | [DefaultValue(false)]
21 | public bool ShowHiddenKeywords { get; set; }
22 |
23 | public override void SaveSettingsToStorage()
24 | {
25 | Telemetry.TrackOperation("CompletionOptionsSaved");
26 | base.SaveSettingsToStorage();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Parser/Section.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Text;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace EditorConfig
6 | {
7 | /// A section is a globbing pattern matching one or more files.
8 | public class Section
9 | {
10 | public Section(ParseItem section)
11 | {
12 | Item = section;
13 | Properties = new List();
14 | }
15 |
16 | /// The ParseItem containing the section display text.
17 | public ParseItem Item { get; }
18 |
19 | /// A list of properties under the Section.
20 | public IList Properties { get; }
21 |
22 | /// The full span of the section including the properties.
23 | public Span Span
24 | {
25 | get
26 | {
27 | Property last = Properties.LastOrDefault();
28 | return last != null ? new Span(Item.Span.Start, last.Span.End - Item.Span.Start) : Item.Span;
29 | }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/DragDrop/EditorConfigDropHandlerProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Text.Editor;
2 | using Microsoft.VisualStudio.Text.Editor.DragDrop;
3 | using Microsoft.VisualStudio.Text.Operations;
4 | using Microsoft.VisualStudio.Utilities;
5 | using System.ComponentModel.Composition;
6 |
7 | namespace EditorConfig
8 | {
9 | [Export(typeof(IDropHandlerProvider))]
10 | [DropFormat("CF_VSSTGPROJECTITEMS")]
11 | [DropFormat("FileDrop")]
12 | [Name("EditorConfigDropHandler")]
13 | [ContentType(Constants.LanguageName)]
14 | [Order(Before = "DefaultFileDropHandler")]
15 | internal class EditorConfigDropHandlerProvider : IDropHandlerProvider
16 | {
17 | [Import(typeof(ITextBufferUndoManagerProvider))]
18 | private ITextBufferUndoManagerProvider UndoProvider { get; set; }
19 |
20 | public IDropHandler GetAssociatedDropHandler(IWpfTextView view)
21 | {
22 | ITextBufferUndoManager undoManager = UndoProvider.GetTextBufferUndoManager(view.TextBuffer);
23 |
24 | return view.Properties.GetOrCreateSingletonProperty(() => new EditorConfigDropHandler(view, undoManager));
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Validation/Tagger/ErrorFormatDefinition.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Microsoft.VisualStudio.Text.Adornments;
4 | using Microsoft.VisualStudio.Text.Classification;
5 | using Microsoft.VisualStudio.Utilities;
6 | using System.ComponentModel.Composition;
7 | using System.Windows.Media;
8 |
9 | namespace EditorConfig
10 | {
11 | public class ErrorFormatDefinition
12 | {
13 | public const string Suggestion = Constants.LanguageName + " Suggestion";
14 |
15 | [Export(typeof(ErrorTypeDefinition))]
16 | [Name(Suggestion)]
17 | [DisplayName(Suggestion)]
18 | internal static ErrorTypeDefinition MessageDefinition = null;
19 |
20 | [Export(typeof(EditorFormatDefinition))]
21 | [Name(Suggestion)]
22 | [Order(After = Priority.High)]
23 | [UserVisible(true)]
24 | internal class MessageFormat : EditorFormatDefinition
25 | {
26 | public MessageFormat()
27 | {
28 | DisplayName = Suggestion;
29 | ForegroundColor = (Color)ColorConverter.ConvertFromString("#CCc0c0c0");
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/QuickInfo/EditorConfigQuickInfoControllerProvider.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.ComponentModel.Composition;
3 | using Microsoft.VisualStudio.Language.Intellisense;
4 | using Microsoft.VisualStudio.Text;
5 | using Microsoft.VisualStudio.Text.Editor;
6 | using Microsoft.VisualStudio.Utilities;
7 |
8 | namespace EditorConfig
9 | {
10 | [Export(typeof(IIntellisenseControllerProvider))]
11 | [Name("EditorConfig QuickInfo Controller")]
12 | [ContentType(Constants.LanguageName)]
13 | public class EditorConfigQuickInfoControllerProvider : IIntellisenseControllerProvider
14 | {
15 | [Import]
16 | public IQuickInfoBroker QuickInfoBroker { get; set; }
17 |
18 | public IIntellisenseController TryCreateIntellisenseController(ITextView textView, IList subjectBuffers)
19 | {
20 | if (EditorConfigPackage.Language.Preferences.EnableQuickInfo && subjectBuffers.Count > 0)
21 | {
22 | return textView.Properties.GetOrCreateSingletonProperty(() => new EditorConfigQuickInfoController(textView, subjectBuffers, this));
23 | }
24 |
25 | return null;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Shared/Telemetry.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Telemetry;
2 | using System;
3 |
4 | namespace EditorConfig
5 | {
6 | public static class Telemetry
7 | {
8 | private const string _namespace = "WebTools/EditorConfig/";
9 |
10 | public static void TrackUserTask(string name, TelemetryResult result = TelemetryResult.Success)
11 | {
12 | string actualName = name.Replace(" ", "_");
13 | TelemetryService.DefaultSession.PostUserTask(_namespace + actualName, result);
14 | }
15 |
16 | public static void TrackOperation(string name, TelemetryResult result = TelemetryResult.Success)
17 | {
18 | string actualName = name.Replace(" ", "_");
19 | TelemetryService.DefaultSession.PostOperation(_namespace + actualName, result);
20 | }
21 |
22 | public static void TrackException(string name, Exception exception)
23 | {
24 | if (string.IsNullOrWhiteSpace(name) || exception == null)
25 | return;
26 |
27 | string actualName = name.Replace(" ", "_");
28 | TelemetryService.DefaultSession.PostFault(_namespace + actualName, exception.Message, exception);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/ProvideBraceCompletionAttribute.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell;
2 | using System;
3 | using System.Globalization;
4 |
5 | namespace EditorConfig
6 | {
7 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
8 | public class ProvideBraceCompletionAttribute : RegistrationAttribute
9 | {
10 | private string languageName;
11 | public ProvideBraceCompletionAttribute(string languageName)
12 | {
13 | this.languageName = languageName;
14 | }
15 |
16 | public override void Register(RegistrationContext context)
17 | {
18 | string keyName = string.Format(CultureInfo.InvariantCulture, "{0}\\{1}\\{2}", "Languages", "Language Services", languageName);
19 | using (Key langKey = context.CreateKey(keyName))
20 | {
21 | langKey.SetValue("ShowBraceCompletion", 1);
22 | }
23 | }
24 |
25 | public override void Unregister(RegistrationContext context)
26 | {
27 | string keyName = string.Format(CultureInfo.InvariantCulture, "{0}\\{1}\\{2}", "Languages", "Language Services", languageName);
28 | context.RemoveKey(keyName);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Schema/Value.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Imaging;
2 | using Microsoft.VisualStudio.Imaging.Interop;
3 | using System;
4 |
5 | namespace EditorConfig
6 | {
7 | /// The value of a property.
8 | public class Value : ITooltip
9 | {
10 | private bool _isUnset;
11 |
12 | public Value(string name)
13 | {
14 | _isUnset = name.Is("unset");
15 |
16 | Name = name;
17 | Description = GetDescription();
18 | IsSupported = !_isUnset;
19 | Moniker = KnownMonikers.EnumerationItemPublic;
20 | }
21 |
22 | /// The value text.
23 | public string Name { get; }
24 |
25 | /// The value description.
26 | public string Description { get; }
27 |
28 | /// The image moniker shown in Intellisense and QuickInfo.
29 | public ImageMoniker Moniker { get; }
30 |
31 | /// True if the value is supported by Visual Studio.
32 | public bool IsSupported { get; }
33 |
34 | private string GetDescription()
35 | {
36 | if (_isUnset)
37 | return Resources.Text.ValueUnset;
38 |
39 | return null;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Adornments/InheritanceAdornmentProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Text;
2 | using Microsoft.VisualStudio.Text.Editor;
3 | using Microsoft.VisualStudio.Utilities;
4 | using System.ComponentModel.Composition;
5 |
6 | namespace EditorConfig
7 | {
8 | [Export(typeof(IWpfTextViewCreationListener))]
9 | [ContentType(Constants.LanguageName)]
10 | [TextViewRole(PredefinedTextViewRoles.PrimaryDocument)]
11 | class AdornmentProvider : IWpfTextViewCreationListener
12 | {
13 | [Import]
14 | public ITextDocumentFactoryService DocumentService { get; set; }
15 |
16 | public void TextViewCreated(IWpfTextView textView)
17 | {
18 | if (DocumentService.TryGetTextDocument(textView.TextBuffer, out ITextDocument doc))
19 | {
20 | textView.Properties.GetOrCreateSingletonProperty(() => new InheritanceAdornment(textView, doc));
21 | }
22 | }
23 | }
24 |
25 | class InheritanceAdornmentLayer
26 | {
27 | public const string LayerName = "EditorConfig Inheritance Layer";
28 |
29 | [Export(typeof(AdornmentLayerDefinition))]
30 | [Name(LayerName)]
31 | [Order(Before = PredefinedAdornmentLayers.Caret)]
32 | public AdornmentLayerDefinition editorAdornmentLayer = null;
33 | }
34 | }
--------------------------------------------------------------------------------
/src/Shared/EditorTooltip.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/SuggestedActions/SuppressErrorAction.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Threading;
4 | using Microsoft.VisualStudio.Imaging;
5 | using Microsoft.VisualStudio.Imaging.Interop;
6 |
7 | namespace EditorConfig
8 | {
9 | class SuppressErrorAction : BaseSuggestedAction
10 | {
11 | private const string _suppressFormat = "# Suppress: {0}";
12 | private EditorConfigDocument _document;
13 | string _errorCode;
14 |
15 | public SuppressErrorAction(EditorConfigDocument document, string errorCode)
16 | {
17 | _document = document;
18 | _errorCode = errorCode;
19 | }
20 |
21 | public override string DisplayText
22 | {
23 | get { return $"Suppress {_errorCode}"; }
24 | }
25 |
26 | public override ImageMoniker IconMoniker => KnownMonikers.ValidationRule;
27 |
28 | public override bool IsEnabled
29 | {
30 | get
31 | {
32 | return !_document.Suppressions.Contains(_errorCode, StringComparer.OrdinalIgnoreCase);
33 | }
34 | }
35 |
36 | public override void Execute(CancellationToken cancellationToken)
37 | {
38 | var validator = EditorConfigValidator.FromDocument(_document);
39 | validator.SuppressError(_errorCode);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/SuggestedActions/AddMissingRulesActionCSharp.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading;
3 | using Microsoft.VisualStudio.Text;
4 | using Microsoft.VisualStudio.Text.Editor;
5 |
6 | namespace EditorConfig
7 | {
8 | class AddMissingRulesActionCSharp : BaseSuggestedAction
9 | {
10 | private List _missingRules;
11 | private EditorConfigDocument _document;
12 | private ITextView _view;
13 |
14 | public AddMissingRulesActionCSharp(List missingRules, EditorConfigDocument document, ITextView view)
15 | {
16 | _missingRules = missingRules;
17 | _document = document;
18 | _view = view;
19 | }
20 |
21 | public override string DisplayText
22 | {
23 | get { return "C#"; }
24 | }
25 |
26 | public override void Execute(CancellationToken cancellationToken)
27 | {
28 | SnapshotPoint caretPost = _view.Caret.Position.BufferPosition;
29 |
30 | using (ITextEdit edit = _view.TextBuffer.CreateEdit())
31 | {
32 | AddMissingRulesActionAll.AddMissingRules(_document, _missingRules, edit);
33 |
34 | if (edit.HasEffectiveChanges)
35 | edit.Apply();
36 | }
37 |
38 | _view.Caret.MoveTo(new SnapshotPoint(_view.TextBuffer.CurrentSnapshot, caretPost));
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/SuggestedActions/AddMissingRulesActionDotNet.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading;
3 | using Microsoft.VisualStudio.Text;
4 | using Microsoft.VisualStudio.Text.Editor;
5 |
6 | namespace EditorConfig
7 | {
8 | class AddMissingRulesActionDotNet : BaseSuggestedAction
9 | {
10 | private List _missingRules;
11 | private EditorConfigDocument _document;
12 | private ITextView _view;
13 |
14 | public AddMissingRulesActionDotNet(List missingRules, EditorConfigDocument document, ITextView view)
15 | {
16 | _missingRules = missingRules;
17 | _document = document;
18 | _view = view;
19 | }
20 |
21 | public override string DisplayText
22 | {
23 | get { return ".NET"; }
24 | }
25 |
26 | public override void Execute(CancellationToken cancellationToken)
27 | {
28 | SnapshotPoint caretPost = _view.Caret.Position.BufferPosition;
29 |
30 | using (ITextEdit edit = _view.TextBuffer.CreateEdit())
31 | {
32 | AddMissingRulesActionAll.AddMissingRules(_document, _missingRules, edit);
33 |
34 | if (edit.HasEffectiveChanges)
35 | edit.Apply();
36 | }
37 |
38 | _view.Caret.MoveTo(new SnapshotPoint(_view.TextBuffer.CurrentSnapshot, caretPost));
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/SuggestedActions/AddMissingRulesActionVB.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading;
4 | using Microsoft.VisualStudio.Text;
5 | using Microsoft.VisualStudio.Text.Editor;
6 |
7 | namespace EditorConfig
8 | {
9 | class AddMissingRulesActionVB : BaseSuggestedAction
10 | {
11 | private List _missingRules;
12 | private EditorConfigDocument _document;
13 | private ITextView _view;
14 |
15 | public AddMissingRulesActionVB(List missingRules, EditorConfigDocument document, ITextView view)
16 | {
17 | _missingRules = missingRules;
18 | _document = document;
19 | _view = view;
20 | }
21 |
22 | public override string DisplayText
23 | {
24 | get { return "VB"; }
25 | }
26 |
27 | public override void Execute(CancellationToken cancellationToken)
28 | {
29 | SnapshotPoint caretPost = _view.Caret.Position.BufferPosition;
30 |
31 | using (ITextEdit edit = _view.TextBuffer.CreateEdit())
32 | {
33 | AddMissingRulesActionAll.AddMissingRules(_document, _missingRules, edit);
34 |
35 | if (edit.HasEffectiveChanges)
36 | edit.Apply();
37 | }
38 |
39 | _view.Caret.MoveTo(new SnapshotPoint(_view.TextBuffer.CurrentSnapshot, caretPost));
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Test/EditorConfigTest/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("EditorConfigTest")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("EditorConfigTest")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("d4005889-6273-4725-af75-8a2ee92fa639")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/Schema/Severity.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Imaging;
2 | using Microsoft.VisualStudio.Imaging.Interop;
3 |
4 | namespace EditorConfig
5 | {
6 | /// The severity determines how the property is enforced by Visual Studio.
7 | public class Severity : ITooltip
8 | {
9 | public Severity(string name, string description)
10 | {
11 | Name = name;
12 | Description = description;
13 | }
14 |
15 | /// The severity name.
16 | public string Name { get; }
17 |
18 | /// The severity description.
19 | public string Description { get; }
20 |
21 | /// True if Visual Studio supports the severity.
22 | public bool IsSupported => true;
23 |
24 | /// The image moniker shown by Intellisense and the adornment next to the severity.
25 | public ImageMoniker Moniker
26 | {
27 | get
28 | {
29 | switch (Name)
30 | {
31 | case "none":
32 | return KnownMonikers.None;
33 | case "suggestion":
34 | return KnownMonikers.StatusInformation;
35 | case "warning":
36 | return KnownMonikers.StatusWarning;
37 | case "error":
38 | return KnownMonikers.StatusError;
39 | }
40 |
41 | return KnownMonikers.UnknownMember;
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Test/EditorConfigTest/CompletionTest.cs:
--------------------------------------------------------------------------------
1 | using EditorConfig;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 |
4 | namespace EditorConfigTest
5 | {
6 | [TestClass]
7 | public class CompletionTest
8 | {
9 | [TestMethod]
10 | public void GetHighlightedSpans()
11 | {
12 | var spans = FilteredCompletionSet.GetHighlightedSpans("dotnet_style_predefined_type_for_locals_parameters_members", "dottymem");
13 | Assert.AreEqual(3, spans.Count);
14 |
15 | var ttw = FilteredCompletionSet.GetHighlightedSpans("trim_trailing_whitespace", "trimtrailingwhitespace");
16 | Assert.AreEqual(3, ttw.Count);
17 | Assert.AreEqual(4, ttw[0].Length);
18 |
19 | var partlyNonMatch = FilteredCompletionSet.GetHighlightedSpans("dotnet_style_explicit_tuple_names", "dottymem");
20 | Assert.AreEqual(0, partlyNonMatch.Count);
21 |
22 | var partlyNonMatch2 = FilteredCompletionSet.GetHighlightedSpans("dotnet_style_qualification_for_event", "dotmem");
23 | Assert.AreEqual(0, partlyNonMatch2.Count);
24 |
25 | var partlyNonMatch3 = FilteredCompletionSet.GetHighlightedSpans("dotnet_style_qualification_for_method", "dotmem");
26 | Assert.AreEqual(0, partlyNonMatch3.Count);
27 |
28 | var nonMatch = FilteredCompletionSet.GetHighlightedSpans("test", "l");
29 | Assert.AreEqual(0, nonMatch.Count);
30 |
31 | var cha = FilteredCompletionSet.GetHighlightedSpans("charset", "CHAR");
32 | Assert.AreEqual(1, cha.Count);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Validation/NamingStyles/NamingStylePreferences.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Immutable;
3 | using System.Linq;
4 |
5 | namespace EditorConfig.Validation.NamingStyles
6 | {
7 | internal class NamingStylePreferences
8 | {
9 | public readonly ImmutableArray SymbolSpecifications;
10 | public readonly ImmutableArray NamingStyles;
11 | public readonly ImmutableArray NamingRules;
12 |
13 | private readonly Lazy _lazyRules;
14 |
15 | internal NamingStylePreferences(
16 | ImmutableArray symbolSpecifications,
17 | ImmutableArray namingStyles,
18 | ImmutableArray namingRules)
19 | {
20 | SymbolSpecifications = symbolSpecifications;
21 | NamingStyles = namingStyles;
22 | NamingRules = namingRules;
23 |
24 | _lazyRules = new Lazy(CreateRules, isThreadSafe: true);
25 | }
26 |
27 | public NamingStyleRules Rules => _lazyRules.Value;
28 |
29 | internal NamingStyle GetNamingStyle(Guid namingStyleID)
30 | => NamingStyles.Single(s => s.ID == namingStyleID);
31 |
32 | internal SymbolSpecification GetSymbolSpecification(Guid symbolSpecificationID)
33 | => SymbolSpecifications.Single(s => s.ID == symbolSpecificationID);
34 |
35 | private NamingStyleRules CreateRules()
36 | => new NamingStyleRules(NamingRules.Select(r => r.GetRule(this)).ToImmutableArray());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/SuggestedActions/SortAllPropertiesAction.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Imaging;
2 | using Microsoft.VisualStudio.Imaging.Interop;
3 | using Microsoft.VisualStudio.Text;
4 | using Microsoft.VisualStudio.Text.Editor;
5 | using System.Threading;
6 |
7 | namespace EditorConfig
8 | {
9 | class SortAllPropertiesAction : BaseSuggestedAction
10 | {
11 | private EditorConfigDocument _document;
12 | private ITextView _view;
13 |
14 | public SortAllPropertiesAction(EditorConfigDocument document, ITextView view)
15 | {
16 | _document = document;
17 | _view = view;
18 | }
19 |
20 | public override string DisplayText
21 | {
22 | get { return "Sort Properties in All Sections"; }
23 | }
24 |
25 | public override ImageMoniker IconMoniker
26 | {
27 | get { return KnownMonikers.SortAscending; }
28 | }
29 |
30 | public override void Execute(CancellationToken cancellationToken)
31 | {
32 | SnapshotPoint caretPost = _view.Caret.Position.BufferPosition;
33 |
34 | using (ITextEdit edit = _document.TextBuffer.CreateEdit())
35 | {
36 | foreach (Section section in _document.Sections)
37 | {
38 | SortPropertiesAction.SortSection(section, edit);
39 | }
40 |
41 | if (edit.HasEffectiveChanges)
42 | edit.Apply();
43 | }
44 |
45 | _view.Caret.MoveTo(new SnapshotPoint(_view.TextBuffer.CurrentSnapshot, caretPost));
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Commands/HideDefaultCommands.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio;
2 | using Microsoft.VisualStudio.OLE.Interop;
3 | using Microsoft.VisualStudio.Shell;
4 | using System;
5 | using System.Collections.Generic;
6 |
7 | namespace EditorConfig
8 | {
9 | internal sealed class HideDefaultCommands : BaseCommand
10 | {
11 | private static Guid _commandGuid = typeof(VSConstants.VSStd97CmdID).GUID;
12 | private static HashSet _commands = new HashSet
13 | {
14 | (uint)VSConstants.VSStd97CmdID.GotoDefn,
15 | (uint)VSConstants.VSStd97CmdID.GotoDecl,
16 | (uint)VSConstants.VSStd97CmdID.GotoRef,
17 | (uint)VSConstants.VSStd97CmdID.FindReferences,
18 | (uint)VSConstants.VSStd97CmdID.RunToCursor,
19 | };
20 |
21 | public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
22 | {
23 | ThreadHelper.ThrowIfNotOnUIThread();
24 |
25 | return Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
26 | }
27 |
28 | public override int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
29 | {
30 | if (pguidCmdGroup == _commandGuid && _commands.Contains(prgCmds[0].cmdID))
31 | {
32 | prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED | (uint)OLECMDF.OLECMDF_INVISIBLE;
33 | return VSConstants.S_OK;
34 | }
35 |
36 | ThreadHelper.ThrowIfNotOnUIThread();
37 |
38 | return Next.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText);
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Shared/EditorTooltip.xaml.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.PlatformUI;
2 | using System.Windows.Controls;
3 |
4 | namespace EditorConfig.Shared
5 | {
6 | ///
7 | /// Interaction logic for EditorTooltip.xaml
8 | ///
9 | public partial class EditorTooltip : UserControl
10 | {
11 | private const int _iconSize = 32;
12 |
13 | internal EditorTooltip(ITooltip item)
14 | {
15 | InitializeComponent();
16 |
17 | Loaded += (s, e) =>
18 | {
19 | ItemName.Content = PrettifyName(item);
20 | ItemName.SetResourceReference(TextBlock.ForegroundProperty, EnvironmentColors.SystemMenuTextBrushKey);
21 |
22 | string description = item.Description;
23 |
24 | if (!item.IsSupported)
25 | description += $"\r\n\r\n{EditorConfig.Resources.Text.NotSupportedByVS}";
26 |
27 | Description.Text = description;
28 | Description.SetResourceReference(TextBlock.ForegroundProperty, EnvironmentColors.SystemMenuTextBrushKey);
29 |
30 | Glyph.Source = item.Moniker.ToBitmap(_iconSize);
31 | };
32 | }
33 |
34 | private static string PrettifyName(ITooltip item)
35 | {
36 | string text = item.Name
37 | .Replace("_", " ")
38 | .Replace("dotnet", ".NET")
39 | .Replace("csharp", "C#");
40 |
41 | if (text.Length > 0)
42 | text = text[0].ToString().ToUpperInvariant() + text.Substring(1);
43 |
44 | return text;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/THIRD-PARTY-NOTICES.txt:
--------------------------------------------------------------------------------
1 | EditorConfig Language Service uses third-party libraries or other resources
2 | that may be distributed under licenses different than the EditorConfig
3 | Language Service software.
4 |
5 | In the event that we accidentally failed to list a required notice, please
6 | bring it to our attention by posting an issue.
7 |
8 | The attached notices are provided for information only.
9 |
10 | License notice for .NET Compiler Platform (Roslyn)
11 | --------------------------------------------------
12 |
13 | The MIT License (MIT)
14 |
15 | Copyright (c) .NET Foundation and Contributors
16 |
17 | All rights reserved.
18 |
19 | Permission is hereby granted, free of charge, to any person obtaining a copy
20 | of this software and associated documentation files (the "Software"), to deal
21 | in the Software without restriction, including without limitation the rights
22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | copies of the Software, and to permit persons to whom the Software is
24 | furnished to do so, subject to the following conditions:
25 |
26 | The above copyright notice and this permission notice shall be included in all
27 | copies or substantial portions of the Software.
28 |
29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 | SOFTWARE.
36 |
--------------------------------------------------------------------------------
/src/SuggestedActions/DeleteSectionAction.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using Microsoft.VisualStudio.Imaging;
3 | using Microsoft.VisualStudio.Imaging.Interop;
4 | using Microsoft.VisualStudio.Text;
5 | using System.Linq;
6 |
7 | namespace EditorConfig
8 | {
9 | class DeleteSectionAction : BaseSuggestedAction
10 | {
11 | private ITextBuffer _buffer;
12 | private Section _section;
13 |
14 | public DeleteSectionAction(ITextBuffer buffer, Section section)
15 | {
16 | _buffer = buffer;
17 | _section = section;
18 | }
19 |
20 | public override string DisplayText
21 | {
22 | get { return "Remove Section"; }
23 | }
24 |
25 | public override ImageMoniker IconMoniker
26 | {
27 | get { return KnownMonikers.Cancel; }
28 | }
29 |
30 | public override void Execute(CancellationToken cancellationToken)
31 | {
32 | ITextSnapshotLine first = _buffer.CurrentSnapshot.GetLineFromPosition(_section.Span.Start);
33 | ITextSnapshotLine last = _buffer.CurrentSnapshot.GetLineFromPosition(_section.Span.End);
34 |
35 | if (_buffer.CurrentSnapshot.LineCount > last.LineNumber + 1)
36 | {
37 | ITextSnapshotLine nextLine = _buffer.CurrentSnapshot.GetLineFromLineNumber(last.LineNumber + 1);
38 | if (nextLine.Extent.IsEmpty)
39 | last = nextLine;
40 | }
41 |
42 | using (ITextEdit edit = _buffer.CreateEdit())
43 | {
44 | edit.Delete(Span.FromBounds(first.Start, last.EndIncludingLineBreak));
45 | edit.Apply();
46 | }
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Parser/Property.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Text;
2 |
3 | namespace EditorConfig
4 | {
5 | /// A property is a keyword/value pair with an optional severity.
6 | public class Property
7 | {
8 | public Property(ParseItem keyword)
9 | {
10 | Keyword = keyword;
11 | }
12 |
13 | /// The keyword is the name of the property.
14 | public ParseItem Keyword { get; set; }
15 |
16 | /// The value is what comes after the = character.
17 | public ParseItem Value { get; set; }
18 |
19 | /// This applies to C# and .NET specific keywords only.
20 | public ParseItem Severity { get; set; }
21 |
22 | /// The full span of the property including the value and severity.
23 | public Span Span
24 | {
25 | get
26 | {
27 | ParseItem last = Severity ?? Value ?? Keyword;
28 | return Span.FromBounds(Keyword.Span.Start, last.Span.End);
29 | }
30 | }
31 |
32 | /// Returns true if there are no syntax errors on the property.
33 | public bool IsValid
34 | {
35 | get
36 | {
37 | return Keyword != null && Value != null;
38 | }
39 | }
40 |
41 | public override string ToString()
42 | {
43 | string text = Keyword.Text;
44 |
45 | if (Value != null)
46 | text += $" = {Value.Text}";
47 |
48 | if (Severity != null)
49 | text += $" : {Severity.Text}";
50 |
51 | return text;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Schema/EditorConfig-schema.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json-schema.org/draft-04/schema",
3 | "type": "object",
4 |
5 | "definitions": {
6 | "keyword": {
7 | "type": "object",
8 | "required": [ "name", "description", "values", "defaultValue" ],
9 | "additionalProperties": false,
10 |
11 | "properties": {
12 | "description": {
13 | "type": "string"
14 | },
15 | "hidden": {
16 | "enum": [ true ]
17 | },
18 | "multiple": {
19 | "type": "boolean"
20 | },
21 | "name": {
22 | "type": "string"
23 | },
24 | "severity": {
25 | "type": "boolean"
26 | },
27 | "unsupported": {
28 | "enum": [ true ]
29 | },
30 | "values": {
31 | "type": "array"
32 | },
33 | "defaultValue": {
34 | "type": "array"
35 | },
36 | "defaultSeverity": {
37 | "enum": [ "none", "silent", "suggestion", "warning", "error" ]
38 | },
39 | "documentationLink": {
40 | "type": "string"
41 | }
42 | }
43 | },
44 | "severities": {
45 | "type": "object",
46 | "required": ["name", "description"],
47 | "additionalProperties": false,
48 |
49 | "properties": {
50 | "name": {
51 | "type": "string"
52 | },
53 | "description": {
54 | "type": "string"
55 | }
56 | }
57 | }
58 | },
59 |
60 | "properties": {
61 | "properties": {
62 | "type": "array",
63 | "items": {
64 | "$ref": "#/definitions/keyword"
65 | }
66 | },
67 | "severities": {
68 | "type": "array",
69 | "items": {
70 | "$ref": "#/definitions/severities"
71 | }
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/src/Validation/Error.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Imaging;
2 | using Microsoft.VisualStudio.Imaging.Interop;
3 | using System;
4 | using System.Linq;
5 |
6 | namespace EditorConfig
7 | {
8 | public class Error : ITooltip
9 | {
10 | private Func _isSupported;
11 |
12 | public Error(string code, ErrorCategory type, string format, Func isSupported)
13 | {
14 | Code = code;
15 | Category = type;
16 | DescriptionFormat = format;
17 | Description = string.Format(format, "x", "y", "z", "a", "b", "c");
18 | _isSupported = isSupported;
19 | }
20 |
21 | /// The error code is displayed in the Error List.
22 | public string Code { get; }
23 |
24 | /// A short description of the error.
25 | public string Description { get; set; }
26 |
27 | public string DescriptionFormat { get; }
28 |
29 | /// The error category determines how to display the error in the Error List.
30 | public ErrorCategory Category { get; }
31 |
32 | string ITooltip.Name => Code;
33 | public ImageMoniker Moniker => KnownMonikers.ValidationRule;
34 | public bool IsSupported => _isSupported();
35 |
36 | public void Run(ParseItem item, Action action)
37 | {
38 | Run(item, true, action);
39 | }
40 |
41 | public void Run(ParseItem item, bool enabled, Action action)
42 | {
43 | if (enabled && item != null && !item.HasErrors && IsSupported && !item.Document.Suppressions.Contains(Code, StringComparer.OrdinalIgnoreCase))
44 | {
45 | action.Invoke(new DisplayError(this, item));
46 | }
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | EditorConfig Language Service
6 | Language service for .editorconfig files.
7 |
8 | EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs.
9 | https://github.com/madskristensen/EditorConfigLanguage
10 | Resources\LICENSE
11 | https://github.com/madskristensen/EditorConfigLanguage/blob/master/CHANGELOG.md
12 | Resources\Icon.png
13 | Resources\Icon.png
14 | editorconfig
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/CodeExpansions/Snippets/dotnetstyle.snippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Dotnet code style settings
6 | netstyle
7 | Code snippet for default .NET code style settings
8 | Mads Kristensen
9 |
10 | Expansion
11 |
12 |
13 |
14 |
15 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/Test/EditorConfigTest/Helpers/Mef.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Text;
2 | using Microsoft.VisualStudio.Utilities;
3 | using System.ComponentModel.Composition;
4 | using System.ComponentModel.Composition.Hosting;
5 | using System.IO;
6 | using System.Reflection;
7 |
8 | namespace EditorConfigTest
9 | {
10 | public class Mef
11 | {
12 | [Import]
13 | private ITextBufferFactoryService TextBufferService { get; set; }
14 |
15 | [Import]
16 | private IContentTypeRegistryService ContentTypeService { get; set; }
17 |
18 | public Mef()
19 | {
20 | string lib = new DirectoryInfo(@"..\..\..\..\lib\").FullName;
21 |
22 | var editor = Assembly.LoadFrom(lib + "Microsoft.VisualStudio.Platform.VSEditor.dll");
23 | var interop = Assembly.LoadFrom(lib + "Microsoft.VisualStudio.Platform.VSEditor.interop.dll");
24 | var text = Assembly.LoadFrom(lib + "Microsoft.VisualStudio.Text.Internal.dll");
25 | var telemetry = Assembly.LoadFrom(lib + "Microsoft.VisualStudio.Telemetry.dll");
26 |
27 | var catalog = new AggregateCatalog();
28 | catalog.Catalogs.Add(new AssemblyCatalog(editor));
29 | catalog.Catalogs.Add(new AssemblyCatalog(interop));
30 | catalog.Catalogs.Add(new AssemblyCatalog(text));
31 | catalog.Catalogs.Add(new AssemblyCatalog(telemetry));
32 |
33 | catalog.Catalogs.Add(new AssemblyCatalog(typeof(DocumentTest).Assembly));
34 | catalog.Catalogs.Add(new AssemblyCatalog(typeof(EditorConfig.EditorConfigDocument).Assembly));
35 |
36 | var container = new CompositionContainer(catalog);
37 | container.SatisfyImportsOnce(this);
38 | }
39 |
40 | public static ITextBuffer CreateTextBuffer(string text)
41 | {
42 | var mef = new Mef();
43 | return mef.TextBufferService.CreateTextBuffer(text, mef.ContentTypeService.UnknownContentType);
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/EditorConfig.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26009.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EditorConfig", "src\EditorConfig.csproj", "{428EFC5A-7AC4-4CE4-8A37-D402B8A03EB4}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A710B3FB-9088-4A90-A822-AE25ACB69895}"
9 | ProjectSection(SolutionItems) = preProject
10 | .editorconfig = .editorconfig
11 | appveyor.yml = appveyor.yml
12 | CHANGELOG.md = CHANGELOG.md
13 | README.md = README.md
14 | EndProjectSection
15 | EndProject
16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EditorConfigTest", "Test\EditorConfigTest\EditorConfigTest.csproj", "{D4005889-6273-4725-AF75-8A2EE92FA639}"
17 | EndProject
18 | Global
19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
20 | Debug|Any CPU = Debug|Any CPU
21 | Release|Any CPU = Release|Any CPU
22 | EndGlobalSection
23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
24 | {428EFC5A-7AC4-4CE4-8A37-D402B8A03EB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {428EFC5A-7AC4-4CE4-8A37-D402B8A03EB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {428EFC5A-7AC4-4CE4-8A37-D402B8A03EB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {428EFC5A-7AC4-4CE4-8A37-D402B8A03EB4}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {D4005889-6273-4725-AF75-8A2EE92FA639}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {D4005889-6273-4725-AF75-8A2EE92FA639}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {D4005889-6273-4725-AF75-8A2EE92FA639}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {D4005889-6273-4725-AF75-8A2EE92FA639}.Release|Any CPU.Build.0 = Release|Any CPU
32 | EndGlobalSection
33 | GlobalSection(SolutionProperties) = preSolution
34 | HideSolutionNode = FALSE
35 | EndGlobalSection
36 | GlobalSection(Performance) = preSolution
37 | HasPerformanceSessions = true
38 | EndGlobalSection
39 | EndGlobal
40 |
--------------------------------------------------------------------------------
/src/Commands/OpenSettings.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio;
2 | using Microsoft.VisualStudio.Shell;
3 | using System;
4 | using System.ComponentModel.Design;
5 |
6 | namespace EditorConfig
7 | {
8 | internal sealed class OpenSettings
9 | {
10 | private readonly Package _package;
11 | private readonly OleMenuCommandService _commandService;
12 |
13 | private OpenSettings(Package package, OleMenuCommandService commandService)
14 | {
15 | _package = package ?? throw new ArgumentNullException(nameof(package));
16 | _commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
17 |
18 | var cmdId = new CommandID(PackageGuids.guidEditorConfigPackageCmdSet, PackageIds.OpenSettingsId);
19 | var menuItem = new OleMenuCommand(Execute, cmdId);
20 | menuItem.BeforeQueryStatus += BeforeQueryStatus;
21 | commandService.AddCommand(menuItem);
22 | }
23 |
24 | private void BeforeQueryStatus(object sender, EventArgs e)
25 | {
26 | var button = (OleMenuCommand)sender;
27 | button.Enabled = button.Visible = VsHelpers.DTE.ActiveDocument?.Language == Constants.LanguageName;
28 | }
29 |
30 | public static OpenSettings Instance
31 | {
32 | get;
33 | private set;
34 | }
35 |
36 | private IServiceProvider ServiceProvider
37 | {
38 | get { return _package; }
39 | }
40 |
41 | public static void Initialize(Package package, OleMenuCommandService commandService)
42 | {
43 | Instance = new OpenSettings(package, commandService);
44 | }
45 |
46 | private void Execute(object sender, EventArgs e)
47 | {
48 | Guid cmdGroup = typeof(VSConstants.VSStd97CmdID).GUID;
49 | var cmd = new CommandID(cmdGroup, VSConstants.cmdidToolsOptions);
50 | _commandService.GlobalInvoke(cmd, typeof(FormatterOptions).GUID.ToString());
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/Formatting/FormatterOptions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell;
2 | using System;
3 | using System.ComponentModel;
4 |
5 | namespace EditorConfig
6 | {
7 | public class FormatterOptions : DialogPage
8 | {
9 | // Formatting
10 | private const string _properties = "Properties";
11 |
12 | [Category(_properties)]
13 | [DisplayName("Align values mode")]
14 | [Description("Determins if the = character should be aligned by section, document or not at all")]
15 | [DefaultValue(FormattingType.Section)]
16 | [TypeConverter(typeof(EnumConverter))]
17 | public FormattingType FormattingType { get; set; } = FormattingType.Section;
18 |
19 | [Category(_properties)]
20 | [DisplayName("Spaces before =")]
21 | [Description("Space characters to add in front of the = character")]
22 | [DefaultValue(1)]
23 | public int SpacesBeforeEquals { get; set; } = 1;
24 |
25 | [Category(_properties)]
26 | [DisplayName("Spaces after =")]
27 | [Description("Space characters to add after the = character")]
28 | [DefaultValue(1)]
29 | public int SpacesAfterEquals { get; set; } = 1;
30 |
31 | // Severity
32 | private const string _severity = "Severity";
33 |
34 | [Category(_severity)]
35 | [DisplayName("Spaces before :")]
36 | [Description("[C# only] Space characters to add in front of the : character used to specify Severity")]
37 | [DefaultValue(1)]
38 | public int SpacesBeforeColon { get; set; } = 1;
39 |
40 | [Category(_severity)]
41 | [DisplayName("Spaces after :")]
42 | [Description("[C# only] Space characters to add after the : character used to specify Severity")]
43 | [DefaultValue(1)]
44 | public int SpacesAfterColon { get; set; } = 1;
45 |
46 | public override void SaveSettingsToStorage()
47 | {
48 | Telemetry.TrackOperation("FormattingOptionsSaved");
49 | base.SaveSettingsToStorage();
50 | Saved?.Invoke(this, EventArgs.Empty);
51 | }
52 |
53 | public static event EventHandler Saved;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/Shared/JoinableTaskFactoryExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft;
3 | using Microsoft.VisualStudio.Shell;
4 | using Microsoft.VisualStudio.Threading;
5 | using Task = System.Threading.Tasks.Task;
6 |
7 | namespace EditorConfig
8 | {
9 | internal static class JoinableTaskFactoryExtensions
10 | {
11 | ///
12 | /// Schedules a delegate for background execution on the UI thread without inheriting any claim to the UI thread from its caller.
13 | ///
14 | /// The factory to use for creating the task.
15 | /// The async delegate to invoke on the UI thread sometime in the future.
16 | /// The priority to use when switching to the UI thread or resuming after a yielding await.
17 | /// The that represents the on-idle operation.
18 | public static JoinableTask StartOnIdle(this JoinableTaskFactory joinableTaskFactory, Func asyncMethod, VsTaskRunContext priority = VsTaskRunContext.UIThreadBackgroundPriority)
19 | {
20 | Requires.NotNull(joinableTaskFactory, nameof(joinableTaskFactory));
21 | Requires.NotNull(asyncMethod, nameof(asyncMethod));
22 |
23 | // Avoid inheriting any context from any ambient JoinableTask that is scheduling this work.
24 | using (joinableTaskFactory.Context.SuppressRelevance())
25 | {
26 | return joinableTaskFactory.RunAsync(
27 | priority,
28 | async () =>
29 | {
30 | // We always yield, so as to not inline execution of the delegate if the caller is already on the UI thread.
31 | await Task.Yield();
32 |
33 | // In case the caller wasn't on the UI thread, switch to it. It no-ops if we're already there.
34 | await joinableTaskFactory.SwitchToMainThreadAsync();
35 |
36 | await asyncMethod();
37 | });
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Validation/ErrorList/SinkManager.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell.TableManager;
2 | using System.Linq;
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | namespace EditorConfig
7 | {
8 | class SinkManager : IDisposable
9 | {
10 | private readonly ITableDataSink _sink;
11 | private TableDataSource _errorList;
12 | private List _snapshots = new List();
13 |
14 | internal SinkManager(TableDataSource errorList, ITableDataSink sink)
15 | {
16 | _sink = sink;
17 | _errorList = errorList;
18 |
19 | errorList.AddSinkManager(this);
20 | }
21 |
22 | internal void Clear()
23 | {
24 | _sink.RemoveAllSnapshots();
25 | }
26 |
27 | internal void UpdateSink(IEnumerable snapshots)
28 | {
29 | foreach (TableEntriesSnapshot snapshot in snapshots)
30 | {
31 | TableEntriesSnapshot existing = _snapshots.FirstOrDefault(s => s.Url == snapshot.Url);
32 |
33 | if (existing != null)
34 | {
35 | _snapshots.Remove(existing);
36 | _sink.ReplaceSnapshot(existing, snapshot);
37 | }
38 | else
39 | {
40 | _sink.AddSnapshot(snapshot);
41 | }
42 |
43 | _snapshots.Add(snapshot);
44 | }
45 | }
46 |
47 | internal void RemoveSnapshots(IEnumerable urls)
48 | {
49 | foreach (string url in urls)
50 | {
51 | TableEntriesSnapshot existing = _snapshots.FirstOrDefault(s => s.Url == url);
52 |
53 | if (existing != null)
54 | {
55 | _snapshots.Remove(existing);
56 | _sink.RemoveSnapshot(existing);
57 | }
58 | }
59 | }
60 |
61 | public void Dispose()
62 | {
63 | // Called when the person who subscribed to the data source disposes of the cookie (== this object) they were given.
64 | _errorList.RemoveSinkManager(this);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/SuggestedActions/RemoveDuplicatePropertiesAction.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Imaging;
2 | using Microsoft.VisualStudio.Imaging.Interop;
3 | using Microsoft.VisualStudio.Text;
4 | using Microsoft.VisualStudio.Text.Editor;
5 | using System.Linq;
6 | using System.Threading;
7 | using System.Collections.Generic;
8 |
9 | namespace EditorConfig
10 | {
11 | class RemoveDuplicatePropertiesAction : BaseSuggestedAction
12 | {
13 | private Section _section;
14 | private ITextView _view;
15 |
16 | public RemoveDuplicatePropertiesAction(Section section, ITextView view)
17 | {
18 | _section = section;
19 | _view = view;
20 | }
21 |
22 | public override string DisplayText
23 | {
24 | get { return "Remove duplicates"; }
25 | }
26 |
27 | public override ImageMoniker IconMoniker
28 | {
29 | get { return KnownMonikers.CleanData; }
30 | }
31 |
32 | public override bool IsEnabled
33 | {
34 | get
35 | {
36 | return _section.Properties.Any(p => p.Keyword.Errors.Any(e => e.Name == ErrorCatalog.DuplicateProperty.Code || e.Name == ErrorCatalog.ParentDuplicateProperty.Code));
37 | }
38 | }
39 |
40 | public override void Execute(CancellationToken cancellationToken)
41 | {
42 | SnapshotPoint caretPost = _view.Caret.Position.BufferPosition;
43 | IEnumerable duplicates = _section.Properties.Where(p => p.Keyword.Errors.Any(e => e.Name == ErrorCatalog.DuplicateProperty.Code || e.Name == ErrorCatalog.ParentDuplicateProperty.Code));
44 |
45 | using (ITextEdit edit = _view.TextBuffer.CreateEdit())
46 | {
47 | foreach (Property dupe in duplicates.Reverse())
48 | {
49 | ITextSnapshotLine line = _view.TextBuffer.CurrentSnapshot.GetLineFromPosition(dupe.Span.Start);
50 | edit.Delete(line.ExtentIncludingLineBreak);
51 | }
52 |
53 | if (edit.HasEffectiveChanges)
54 | edit.Apply();
55 | }
56 |
57 | _view.Caret.MoveTo(new SnapshotPoint(_view.TextBuffer.CurrentSnapshot, caretPost));
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/CommandTable.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This file was generated by Extensibility Tools v1.10.188
4 | //
5 | // ------------------------------------------------------------------------------
6 | namespace EditorConfig
7 | {
8 | using System;
9 |
10 | ///
11 | /// Helper class that exposes all GUIDs used across VS Package.
12 | ///
13 | internal sealed partial class PackageGuids
14 | {
15 | public const string guidEditorConfigPackageString = "6736c72d-7a27-49f0-9153-413ff47963ef";
16 | public const string guidEditorFactoryString = "13cabf99-9eae-4ecc-a6f4-89f3ad54dc83";
17 | public const string guidEditorConfigPackageCmdSetString = "13cabf99-9eae-4ecc-a6f4-89f3ad54dc83";
18 | public const string guidWorkspaceExplorerToolWindowPackageCmdSetString = "cfb400f1-5c60-4f3c-856e-180d28def0b7";
19 | public const string iconsString = "666770e6-562f-46d7-a555-3a0cdffe94d2";
20 | public static Guid guidEditorConfigPackage = new Guid(guidEditorConfigPackageString);
21 | public static Guid guidEditorFactory = new Guid(guidEditorFactoryString);
22 | public static Guid guidEditorConfigPackageCmdSet = new Guid(guidEditorConfigPackageCmdSetString);
23 | public static Guid guidWorkspaceExplorerToolWindowPackageCmdSet = new Guid(guidWorkspaceExplorerToolWindowPackageCmdSetString);
24 | public static Guid icons = new Guid(iconsString);
25 | }
26 | ///
27 | /// Helper class that encapsulates all CommandIDs uses across VS Package.
28 | ///
29 | internal sealed partial class PackageIds
30 | {
31 | public const int AddGroup = 0x0001;
32 | public const int AddGroupAnyCode = 0x0002;
33 | public const int EditorContextMenu = 0x0003;
34 | public const int ErrorListGroup = 0x0004;
35 | public const int CreateEditorConfigFileId = 0x0100;
36 | public const int CreateEditorConfigFileAnyCodeId = 0x0200;
37 | public const int OpenSettingsId = 0x0300;
38 | public const int NavigateToParentId = 0x0400;
39 | public const int SuppressErrorId = 0x0500;
40 | public const int idmAddNew = 0x2200;
41 | public const int logo = 0x0001;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/QuickInfo/EditorConfigQuickInfoController.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Microsoft.VisualStudio.Language.Intellisense;
3 | using Microsoft.VisualStudio.Text;
4 | using Microsoft.VisualStudio.Text.Editor;
5 |
6 | namespace EditorConfig
7 | {
8 | internal class EditorConfigQuickInfoController : IIntellisenseController
9 | {
10 | private ITextView m_textView;
11 | private IList m_subjectBuffers;
12 | private EditorConfigQuickInfoControllerProvider m_provider;
13 |
14 | internal EditorConfigQuickInfoController(ITextView textView, IList subjectBuffers, EditorConfigQuickInfoControllerProvider provider)
15 | {
16 | m_textView = textView;
17 | m_subjectBuffers = subjectBuffers;
18 | m_provider = provider;
19 |
20 | m_textView.MouseHover += OnTextViewMouseHover;
21 | }
22 |
23 | private void OnTextViewMouseHover(object sender, MouseHoverEventArgs e)
24 | {
25 | //find the mouse position by mapping down to the subject buffer
26 | SnapshotPoint? point = m_textView.BufferGraph.MapDownToFirstMatch
27 | (new SnapshotPoint(m_textView.TextSnapshot, e.Position),
28 | PointTrackingMode.Positive,
29 | snapshot => m_subjectBuffers.Contains(snapshot.TextBuffer),
30 | PositionAffinity.Predecessor);
31 |
32 | if (point != null)
33 | {
34 | ITrackingPoint triggerPoint = point.Value.Snapshot.CreateTrackingPoint(point.Value.Position, PointTrackingMode.Positive);
35 |
36 | if (!m_provider.QuickInfoBroker.IsQuickInfoActive(m_textView))
37 | {
38 | m_provider.QuickInfoBroker.TriggerQuickInfo(m_textView, triggerPoint, true);
39 | }
40 | }
41 | }
42 |
43 | public void Detach(ITextView textView)
44 | {
45 | if (m_textView == textView)
46 | {
47 | m_textView.MouseHover -= OnTextViewMouseHover;
48 | m_textView = null;
49 | }
50 | }
51 |
52 | public void ConnectSubjectBuffer(ITextBuffer subjectBuffer)
53 | {
54 | }
55 |
56 | public void DisconnectSubjectBuffer(ITextBuffer subjectBuffer)
57 | {
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/Validation/ErrorList/DisplayError.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Imaging;
2 | using Microsoft.VisualStudio.Imaging.Interop;
3 | using Microsoft.VisualStudio.Text;
4 |
5 | namespace EditorConfig
6 | {
7 | public class DisplayError : ITooltip
8 | {
9 | private Error _error;
10 | private ParseItem _item;
11 |
12 | public DisplayError(Error error, ParseItem item)
13 | {
14 | _error = error;
15 | _item = item;
16 | Description = _error.Description;
17 | }
18 |
19 | /// The error code is displayed in the Error List.
20 | public string Name => _error.Code;
21 |
22 | /// A short description of the error.
23 | public string Description { get; private set; }
24 |
25 | /// The error category determines how to display the error in the Error List.
26 | public ErrorCategory Category => _error.Category;
27 |
28 | /// A URL pointing to documentation about the error.
29 | public string HelpLink => string.Format(Constants.HelpLink, Name.ToLowerInvariant());
30 |
31 | /// The line number containing the error.
32 | public int Line { get; private set; } = 0;
33 |
34 | /// The column number containing the error.
35 | public int Column { get; private set; } = 0;
36 |
37 | public ImageMoniker Moniker => _error.Moniker;
38 |
39 | public bool IsSupported => _error.IsSupported;
40 |
41 | /// Register the error on the specified ParseItem.
42 | public void Register(params string[] tokens)
43 | {
44 | Register(_item, tokens);
45 | }
46 |
47 | /// Register the error on the specified ParseItem.
48 | public void Register(ParseItem item, params string[] tokens)
49 | {
50 | var span = new SnapshotSpan(item.Document.TextBuffer.CurrentSnapshot, item.Span);
51 | ITextSnapshotLine line = span.Snapshot.GetLineFromPosition(span.Start);
52 |
53 | Line = line.LineNumber;
54 | Column = span.Start.Position - line.Start.Position;
55 | Description = string.Format(_error.DescriptionFormat, tokens);
56 |
57 | item.AddError(this);
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/Formatting/FormatterCommand.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio;
2 | using Microsoft.VisualStudio.OLE.Interop;
3 | using Microsoft.VisualStudio.Shell;
4 | using Microsoft.VisualStudio.Text.Editor;
5 | using Microsoft.VisualStudio.Text.Operations;
6 | using System;
7 |
8 | namespace EditorConfig
9 | {
10 | internal sealed class FormatterCommand : BaseCommand
11 | {
12 | private ITextBufferUndoManager _undoManager;
13 | private IWpfTextView _view;
14 |
15 | public FormatterCommand(IWpfTextView textView, ITextBufferUndoManager undoManager)
16 | {
17 | _view = textView;
18 | _undoManager = undoManager;
19 | }
20 |
21 | public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
22 | {
23 | if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.FORMATDOCUMENT)
24 | {
25 | FormatDocument();
26 | return VSConstants.S_OK;
27 | }
28 |
29 | ThreadHelper.ThrowIfNotOnUIThread();
30 |
31 | return Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
32 | }
33 |
34 | private void FormatDocument()
35 | {
36 | using (ITextUndoTransaction transaction = _undoManager.TextBufferUndoHistory.CreateTransaction(Resources.Text.FormatDocument))
37 | {
38 | EditorConfigFormatter formatter = _view.Properties.GetOrCreateSingletonProperty(() => new EditorConfigFormatter(_view.TextBuffer));
39 | bool changed = formatter.Format();
40 |
41 | if (changed)
42 | transaction.Complete();
43 | else
44 | transaction.Cancel();
45 | }
46 | }
47 |
48 | public override int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
49 | {
50 | if (pguidCmdGroup == VSConstants.VSStd2K && prgCmds[0].cmdID == (uint)VSConstants.VSStd2KCmdID.FORMATDOCUMENT)
51 | {
52 | prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED;
53 | return VSConstants.S_OK;
54 | }
55 |
56 | ThreadHelper.ThrowIfNotOnUIThread();
57 |
58 | return Next.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText);
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/src/Validation/ErrorList/ErrorList.cs:
--------------------------------------------------------------------------------
1 | using EnvDTE;
2 | using Microsoft.VisualStudio.Shell;
3 | using Microsoft.VisualStudio.Text;
4 | using Microsoft.VisualStudio.Text.Editor;
5 | using Microsoft.VisualStudio.Utilities;
6 | using System;
7 | using System.ComponentModel.Composition;
8 | using System.Linq;
9 |
10 | namespace EditorConfig
11 | {
12 | [Export(typeof(IWpfTextViewCreationListener))]
13 | [ContentType(Constants.LanguageName)]
14 | [TextViewRole(PredefinedTextViewRoles.PrimaryDocument)]
15 | public class ErrorList : IWpfTextViewCreationListener
16 | {
17 | private EditorConfigValidator _validator;
18 | private EditorConfigDocument _document;
19 | private Project _project;
20 | private string _file;
21 |
22 | [Import]
23 | private ITextDocumentFactoryService _documentService = null;
24 |
25 | public void TextViewCreated(IWpfTextView view)
26 | {
27 | ThreadHelper.ThrowIfNotOnUIThread();
28 |
29 | if (_documentService.TryGetTextDocument(view.TextBuffer, out var doc))
30 | {
31 | _file = doc.FilePath;
32 | view.Properties.AddProperty("file", doc.FilePath);
33 | }
34 |
35 | _document = EditorConfigDocument.FromTextBuffer(view.TextBuffer);
36 | _validator = EditorConfigValidator.FromDocument(_document);
37 | _project = VsHelpers.DTE.Solution?.FindProjectItem(_file)?.ContainingProject;
38 |
39 | view.Closed += ViewClosed;
40 | _validator.Validated += Validated;
41 | }
42 |
43 | private void Validated(object sender, EventArgs e)
44 | {
45 | UpdateErrorList();
46 | }
47 |
48 | private void UpdateErrorList()
49 | {
50 | if (_document.IsParsing)
51 | return;
52 |
53 | ParseItem[] items = _document.ParseItems.Where(p => p.HasErrors).ToArray();
54 |
55 | TableDataSource.Instance.CleanErrors(_file);
56 | TableDataSource.Instance.AddErrors(items, _project?.Name, _file);
57 | }
58 |
59 | private void ViewClosed(object sender, EventArgs e)
60 | {
61 | var view = (IWpfTextView)sender;
62 | view.Closed -= ViewClosed;
63 |
64 | if (view.Properties.TryGetProperty("file", out string file))
65 | {
66 | TableDataSource.Instance.CleanErrors(file);
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/SuggestedActions/BaseSuggestedAction.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 | using EnvDTE;
6 | using Microsoft.VisualStudio.Imaging.Interop;
7 | using Microsoft.VisualStudio.Language.Intellisense;
8 | using Microsoft.VisualStudio.Shell;
9 |
10 | namespace EditorConfig
11 | {
12 | abstract class BaseSuggestedAction : ISuggestedAction
13 | {
14 | public abstract string DisplayText { get; }
15 |
16 | public virtual bool IsEnabled { get; } = true;
17 |
18 | public virtual bool HasActionSets
19 | {
20 | get { return false; }
21 | }
22 |
23 | public virtual bool HasPreview
24 | {
25 | get { return false; }
26 | }
27 |
28 | public string IconAutomationText
29 | {
30 | get { return null; }
31 | }
32 |
33 | public virtual ImageMoniker IconMoniker
34 | {
35 | get { return default(ImageMoniker); }
36 | }
37 |
38 | public string InputGestureText
39 | {
40 | get { return null; }
41 | }
42 |
43 | public virtual void Dispose()
44 | {
45 | // nothing to dispose
46 | }
47 |
48 | public virtual Task> GetActionSetsAsync(CancellationToken cancellationToken)
49 | {
50 | return System.Threading.Tasks.Task.FromResult>(null);
51 | }
52 |
53 | public Task