├── .editorconfig
├── .gitattributes
├── .github
├── CONTRIBUTING.md
├── FUNDING.yml
└── ISSUE_TEMPLATE.md
├── .gitignore
├── CHANGELOG.md
├── Directory.Build.props
├── EditorConfig.sln
├── LICENSE
├── README.md
├── THIRD-PARTY-NOTICES.txt
├── Test
└── EditorConfigTest
│ ├── CompletionTest.cs
│ ├── DocumentTest.cs
│ ├── EditorConfigTest.csproj
│ ├── Helpers
│ ├── Extensions.cs
│ ├── Mef.cs
│ └── Samples.cs
│ ├── ParseItemTest.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── ValidationTest.cs
│ └── app.config
├── appveyor.yml
├── art
├── classification.png
├── context-menu.png
├── csharp-analyzers.png
├── editor-context-menu.png
├── formatting.png
├── inheritance-visualizer.png
├── keyword-intellisense.png
├── light-bulb.png
├── navigation-dropdown.png
├── quick-info.png
├── settings.png
├── snippets-context-menu.png
├── snippets-expansion.png
├── suppress-comment.png
├── suppress-errorlist.png
├── suppress_error.png
├── validation-duplicates-parent.png
├── validation-duplicates.png
├── validation.png
└── value-intellisense.png
├── lib
├── Microsoft.VisualStudio.Platform.VSEditor.Interop.dll
├── Microsoft.VisualStudio.Platform.VSEditor.dll
├── Microsoft.VisualStudio.Telemetry.dll
└── Microsoft.VisualStudio.Text.Internal.dll
└── src
├── Adornments
├── InheritanceAdornment.cs
└── InheritanceAdornmentProvider.cs
├── BraceCompletion
├── BraceCompletionContext.cs
├── BraceCompletionContextProvider.cs
├── BraceMatchingTagger.cs
└── BraceMatchingTaggerProvider.cs
├── Classifier
├── EditorConfigClassifier.cs
└── EditorConfigProvider.cs
├── CodeExpansions
├── EnableSnippetsCommand.cs
└── Snippets
│ ├── basicdocument.snippet
│ ├── csharpstyle.snippet
│ └── dotnetstyle.snippet
├── CommandTable.cs
├── CommandTable.vsct
├── Commands
├── BaseCommand.cs
├── CreateEditorConfigFile.cs
├── CreateEditorConfigFileAnyCode.cs
├── F1Help.cs
├── HideDefaultCommands.cs
├── NavigateToParent.cs
└── OpenSettings.cs
├── Completion
├── CompletionController.cs
├── CompletionElementProvider.cs
├── CompletionOptions.cs
├── CompletionSource.cs
├── CompletionSourceProvider.cs
└── FilteredCompletionSet.cs
├── Constants.cs
├── DragDrop
├── EditorConfigDropHandler.cs
└── EditorConfigDropHandlerProvider.cs
├── EditorConfig.csproj
├── EditorConfigPackage.cs
├── Formatting
├── EditorConfigFormatter.cs
├── FormatterCommand.cs
├── FormatterOptions.cs
└── FormattingType.cs
├── LanguageService
├── Colorizer.cs
├── ContentTypes.cs
├── DropDownBars.cs
├── EditorFactory.cs
├── LanguageService.cs
└── Source.cs
├── Monikers.imagemanifest
├── Outlining
├── OutliningTagger.cs
└── OutliningTaggerProvider.cs
├── Parser
├── EditorConfigDocument.cs
├── EditorConfigDocumentInheritance.cs
├── EditorConfigDocumentParser.cs
├── ParseItem.cs
├── Property.cs
└── Section.cs
├── Properties
└── AssemblyInfo.cs
├── ProvideBraceCompletionAttribute.cs
├── QuickInfo
├── EditorConfigQuickInfo.cs
├── EditorConfigQuickInfoController.cs
├── EditorConfigQuickInfoControllerProvider.cs
└── EditorConfigQuickInfoSourceProvider.cs
├── Resources
├── ButtonIcon.png
├── Icon.png
├── Text.Designer.cs
└── Text.resx
├── Schema
├── Category.cs
├── EditorConfig-schema.json
├── EditorConfig.json
├── Keyword.cs
├── SchemaCatalog.cs
├── Severity.cs
└── Value.cs
├── Shared
├── AnalyzerConfig_SectionNameMatching.cs
├── EditorTooltip.xaml
├── EditorTooltip.xaml.cs
├── Extensions.cs
├── ITooltip.cs
├── JoinableTaskFactoryExtensions.cs
├── Telemetry.cs
├── TextViewCreationListener.cs
├── TextViewUtil.cs
└── VsHelpers.cs
├── SignatureHelp
├── SectionParameter.cs
├── SectionSignature.cs
├── SectionSignatureHelpSource.cs
├── SignatureHelpController.cs
└── SignatureHelpSourceProvider.cs
├── SuggestedActions
├── AddMissingRulesAction.cs
├── AddMissingRulesActionAll.cs
├── AddMissingRulesActionCSharp.cs
├── AddMissingRulesActionDotNet.cs
├── AddMissingRulesActionVB.cs
├── BaseSuggestedAction.cs
├── DeleteSectionAction.cs
├── RemoveDuplicatePropertiesAction.cs
├── SortAllPropertiesAction.cs
├── SortPropertiesAction.cs
├── SuggestedActionsSource.cs
├── SuggestedActionsSourceProvider.cs
└── SuppressErrorAction.cs
├── Validation
├── Commands
│ └── SuppressError.cs
├── EditorConfigValidator.cs
├── EditorConfigValidatorRules.cs
├── Error.cs
├── ErrorCatalog.cs
├── ErrorCategory.cs
├── ErrorList
│ ├── DisplayError.cs
│ ├── ErrorList.cs
│ ├── SinkManager.cs
│ ├── TableDataSource.cs
│ └── TableEntriesSnapshot.cs
├── NamingStyles
│ ├── Accessibility.cs
│ ├── EditorConfigNamingStyleParser.cs
│ ├── ModifierKind.cs
│ ├── NamingRule.cs
│ ├── NamingStyle.cs
│ ├── NamingStylePreferences.cs
│ ├── NamingStyleRules.cs
│ ├── ReportDiagnostic.cs
│ ├── SerializableNamingRule.cs
│ ├── SymbolKindOrTypeKind.cs
│ └── SymbolSpecification.cs
├── Tagger
│ ├── ErrorFormatDefinition.cs
│ ├── ErrorTagger.cs
│ └── ErrorTaggerProvider.cs
└── ValidationOptions.cs
├── icons.pkgdef
├── source.extension.cs
├── source.extension.ico
├── source.extension.resx
└── source.extension.vsixmanifest
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome:http://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # Don't use tabs for indentation.
7 | [*]
8 | indent_style = space
9 | end_of_line = crlf
10 | # (Please don't specify an indent_size here; that has too many unintended consequences.)
11 |
12 | # Code files
13 | [*.{cs,csx,vb,vbx}]
14 | indent_size = 4
15 |
16 | # Xml project files
17 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
18 | indent_size = 2
19 |
20 | # Xml config files
21 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
22 | indent_size = 2
23 |
24 | # JSON files
25 | [*.json]
26 | indent_size = 2
27 |
28 | # Dotnet code style settings:
29 | [*.{cs, vb}]
30 | # Sort using and Import directives with System.* appearing first
31 | dotnet_sort_system_directives_first = true
32 | # Avoid "this." and "Me." if not necessary
33 | dotnet_style_qualification_for_field = false:suggestion
34 | dotnet_style_qualification_for_property = false:suggestion
35 | dotnet_style_qualification_for_method = false:suggestion
36 | dotnet_style_qualification_for_event = false:suggestion
37 |
38 | # Use language keywords instead of framework type names for type references
39 | dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
40 | dotnet_style_predefined_type_for_member_access = true:suggestion
41 |
42 | # Suggest more modern language features when available
43 | dotnet_style_object_initializer = true:suggestion
44 | dotnet_style_collection_initializer = true:suggestion
45 | dotnet_style_coalesce_expression = true:suggestion
46 | dotnet_style_null_propagation = true:suggestion
47 | dotnet_style_explicit_tuple_names = true:suggestion
48 |
49 | # CSharp code style settings:
50 | [*.cs]
51 | # Prefer "var" everywhere
52 | csharp_style_var_for_built_in_types = false:suggestion
53 | csharp_style_var_when_type_is_apparent = true:suggestion
54 | csharp_style_var_elsewhere = false:suggestion
55 |
56 | # Prefer method-like constructs to have a block body
57 | csharp_style_expression_bodied_methods = false:none
58 | csharp_style_expression_bodied_constructors = false:none
59 | csharp_style_expression_bodied_operators = false:none
60 |
61 | # Prefer property-like constructs to have an expression-body
62 | csharp_style_expression_bodied_properties = true:none
63 | csharp_style_expression_bodied_indexers = true:none
64 | csharp_style_expression_bodied_accessors = true:none
65 |
66 | # Suggest more modern language features when available
67 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
68 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
69 | csharp_style_inlined_variable_declaration = true:suggestion
70 | csharp_style_throw_expression = true:suggestion
71 | csharp_style_conditional_delegate_call = true:suggestion
72 |
73 | # Newline settings
74 | csharp_new_line_before_open_brace = all
75 | csharp_new_line_before_else = true
76 | csharp_new_line_before_catch = true
77 | csharp_new_line_before_finally = true
78 | csharp_new_line_before_members_in_object_initializers = true
79 | csharp_new_line_before_members_in_anonymous_types = true
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: madskristensen
4 |
--------------------------------------------------------------------------------
/.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.
--------------------------------------------------------------------------------
/.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
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | 7.3
4 |
5 |
6 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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.
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/Test/EditorConfigTest/DocumentTest.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Linq;
3 | using System.Threading.Tasks;
4 | using EditorConfig;
5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
6 | using Microsoft.VisualStudio.Text;
7 |
8 | namespace EditorConfigTest
9 | {
10 | [TestClass]
11 | public class DocumentTest
12 | {
13 | [TestMethod, TestCategory("MEF")]
14 | public async Task Parse()
15 | {
16 | ITextBuffer buffer = Mef.CreateTextBuffer(Samples.OneSectionStandard);
17 | var doc = EditorConfigDocument.FromTextBuffer(buffer);
18 |
19 | await doc.WaitForParsingComplete();
20 |
21 | Assert.AreEqual(12, doc.ParseItems.Count);
22 | Assert.AreEqual(ItemType.Keyword, doc.ParseItems[0].ItemType);
23 | Assert.AreEqual(ItemType.Comment, doc.ParseItems[2].ItemType);
24 |
25 | Property root = doc.Properties[0];
26 | Assert.AreEqual(1, doc.Properties.Count);
27 | Assert.IsTrue(root.IsValid);
28 | Assert.AreEqual(SchemaCatalog.Root, root.Keyword.Text);
29 |
30 | Section section = doc.Sections[0];
31 | Assert.AreEqual("[*.cs]", section.Item.Text);
32 | Assert.AreEqual(4, section.Properties.Count);
33 | Assert.IsTrue(section.Properties.All(p => p.IsValid));
34 | }
35 |
36 | [TestMethod, TestCategory("MEF")]
37 | public async Task MultipleValues()
38 | {
39 | ITextBuffer buffer = Mef.CreateTextBuffer(Samples.MultipleValuesSection);
40 | var doc = EditorConfigDocument.FromTextBuffer(buffer);
41 |
42 | await doc.WaitForParsingComplete();
43 |
44 | Assert.AreEqual(3, doc.ParseItems.Count);
45 | Assert.AreEqual("accessors, indexers", doc.ParseItems.Last().Text);
46 | }
47 |
48 | [TestMethod, TestCategory("MEF")]
49 | public async Task Suppressions()
50 | {
51 | ITextBuffer buffer = Mef.CreateTextBuffer(Samples.Suppression);
52 | var doc = EditorConfigDocument.FromTextBuffer(buffer);
53 |
54 | await doc.WaitForParsingComplete();
55 |
56 | Assert.AreEqual(3, doc.ParseItems.Count);
57 | Assert.AreEqual("EC101", doc.ParseItems[1].Text);
58 | Assert.AreEqual(12, doc.ParseItems[1].Span.Start);
59 | Assert.AreEqual(5, doc.ParseItems[1].Span.Length);
60 | }
61 |
62 | [TestMethod]
63 | public void NamingRules()
64 | {
65 | var file = new FileInfo(@"..\..\..\..\src\schema\EditorConfig.json");
66 | SchemaCatalog.ParseJson(file.FullName);
67 |
68 | bool exist = SchemaCatalog.TryGetKeyword("dotnet_naming_rule.foo.symbols", out Keyword keyword);
69 |
70 | Assert.IsTrue(exist);
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Test/EditorConfigTest/EditorConfigTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {D4005889-6273-4725-AF75-8A2EE92FA639}
7 | Library
8 | Properties
9 | EditorConfigTest
10 | EditorConfigTest
11 | v4.6
12 | 512
13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 15.0
15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
17 | False
18 | UnitTest
19 |
20 |
21 |
22 |
23 |
24 | true
25 | full
26 | false
27 | bin\Debug\
28 | DEBUG;TRACE
29 | prompt
30 | 4
31 |
32 |
33 | pdbonly
34 | true
35 | bin\Release\
36 | TRACE
37 | prompt
38 | 4
39 |
40 |
41 |
42 | False
43 | ..\..\lib\Microsoft.VisualStudio.Platform.VSEditor.dll
44 |
45 |
46 | ..\..\lib\Microsoft.VisualStudio.Platform.VSEditor.Interop.dll
47 | True
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | {428efc5a-7ac4-4ce4-8a37-d402b8a03eb4}
68 | EditorConfig
69 |
70 |
71 |
72 |
73 | 15.0.0-beta4
74 |
75 |
76 | 1.3.2
77 |
78 |
79 | 1.3.2
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/Test/EditorConfigTest/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/art/classification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/classification.png
--------------------------------------------------------------------------------
/art/context-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/context-menu.png
--------------------------------------------------------------------------------
/art/csharp-analyzers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/csharp-analyzers.png
--------------------------------------------------------------------------------
/art/editor-context-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/editor-context-menu.png
--------------------------------------------------------------------------------
/art/formatting.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/formatting.png
--------------------------------------------------------------------------------
/art/inheritance-visualizer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/inheritance-visualizer.png
--------------------------------------------------------------------------------
/art/keyword-intellisense.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/keyword-intellisense.png
--------------------------------------------------------------------------------
/art/light-bulb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/light-bulb.png
--------------------------------------------------------------------------------
/art/navigation-dropdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/navigation-dropdown.png
--------------------------------------------------------------------------------
/art/quick-info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/quick-info.png
--------------------------------------------------------------------------------
/art/settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/settings.png
--------------------------------------------------------------------------------
/art/snippets-context-menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/snippets-context-menu.png
--------------------------------------------------------------------------------
/art/snippets-expansion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/snippets-expansion.png
--------------------------------------------------------------------------------
/art/suppress-comment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/suppress-comment.png
--------------------------------------------------------------------------------
/art/suppress-errorlist.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/suppress-errorlist.png
--------------------------------------------------------------------------------
/art/suppress_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/suppress_error.png
--------------------------------------------------------------------------------
/art/validation-duplicates-parent.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/validation-duplicates-parent.png
--------------------------------------------------------------------------------
/art/validation-duplicates.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/validation-duplicates.png
--------------------------------------------------------------------------------
/art/validation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/validation.png
--------------------------------------------------------------------------------
/art/value-intellisense.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/art/value-intellisense.png
--------------------------------------------------------------------------------
/lib/Microsoft.VisualStudio.Platform.VSEditor.Interop.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/lib/Microsoft.VisualStudio.Platform.VSEditor.Interop.dll
--------------------------------------------------------------------------------
/lib/Microsoft.VisualStudio.Platform.VSEditor.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/lib/Microsoft.VisualStudio.Platform.VSEditor.dll
--------------------------------------------------------------------------------
/lib/Microsoft.VisualStudio.Telemetry.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/lib/Microsoft.VisualStudio.Telemetry.dll
--------------------------------------------------------------------------------
/lib/Microsoft.VisualStudio.Text.Internal.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/EditorConfigLanguage/5848368ab1b727ea313a0aad29c7cdc529390a5f/lib/Microsoft.VisualStudio.Text.Internal.dll
--------------------------------------------------------------------------------
/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/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/BraceCompletion/BraceCompletionContextProvider.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.Composition;
2 | using System.Diagnostics;
3 | using Microsoft.VisualStudio.Text;
4 | using Microsoft.VisualStudio.Text.BraceCompletion;
5 | using Microsoft.VisualStudio.Text.Editor;
6 | using Microsoft.VisualStudio.Utilities;
7 | using Microsoft.VisualStudio.Text.Classification;
8 | using Microsoft.VisualStudio.Language.StandardClassification;
9 | using System.Collections.Generic;
10 |
11 | namespace EditorConfig
12 | {
13 | [Export(typeof(IBraceCompletionContextProvider))]
14 | [BracePair('(', ')')]
15 | [BracePair('[', ']')]
16 | [BracePair('{', '}')]
17 | [ContentType(Constants.LanguageName)]
18 | internal sealed class BraceCompletionContextProvider : IBraceCompletionContextProvider
19 | {
20 | [Import]
21 | IClassifierAggregatorService ClassifierService { get; set; }
22 |
23 | public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
24 | {
25 | if (IsValidBraceCompletionContext(openingPoint))
26 | {
27 | context = new BraceCompletionContext();
28 | return true;
29 | }
30 | else
31 | {
32 | context = null;
33 | return false;
34 | }
35 | }
36 |
37 | private bool IsValidBraceCompletionContext(SnapshotPoint openingPoint)
38 | {
39 | Debug.Assert(openingPoint.Position >= 0, "SnapshotPoint.Position should always be zero or positive.");
40 |
41 | if (openingPoint.Position > 0)
42 | {
43 | IList classificationSpans = ClassifierService.GetClassifier(openingPoint.Snapshot.TextBuffer)
44 | .GetClassificationSpans(new SnapshotSpan(openingPoint - 1, 1));
45 |
46 | foreach (ClassificationSpan span in classificationSpans)
47 | {
48 | if (span.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Comment))
49 | {
50 | return false;
51 | }
52 | if (span.ClassificationType.IsOfType(PredefinedClassificationTypeNames.String))
53 | {
54 | return false;
55 | }
56 | }
57 | }
58 | return true;
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/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/Classifier/EditorConfigClassifier.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Language.StandardClassification;
2 | using Microsoft.VisualStudio.Text;
3 | using Microsoft.VisualStudio.Text.Classification;
4 | using System;
5 | using System.Collections.Generic;
6 |
7 | namespace EditorConfig
8 | {
9 | internal class EditorConfigClassifier : IClassifier
10 | {
11 | private static Dictionary _map;
12 | private EditorConfigDocument _document;
13 | private ITextBuffer _buffer;
14 |
15 | public EditorConfigClassifier(IClassificationTypeRegistryService registry, ITextBuffer buffer)
16 | {
17 | _map = _map ?? new Dictionary {
18 | { ItemType.Comment, registry.GetClassificationType(PredefinedClassificationTypeNames.Comment)},
19 | { ItemType.Section, registry.GetClassificationType(PredefinedClassificationTypeNames.String)},
20 | { ItemType.Keyword, registry.GetClassificationType(PredefinedClassificationTypeNames.Identifier)},
21 | { ItemType.Value, registry.GetClassificationType(PredefinedClassificationTypeNames.Keyword)},
22 | { ItemType.Severity, registry.GetClassificationType(PredefinedClassificationTypeNames.SymbolDefinition)},
23 | { ItemType.Suppression, registry.GetClassificationType(PredefinedClassificationTypeNames.ExcludedCode)},
24 | };
25 |
26 | _buffer = buffer;
27 | _document = EditorConfigDocument.FromTextBuffer(buffer);
28 | }
29 |
30 | public IList GetClassificationSpans(SnapshotSpan span)
31 | {
32 | var list = new List();
33 |
34 | if (_document.IsParsing)
35 | return list;
36 |
37 | IEnumerable parseItems = _document.ItemsInSpan(span);
38 |
39 | foreach (ParseItem item in parseItems)
40 | {
41 | if (_map.ContainsKey(item.ItemType))
42 | {
43 | var snapshotSpan = new SnapshotSpan(span.Snapshot, item.Span);
44 | list.Add(new ClassificationSpan(snapshotSpan, _map[item.ItemType]));
45 | }
46 | }
47 |
48 | return list;
49 | }
50 |
51 | public event EventHandler ClassificationChanged
52 | {
53 | add { }
54 | remove { }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/src/CodeExpansions/Snippets/csharpstyle.snippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | C# code style settings
6 | csharpstyle
7 | Code snippet for default C# code style settings
8 | Mads Kristensen
9 |
10 | Expansion
11 |
12 |
13 |
14 |
15 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/Commands/CreateEditorConfigFileAnyCode.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio;
2 | using Microsoft.VisualStudio.OLE.Interop;
3 | using Microsoft.VisualStudio.Shell;
4 | using Microsoft.VisualStudio.Workspace.VSIntegration.UI;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.ComponentModel.Composition;
8 | using System.IO;
9 | using System.Windows;
10 |
11 | namespace EditorConfig.Commands
12 | {
13 | [Export(typeof(INodeExtender))]
14 | public class CreateEditorConfigFileAnyCodeProvider : INodeExtender
15 | {
16 | private IWorkspaceCommandHandler _handler = new CreateEditorConfigFileAnyCode();
17 | public IChildrenSource ProvideChildren(WorkspaceVisualNodeBase parentNode) => null;
18 |
19 | public IWorkspaceCommandHandler ProvideCommandHandler(WorkspaceVisualNodeBase parentNode)
20 | {
21 | if (parentNode is IFolderNode)
22 | {
23 | return _handler;
24 | }
25 |
26 | return null;
27 | }
28 | }
29 |
30 | public class CreateEditorConfigFileAnyCode : IWorkspaceCommandHandler
31 | {
32 | public bool IgnoreOnMultiselect => true;
33 |
34 | public int Priority => 100;
35 |
36 | public int Exec(List selection, Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
37 | {
38 | ThreadHelper.ThrowIfNotOnUIThread();
39 |
40 | if (IsSupportedCommand(pguidCmdGroup, nCmdID))
41 | {
42 | if (selection.Count == 1 && selection[0] is IFolderNode folder)
43 | {
44 | string fileName = Path.Combine(folder.FullPath, Constants.FileName);
45 |
46 | if (File.Exists(fileName))
47 | {
48 | MessageBox.Show(Resources.Text.EditorConfigFileAlreadyExist, Vsix.Name, MessageBoxButton.OK, MessageBoxImage.Information);
49 | }
50 | else
51 | {
52 | File.WriteAllText(fileName, Constants.DefaultFileContent);
53 | VsHelpers.OpenFile(fileName);
54 | }
55 |
56 | return VSConstants.S_OK;
57 | }
58 | }
59 |
60 | return (int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED;
61 | }
62 |
63 | public bool QueryStatus(List selection, Guid pguidCmdGroup, uint nCmdID, ref uint cmdf, ref string customTitle)
64 | {
65 | if (selection.Count != 1 || selection[0] is IFileNode)
66 | {
67 | return false;
68 | }
69 |
70 | if (IsSupportedCommand(pguidCmdGroup, nCmdID))
71 | {
72 | cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED);
73 | return true;
74 | }
75 |
76 | return selection[0].Parent.QueryStatus(pguidCmdGroup, nCmdID, ref cmdf, ref customTitle);
77 | }
78 |
79 | private static bool IsSupportedCommand(Guid pguidCmdGroup, uint nCmdID)
80 | {
81 | return pguidCmdGroup == PackageGuids.guidEditorConfigPackageCmdSet && nCmdID == PackageIds.CreateEditorConfigFileAnyCodeId;
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/Commands/F1Help.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio;
2 | using Microsoft.VisualStudio.OLE.Interop;
3 | using System;
4 | using Microsoft.VisualStudio.Shell;
5 | using Microsoft.VisualStudio.Text.Editor;
6 | using Microsoft.VisualStudio.TextManager.Interop;
7 | using System.Text.RegularExpressions;
8 |
9 | namespace EditorConfig
10 | {
11 | internal sealed class F1Help : BaseCommand
12 | {
13 | private Guid _commandGroup = typeof(VSConstants.VSStd97CmdID).GUID;
14 | private const uint _commandId = (uint)VSConstants.VSStd97CmdID.F1Help;
15 | private IVsTextView _vsTextView;
16 | private IWpfTextView _view;
17 |
18 | public F1Help(IVsTextView textViewAdapter, IWpfTextView view)
19 | {
20 | _vsTextView = textViewAdapter;
21 | _view = view;
22 | }
23 |
24 | public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
25 | {
26 | if (pguidCmdGroup == _commandGroup && nCmdID == _commandId)
27 | {
28 | _vsTextView.GetCaretPos(out int line, out int column);
29 | string curLine = _view.TextSnapshot.GetLineFromLineNumber(line).GetText();
30 |
31 | var pattern = new Regex(@"([\w .]+)=");
32 | if (pattern.IsMatch(curLine))
33 | {
34 | GroupCollection groups = pattern.Match(curLine).Groups;
35 | string ruleName = groups[1].Value.ToString().Trim();
36 |
37 | SchemaCatalog.TryGetKeyword(ruleName, out Keyword keyword);
38 | if (keyword != null && keyword.DocumentationLink != null)
39 | {
40 | VsShellUtilities.OpenSystemBrowser(keyword.DocumentationLink);
41 | }
42 | else
43 | {
44 | VsShellUtilities.OpenSystemBrowser(Constants.Homepage);
45 | }
46 | }
47 | else
48 | {
49 | VsShellUtilities.OpenSystemBrowser(Constants.Homepage);
50 | }
51 | return VSConstants.S_OK;
52 | }
53 |
54 | ThreadHelper.ThrowIfNotOnUIThread();
55 |
56 | return Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
57 | }
58 |
59 | public override int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
60 | {
61 | if (pguidCmdGroup == _commandGroup && prgCmds[0].cmdID == _commandId)
62 | {
63 | prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED;
64 | return VSConstants.S_OK;
65 | }
66 |
67 | ThreadHelper.ThrowIfNotOnUIThread();
68 |
69 | return Next.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText);
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/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/Commands/NavigateToParent.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio;
2 | using Microsoft.VisualStudio.OLE.Interop;
3 | using Microsoft.VisualStudio.Shell;
4 | using Microsoft.VisualStudio.Shell.Interop;
5 | using Microsoft.VisualStudio.Text;
6 | using System;
7 |
8 | namespace EditorConfig
9 | {
10 | internal sealed class NavigateToParent : BaseCommand
11 | {
12 | private Guid _commandGroup = PackageGuids.guidEditorConfigPackageCmdSet;
13 | private const uint _commandId = PackageIds.NavigateToParentId;
14 | private ITextBuffer _buffer;
15 |
16 | public NavigateToParent(ITextBuffer buffer)
17 | {
18 | _buffer = buffer;
19 | }
20 |
21 | public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
22 | {
23 | ThreadHelper.ThrowIfNotOnUIThread();
24 |
25 | if (pguidCmdGroup == _commandGroup && nCmdID == _commandId)
26 | {
27 | var document = EditorConfigDocument.FromTextBuffer(_buffer);
28 | EditorConfigDocument parent = document?.Parent;
29 |
30 | if (parent != null)
31 | {
32 | VsHelpers.PreviewDocument(parent.FileName);
33 | }
34 | else
35 | {
36 | var statusBar = Package.GetGlobalService(typeof(SVsStatusbar)) as IVsStatusbar;
37 | statusBar.IsFrozen(out int frozen);
38 |
39 | if (frozen == 0)
40 | {
41 | statusBar.SetText("This is a root document with no inheritance");
42 | }
43 | }
44 |
45 | return VSConstants.S_OK;
46 | }
47 |
48 | return Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
49 | }
50 |
51 |
52 | public override int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
53 | {
54 | if (pguidCmdGroup == _commandGroup && prgCmds[0].cmdID == _commandId)
55 | {
56 | var document = EditorConfigDocument.FromTextBuffer(_buffer);
57 | EditorConfigDocument parent = document?.Parent;
58 |
59 | if (parent != null)
60 | {
61 | prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED;
62 | return VSConstants.S_OK;
63 | }
64 |
65 | return VSConstants.S_OK;
66 | }
67 |
68 | ThreadHelper.ThrowIfNotOnUIThread();
69 |
70 | return Next.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText);
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/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/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/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/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/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 |
--------------------------------------------------------------------------------
/src/DragDrop/EditorConfigDropHandler.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Text.Editor;
2 | using Microsoft.VisualStudio.Text.Editor.DragDrop;
3 | using Microsoft.VisualStudio.Text.Operations;
4 | using System;
5 | using System.IO;
6 | using System.Windows;
7 | using Microsoft.VisualStudio.Text;
8 | using System.Collections.Specialized;
9 |
10 | namespace EditorConfig
11 | {
12 | internal class EditorConfigDropHandler : IDropHandler
13 | {
14 | private IWpfTextView _view;
15 | private ITextBufferUndoManager _undoManager;
16 | private string _ext;
17 |
18 | const string _template = "[*{0}]";
19 |
20 | public EditorConfigDropHandler(IWpfTextView view, ITextBufferUndoManager undoManager)
21 | {
22 | _view = view;
23 | _undoManager = undoManager;
24 | }
25 |
26 | public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
27 | {
28 | try
29 | {
30 |
31 | SnapshotPoint position = dragDropInfo.VirtualBufferPosition.Position;
32 | string header = string.Format(_template, _ext);
33 |
34 | ITextSnapshotLine line = _view.TextBuffer.CurrentSnapshot.GetLineFromPosition(position);
35 |
36 | if (!line.Extent.IsEmpty)
37 | header = Environment.NewLine + header;
38 |
39 | using (ITextUndoTransaction transaction = _undoManager.TextBufferUndoHistory.CreateTransaction($"Dragged {_ext}"))
40 | using (ITextEdit edit = _view.TextBuffer.CreateEdit())
41 | {
42 | edit.Insert(position, header);
43 | edit.Apply();
44 | transaction.Complete();
45 | }
46 |
47 | Telemetry.TrackUserTask("FileDragged");
48 | }
49 | catch (Exception ex)
50 | {
51 | Telemetry.TrackException("DragDrop", ex);
52 | }
53 |
54 | return DragDropPointerEffects.Copy;
55 | }
56 |
57 | public void HandleDragCanceled()
58 | { }
59 |
60 | public DragDropPointerEffects HandleDragStarted(DragDropInfo dragDropInfo)
61 | {
62 | return DragDropPointerEffects.All;
63 | }
64 |
65 | public DragDropPointerEffects HandleDraggingOver(DragDropInfo dragDropInfo)
66 | {
67 | return DragDropPointerEffects.All;
68 | }
69 |
70 | public bool IsDropEnabled(DragDropInfo dragDropInfo)
71 | {
72 | string draggedFileName = GetDraggedFilename(dragDropInfo);
73 | _ext = Path.GetExtension(draggedFileName);
74 |
75 | return !string.IsNullOrWhiteSpace(_ext);
76 | }
77 |
78 | private static string GetDraggedFilename(DragDropInfo info)
79 | {
80 | var data = new DataObject(info.Data);
81 |
82 | if (info.Data.GetDataPresent("FileDrop"))
83 | {
84 | // The drag and drop operation came from the file system
85 | StringCollection files = data.GetFileDropList();
86 |
87 | if (files != null && files.Count == 1)
88 | {
89 | return files[0];
90 | }
91 | }
92 | else if (info.Data.GetDataPresent("CF_VSSTGPROJECTITEMS"))
93 | {
94 | // The drag and drop operation came from the VS solution explorer
95 | return data.GetText();
96 | }
97 |
98 | return null;
99 | }
100 | }
101 | }
--------------------------------------------------------------------------------
/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/EditorConfigPackage.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio;
2 | using Microsoft.VisualStudio.Shell;
3 | using Microsoft.VisualStudio.Shell.Interop;
4 | using System;
5 | using System.ComponentModel.Design;
6 | using System.Runtime.InteropServices;
7 | using System.Threading;
8 | using Task = System.Threading.Tasks.Task;
9 |
10 | namespace EditorConfig
11 | {
12 | [Guid(PackageGuids.guidEditorConfigPackageString)]
13 | [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
14 | [InstalledProductRegistration("#110", "#112", Vsix.Version, IconResourceID = 400)]
15 |
16 | [ProvideLanguageService(typeof(EditorConfigLanguage), Constants.LanguageName, 101, ShowCompletion = true, EnableAsyncCompletion = true, EnableAdvancedMembersOption = true, HideAdvancedMembersByDefault = false, QuickInfo = true, ShowDropDownOptions = true, DefaultToInsertSpaces = true, EnableCommenting = true, AutoOutlining = true, EnableLineNumbers = true, MatchBraces = true, MatchBracesAtCaret = true, ShowMatchingBrace = true)]
17 | [ProvideLanguageExtension(typeof(EditorConfigLanguage), Constants.FileName)]
18 | [ProvideLanguageEditorOptionPage(typeof(FormatterOptions), Constants.LanguageName, null, "Formatting", "#101", new[] { "editorconfig", "formatting" })]
19 | [ProvideLanguageEditorOptionPage(typeof(ValidationOptions), Constants.LanguageName, null, "Validation", "#102", new[] { "editorconfig", "validation" })]
20 | [ProvideLanguageEditorOptionPage(typeof(CompletionOptions), Constants.LanguageName, null, "Intellisense", "#103", new[] { "editorconfig", "intellisenes", "completion" })]
21 | [ProvideLanguageCodeExpansion(typeof(EditorConfigLanguage), Constants.LanguageName, 0, Constants.LanguageName, null, SearchPaths = @"$PackageFolder$\CodeExpansions\Snippets")]
22 | [ProvideEditorFactory(typeof(EditorFactory), 110, CommonPhysicalViewAttributes = (int)__VSPHYSICALVIEWATTRIBUTES.PVA_SupportsPreview, TrustLevel = __VSEDITORTRUSTLEVEL.ETL_AlwaysTrusted)]
23 | [ProvideEditorLogicalView(typeof(EditorFactory), VSConstants.LOGVIEWID.TextView_string, IsTrusted = true)]
24 |
25 | [ProvideEditorExtension(typeof(EditorFactory), Constants.FileName, 1000)]
26 | [ProvideBraceCompletion(Constants.LanguageName)]
27 | [ProvideMenuResource("Menus.ctmenu", 1)]
28 | public sealed class EditorConfigPackage : AsyncPackage
29 | {
30 | public static EditorConfigLanguage Language
31 | {
32 | get;
33 | private set;
34 | }
35 |
36 | public static FormatterOptions FormatterOptions
37 | {
38 | get;
39 | private set;
40 | }
41 |
42 | public static ValidationOptions ValidationOptions
43 | {
44 | get;
45 | private set;
46 | }
47 |
48 | public static CompletionOptions CompletionOptions
49 | {
50 | get;
51 | private set;
52 | }
53 |
54 | protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress)
55 | {
56 | Language = new EditorConfigLanguage(this);
57 | FormatterOptions = (FormatterOptions)GetDialogPage(typeof(FormatterOptions));
58 | ValidationOptions = (ValidationOptions)GetDialogPage(typeof(ValidationOptions));
59 | CompletionOptions = (CompletionOptions)GetDialogPage(typeof(CompletionOptions));
60 |
61 | var serviceContainer = this as IServiceContainer;
62 | serviceContainer.AddService(typeof(EditorConfigLanguage), Language, true);
63 |
64 | var editorFactory = new EditorFactory(this, typeof(EditorConfigLanguage).GUID);
65 | RegisterEditorFactory(editorFactory);
66 |
67 | if (await GetServiceAsync(typeof(IMenuCommandService)) is OleMenuCommandService commandService)
68 | {
69 | CreateEditorConfigFile.Initialize(this, commandService);
70 | OpenSettings.Initialize(this, commandService);
71 | SuppressError.Initialize(this, commandService);
72 | }
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/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/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/Formatting/FormattingType.cs:
--------------------------------------------------------------------------------
1 | namespace EditorConfig
2 | {
3 | public enum FormattingType
4 | {
5 | None,
6 | Section,
7 | Document
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/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/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/LanguageService/LanguageService.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Package;
2 | using Microsoft.VisualStudio.Shell;
3 | using Microsoft.VisualStudio.TextManager.Interop;
4 | using System;
5 | using System.Runtime.InteropServices;
6 |
7 | namespace EditorConfig
8 | {
9 | [Guid(LanguageGuid)]
10 | public class EditorConfigLanguage : LanguageService
11 | {
12 | public const string LanguageGuid = "f99a05b5-311b-4772-92fc-6441a78ca26f";
13 | private LanguagePreferences preferences = null;
14 |
15 | public EditorConfigLanguage(object site)
16 | {
17 | ThreadHelper.ThrowIfNotOnUIThread();
18 |
19 | SetSite(site);
20 | }
21 |
22 | public override Source CreateSource(IVsTextLines buffer)
23 | {
24 | return new EditorConfigSource(this, buffer, new EditorConfigColorizer(this, buffer, null));
25 | }
26 |
27 | public override TypeAndMemberDropdownBars CreateDropDownHelper(IVsTextView forView)
28 | {
29 | if (Preferences.ShowNavigationBar)
30 | return new DropDownBars(this, forView);
31 |
32 | return null;
33 | }
34 |
35 | public override LanguagePreferences GetLanguagePreferences()
36 | {
37 | if (preferences == null)
38 | {
39 | preferences = new LanguagePreferences(Site, typeof(EditorConfigLanguage).GUID, Name);
40 |
41 | if (preferences != null)
42 | {
43 | preferences.Init();
44 |
45 | preferences.EnableCodeSense = true;
46 | preferences.EnableMatchBraces = true;
47 | preferences.EnableMatchBracesAtCaret = true;
48 | preferences.EnableShowMatchingBrace = true;
49 | preferences.EnableCommenting = true;
50 | preferences.HighlightMatchingBraceFlags = _HighlightMatchingBraceFlags.HMB_USERECTANGLEBRACES;
51 | preferences.LineNumbers = true;
52 | preferences.MaxErrorMessages = 100;
53 | preferences.AutoOutlining = true;
54 | preferences.MaxRegionTime = 2000;
55 | preferences.ShowNavigationBar = true;
56 | preferences.InsertTabs = false;
57 | preferences.IndentSize = 2;
58 | preferences.ShowNavigationBar = true;
59 | preferences.EnableAsyncCompletion = true;
60 |
61 | preferences.WordWrap = false;
62 | preferences.WordWrapGlyphs = true;
63 |
64 | preferences.AutoListMembers = true;
65 | preferences.EnableQuickInfo = true;
66 | preferences.ParameterInformation = true;
67 | preferences.HideAdvancedMembers = false;
68 | }
69 | }
70 |
71 | return preferences;
72 | }
73 |
74 | public override IScanner GetScanner(IVsTextLines buffer)
75 | {
76 | return null;
77 | }
78 |
79 | public override AuthoringScope ParseSource(ParseRequest req)
80 | {
81 | return null;
82 | }
83 |
84 | public override string GetFormatFilterList()
85 | {
86 | return $"EditorConfig File (*{Constants.FileName})|*{Constants.FileName}";
87 | }
88 |
89 | public override string Name => Constants.LanguageName;
90 |
91 | public sealed override void Dispose()
92 | {
93 | Dispose(true);
94 | GC.SuppressFinalize(this);
95 | }
96 |
97 | private void Dispose(bool dispose)
98 | {
99 | try
100 | {
101 | if (preferences != null)
102 | {
103 | preferences.Dispose();
104 | preferences = null;
105 | }
106 | }
107 | finally
108 | {
109 | base.Dispose();
110 | }
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/src/Monikers.imagemanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/Outlining/OutliningTagger.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell;
2 | using Microsoft.VisualStudio.Text;
3 | using Microsoft.VisualStudio.Text.Tagging;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using Task = System.Threading.Tasks.Task;
8 |
9 | namespace EditorConfig
10 | {
11 | internal sealed class OutliningTagger : ITagger
12 | {
13 | private readonly ITextBuffer _buffer;
14 | private ITextSnapshot _snapshot;
15 | private EditorConfigDocument _document;
16 |
17 | public OutliningTagger(ITextBuffer buffer)
18 | {
19 | _buffer = buffer;
20 | _snapshot = buffer.CurrentSnapshot;
21 |
22 | _document = EditorConfigDocument.FromTextBuffer(buffer);
23 | _document.Parsed += DocumentChanged;
24 |
25 | StartParsing();
26 | }
27 |
28 | public List Regions { get; private set; } = new List();
29 |
30 | public IEnumerable> GetTags(NormalizedSnapshotSpanCollection spans)
31 | {
32 | if (spans.Count == 0 || !Regions.Any())
33 | yield break;
34 |
35 | IEnumerable currentRegions = Regions;
36 | ITextSnapshot currentSnapshot = _snapshot;
37 | SnapshotSpan entire = new SnapshotSpan(spans[0].Start, spans[spans.Count - 1].End).TranslateTo(currentSnapshot, SpanTrackingMode.EdgeExclusive);
38 | int startLineNumber = entire.Start.GetContainingLine().LineNumber;
39 | int endLineNumber = entire.End.GetContainingLine().LineNumber;
40 |
41 | foreach (Region region in currentRegions)
42 | {
43 | if (region.StartLine <= endLineNumber && region.EndLine >= startLineNumber)
44 | {
45 | ITextSnapshotLine startLine = currentSnapshot.GetLineFromLineNumber(region.StartLine);
46 | string text = startLine.GetText();
47 | string hover = entire.Snapshot.GetText(region.StartOffset, region.EndOffset - region.StartOffset);
48 |
49 | yield return new TagSpan(
50 | new SnapshotSpan(currentSnapshot, region.StartOffset, region.EndOffset - region.StartOffset),
51 | new OutliningRegionTag(false, false, text, hover));
52 | }
53 | }
54 | }
55 |
56 | public event EventHandler TagsChanged;
57 |
58 | void DocumentChanged(object sender, EventArgs e)
59 | {
60 | StartParsing();
61 | }
62 |
63 | private void StartParsing()
64 | {
65 | ThreadHelper.JoinableTaskFactory.StartOnIdle(
66 | () =>
67 | {
68 | if (TagsChanged == null || _document.IsParsing)
69 | return Task.CompletedTask;
70 |
71 | Regions.Clear();
72 | ReParse();
73 | TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(_snapshot, 0, _snapshot.Length)));
74 | return Task.CompletedTask;
75 | },
76 | VsTaskRunContext.UIThreadIdlePriority);
77 | }
78 |
79 | void ReParse()
80 | {
81 | ITextSnapshot newSnapshot = _buffer.CurrentSnapshot;
82 | var newRegions = new List();
83 |
84 | foreach (Section section in _document.Sections)
85 | {
86 | ITextSnapshotLine startLine = newSnapshot.GetLineFromPosition(section.Span.Start);
87 | ITextSnapshotLine endLine = newSnapshot.GetLineFromPosition(section.Span.End);
88 |
89 | var region = new Region
90 | {
91 | StartLine = startLine.LineNumber,
92 | StartOffset = startLine.Start,
93 | EndLine = endLine.LineNumber,
94 | EndOffset = endLine.End
95 | };
96 |
97 | newRegions.Add(region);
98 | }
99 |
100 | _snapshot = newSnapshot;
101 | Regions = newRegions.Where(line => line.StartLine != line.EndLine).ToList();
102 | }
103 | }
104 |
105 | class Region
106 | {
107 | public int StartLine { get; set; }
108 | public int StartOffset { get; set; }
109 | public int EndLine { get; set; }
110 | public int EndOffset { get; set; }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/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/Parser/EditorConfigDocument.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Text;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 |
6 | namespace EditorConfig
7 | {
8 | /// A representation of the .editorconfig document.
9 | sealed partial class EditorConfigDocument : IDisposable
10 | {
11 | private EditorConfigDocument(ITextBuffer buffer)
12 | {
13 | TextBuffer = buffer;
14 |
15 | InitializeParser();
16 | InitializeInheritance();
17 | }
18 |
19 | /// The ITextBuffer associated with the document.
20 | public ITextBuffer TextBuffer { get; }
21 |
22 | /// A list of all the parse items in the document.
23 | public List ParseItems { get; private set; } = new List();
24 |
25 | /// A list of all the sections in the document.
26 | public List Sections { get; private set; } = new List();
27 |
28 | /// A list of all the properties in the root of the document.
29 | public List Properties { get; private set; } = new List();
30 |
31 | /// A list of all the error suppressions in the document.
32 | public List Suppressions { get; private set; } = new List();
33 |
34 | /// The root property of the document if one is specified
35 | public Property Root
36 | {
37 | get
38 | {
39 | return Properties.FirstOrDefault(p => p.Keyword.Text.Equals(SchemaCatalog.Root));
40 | }
41 | }
42 |
43 | /// A list of all the sections in the document.
44 | public static EditorConfigDocument FromTextBuffer(ITextBuffer buffer)
45 | {
46 | return buffer.Properties.GetOrCreateSingletonProperty(() => new EditorConfigDocument(buffer));
47 | }
48 |
49 | /// Returns all the parse items contained within the specified span.
50 | public IEnumerable ItemsInSpan(Span span)
51 | {
52 | return ParseItems?.Where(i => span.Contains(i.Span));
53 | }
54 |
55 | /// Returns the ParseItem located at the specified position.
56 | public ParseItem ItemAtPosition(int position)
57 | {
58 | return ParseItems?.FirstOrDefault(p => p.Span.Contains(position - 1));
59 | }
60 |
61 | /// Returns the Property located at the specified position.
62 | public Property PropertyAtPosition(int position)
63 | {
64 | foreach (Property property in Properties)
65 | {
66 | if (property.Span.Contains(position - 1))
67 | return property;
68 | }
69 |
70 | foreach (Property property in Sections.SelectMany(s => s.Properties))
71 | {
72 | if (property.Span.Contains(position - 1))
73 | return property;
74 | }
75 |
76 | return null;
77 | }
78 |
79 | /// Returns a list of all rules included in the current or parent document(s).
80 | public List GetAllIncludedRules()
81 | {
82 | EditorConfigDocument curDoc = this;
83 | var rules = new List();
84 | while (curDoc != null)
85 | {
86 | foreach (ParseItem parseItem in curDoc.ParseItems)
87 | {
88 | string parseItemStr = parseItem.Text;
89 | if (!rules.Contains(parseItemStr) && parseItem.ItemType == ItemType.Keyword)
90 | {
91 | rules.Add(parseItemStr);
92 | }
93 | }
94 | curDoc = curDoc.Parent;
95 | }
96 | return rules;
97 | }
98 |
99 | public void Dispose()
100 | {
101 | DisposeParser();
102 | DisposeInheritance();
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/Parser/EditorConfigDocumentInheritance.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.ComponentModelHost;
2 | using Microsoft.VisualStudio.Shell;
3 | using Microsoft.VisualStudio.Text;
4 | using Microsoft.VisualStudio.Utilities;
5 | using System;
6 | using System.ComponentModel.Composition;
7 | using System.IO;
8 |
9 | namespace EditorConfig
10 | {
11 | public partial class EditorConfigDocument
12 | {
13 | private IContentType _contentType;
14 | private EditorConfigDocument _parent;
15 |
16 | [Import]
17 | private ITextDocumentFactoryService DocumentService { get; set; }
18 |
19 | /// The absolute file path to the .editorconfig document.
20 | public string FileName { get; private set; }
21 |
22 | /// Returns a parent document if one exist.
23 | public EditorConfigDocument Parent
24 | {
25 | get
26 | {
27 | if (Root != null && Root.IsValid && Root.Value.Text.Is("true") && Root.Severity == null)
28 | return null;
29 |
30 | if (_parent == null)
31 | _parent = InheritsFrom();
32 |
33 | return _parent;
34 | }
35 | }
36 |
37 | private void InitializeInheritance()
38 | {
39 | VsHelpers.SatisfyImportsOnce(this);
40 |
41 | var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
42 |
43 | if (componentModel == null)
44 | return;
45 |
46 | IContentTypeRegistryService contentTypeRegistry = componentModel.DefaultExportProvider.GetExportedValue();
47 | _contentType = contentTypeRegistry.GetContentType(Constants.LanguageName);
48 |
49 | if (DocumentService.TryGetTextDocument(TextBuffer, out ITextDocument doc))
50 | {
51 | FileName = doc.FilePath;
52 | }
53 | }
54 |
55 | private EditorConfigDocument InheritsFrom()
56 | {
57 | var file = new FileInfo(FileName);
58 | DirectoryInfo parent = file.Directory.Parent;
59 |
60 | while (parent != null)
61 | {
62 | string parentFileName = Path.Combine(parent.FullName, Constants.FileName);
63 |
64 | if (File.Exists(parentFileName))
65 | {
66 | ITextDocument doc = DocumentService.CreateAndLoadTextDocument(parentFileName, _contentType);
67 | return new EditorConfigDocument(doc.TextBuffer) { FileName = parentFileName };
68 | }
69 |
70 | parent = parent.Parent;
71 | }
72 |
73 | return null;
74 | }
75 |
76 | private void DisposeInheritance()
77 | {
78 | if (_parent != null)
79 | {
80 | _parent.Dispose();
81 | }
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/Parser/ParseItem.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Text;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System;
5 |
6 | namespace EditorConfig
7 | {
8 | /// A building block of the document.
9 | public class ParseItem
10 | {
11 | public ParseItem(EditorConfigDocument document, ItemType type, Span span, string text)
12 | {
13 | Document = document;
14 | ItemType = type;
15 | Span = span;
16 | Text = text;
17 | }
18 |
19 | /// The document this item belongs to.
20 | public EditorConfigDocument Document { get; set; }
21 |
22 | /// The span of this item in the text buffer.
23 | public Span Span { get; set; }
24 |
25 | /// The type of item.
26 | public ItemType ItemType { get; set; }
27 |
28 | /// The text of this item in the text buffer.
29 | public string Text { get; set; }
30 |
31 | /// A list of validation errors.
32 | public List Errors { get; } = new List();
33 |
34 | /// True if the item contains errors; otherwise false.
35 | public bool HasErrors
36 | {
37 | get { return Errors.Any(); }
38 | }
39 |
40 | /// Adds an error to the Errors list if it doesn't already contain it.
41 | public void AddError(DisplayError error)
42 | {
43 | if (!Errors.Any(e => e.Name == error.Name))
44 | Errors.Add(error);
45 | }
46 |
47 | public override string ToString()
48 | {
49 | return ItemType + ": " + Text;
50 | }
51 |
52 | public override int GetHashCode()
53 | {
54 | int textHash = string.IsNullOrEmpty(Text) ? 1 : Text.GetHashCode();
55 | return Span.GetHashCode() ^ textHash;
56 | }
57 |
58 | public override bool Equals(object obj)
59 | {
60 | if (!(obj is ParseItem other))
61 | return false;
62 |
63 | return Equals(other);
64 | }
65 |
66 | public bool Equals(ParseItem other)
67 | {
68 | if (other == null)
69 | return false;
70 |
71 | if (Span != other.Span)
72 | return false;
73 |
74 | return Text.Is(other.Text);
75 | }
76 |
77 | public static bool operator ==(ParseItem a, ParseItem b)
78 | {
79 | if (ReferenceEquals(a, b))
80 | return true;
81 |
82 | if (((object)a == null) || ((object)b == null))
83 | return false;
84 |
85 | return a.Equals(b);
86 | }
87 |
88 | public static bool operator !=(ParseItem a, ParseItem b)
89 | {
90 | return !(a == b);
91 | }
92 | }
93 |
94 | public enum ItemType
95 | {
96 | Comment,
97 | Section,
98 | Keyword,
99 | Value,
100 | Severity,
101 | Suppression,
102 | Unknown
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/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/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/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/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/QuickInfo/EditorConfigQuickInfo.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Language.Intellisense;
2 | using Microsoft.VisualStudio.Text;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 |
7 | namespace EditorConfig
8 | {
9 | internal class EditorConfigQuickInfo : IQuickInfoSource
10 | {
11 | private ITextBuffer _buffer;
12 | private EditorConfigDocument _document;
13 |
14 | public EditorConfigQuickInfo(ITextBuffer buffer)
15 | {
16 | _buffer = buffer;
17 | _document = EditorConfigDocument.FromTextBuffer(buffer);
18 | }
19 |
20 | public void AugmentQuickInfoSession(IQuickInfoSession session, IList