├── .gitattributes
├── .github
└── FUNDING.yml
├── .gitignore
├── Global.props
├── LICENSE
├── SemanticColorizer.sln
├── SemanticColorizer
├── CSharpExtensions.cs
├── ClassificationDefinitions.cs
├── Constants.cs
├── EditorFormats.cs
├── Extensions.cs
├── LICENSE.txt
├── Properties
│ └── AssemblyInfo.cs
├── ReleaseNotes.txt
├── SemanticColorizer.cs
├── SemanticColorizer.csproj
├── SemanticColorizerExample.png
├── VisualBasicExtensions.cs
├── app.config
├── packages.config
├── rainbow.png
└── source.extension.vsixmanifest
├── TestFile.cs
├── readme.md
└── root.marker
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: arBmind
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 | [Dd]ebug/
11 | [Dd]ebugPublic/
12 | [Rr]elease/
13 | x64/
14 | build/
15 | bld/
16 | [Bb]in/
17 | [Oo]bj/
18 |
19 | # MSTest test Results
20 | [Tt]est[Rr]esult*/
21 | [Bb]uild[Ll]og.*
22 |
23 | #NUNIT
24 | *.VisualState.xml
25 | TestResult.xml
26 |
27 | # Build Results of an ATL Project
28 | [Dd]ebugPS/
29 | [Rr]eleasePS/
30 | dlldata.c
31 |
32 | *_i.c
33 | *_p.c
34 | *_i.h
35 | *.ilk
36 | *.meta
37 | *.obj
38 | *.pch
39 | *.pdb
40 | *.pgc
41 | *.pgd
42 | *.rsp
43 | *.sbr
44 | *.tlb
45 | *.tli
46 | *.tlh
47 | *.tmp
48 | *.tmp_proj
49 | *.log
50 | *.vspscc
51 | *.vssscc
52 | .builds
53 | *.pidb
54 | *.svclog
55 | *.scc
56 |
57 | # Chutzpah Test files
58 | _Chutzpah*
59 |
60 | # Visual C++ cache files
61 | ipch/
62 | *.aps
63 | *.ncb
64 | *.opensdf
65 | *.sdf
66 | *.cachefile
67 |
68 | # Visual Studio profiler
69 | *.psess
70 | *.vsp
71 | *.vspx
72 |
73 | # TFS 2012 Local Workspace
74 | $tf/
75 |
76 | # Guidance Automation Toolkit
77 | *.gpState
78 |
79 | # ReSharper is a .NET coding add-in
80 | _ReSharper*/
81 | *.[Rr]e[Ss]harper
82 | *.DotSettings.user
83 |
84 | # JustCode is a .NET coding addin-in
85 | .JustCode
86 |
87 | # TeamCity is a build add-in
88 | _TeamCity*
89 |
90 | # DotCover is a Code Coverage Tool
91 | *.dotCover
92 |
93 | # NCrunch
94 | _NCrunch_*
95 | .*crunch*.local.xml
96 |
97 | # MightyMoose
98 | *.mm.*
99 | AutoTest.Net/
100 |
101 | # Web workbench (sass)
102 | .sass-cache/
103 |
104 | # Installshield output folder
105 | [Ee]xpress/
106 |
107 | # DocProject is a documentation generator add-in
108 | DocProject/buildhelp/
109 | DocProject/Help/*.HxT
110 | DocProject/Help/*.HxC
111 | DocProject/Help/*.hhc
112 | DocProject/Help/*.hhk
113 | DocProject/Help/*.hhp
114 | DocProject/Help/Html2
115 | DocProject/Help/html
116 |
117 | # Click-Once directory
118 | publish/
119 |
120 | # Publish Web Output
121 | *.[Pp]ublish.xml
122 | *.azurePubxml
123 | ## TODO: Comment the next line if you want to checkin your
124 | ## web deploy settings but do note that will include unencrypted
125 | ## passwords
126 | #*.pubxml
127 |
128 | # NuGet Packages Directory
129 | packages/*
130 | ## TODO: If the tool you use requires repositories.config
131 | ## uncomment the next line
132 | #!packages/repositories.config
133 |
134 | # Enable "build/" folder in the NuGet Packages folder since
135 | # NuGet packages use it for MSBuild targets.
136 | # This line needs to be after the ignore of the build folder
137 | # (and the packages folder if the line above has been uncommented)
138 | !packages/build/
139 |
140 | # Windows Azure Build Output
141 | csx/
142 | *.build.csdef
143 |
144 | # Windows Store app package directory
145 | AppPackages/
146 |
147 | # Others
148 | sql/
149 | *.Cache
150 | ClientBin/
151 | [Ss]tyle[Cc]op.*
152 | ~$*
153 | *~
154 | *.dbmdl
155 | *.dbproj.schemaview
156 | *.pfx
157 | *.publishsettings
158 | node_modules/
159 |
160 | # RIA/Silverlight projects
161 | Generated_Code/
162 |
163 | # Backup & report files from converting an old project file
164 | # to a newer Visual Studio version. Backup files are not needed,
165 | # because we have git ;-)
166 | _UpgradeReport_Files/
167 | Backup*/
168 | UpgradeLog*.XML
169 | UpgradeLog*.htm
170 |
171 | # SQL Server files
172 | *.mdf
173 | *.ldf
174 |
175 | # Business Intelligence projects
176 | *.rdl.data
177 | *.bim.layout
178 | *.bim_*.settings
179 |
180 | # Microsoft Fakes
181 | FakesAssemblies/
182 |
183 | # LightSwitch generated files
184 | GeneratedArtifacts/
185 | _Pvt_Extensions/
186 | ModelManifest.xml
187 | .vs/
188 |
--------------------------------------------------------------------------------
/Global.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Release
5 | AnyCPU
6 |
7 | $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'root.marker'))
8 | $(EnlistmentRoot)\bin
9 | $([System.IO.Path]::GetFullPath( $(BinRoot) ))
10 |
11 |
12 | true
13 | full
14 | false
15 | $(BinRoot)\Debug\
16 | DEBUG;TRACE
17 | prompt
18 | 4
19 | true
20 |
21 |
22 | pdbonly
23 | true
24 | $(BinRoot)\Release\
25 | TRACE
26 | prompt
27 | 4
28 |
29 |
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/SemanticColorizer.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio 14
3 | VisualStudioVersion = 14.0.25420.1
4 | MinimumVisualStudioVersion = 10.0.40219.1
5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemanticColorizer", "SemanticColorizer\SemanticColorizer.csproj", "{1EC486EE-EE95-4159-A186-84EDF5B2EC29}"
6 | EndProject
7 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DC7EA05A-4257-47E3-A403-D080B0DE096D}"
8 | ProjectSection(SolutionItems) = preProject
9 | Global.props = Global.props
10 | readme.md = readme.md
11 | TestFile.cs = TestFile.cs
12 | EndProjectSection
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {1EC486EE-EE95-4159-A186-84EDF5B2EC29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {1EC486EE-EE95-4159-A186-84EDF5B2EC29}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {1EC486EE-EE95-4159-A186-84EDF5B2EC29}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {1EC486EE-EE95-4159-A186-84EDF5B2EC29}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/SemanticColorizer/CSharpExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp;
2 | using Microsoft.CodeAnalysis;
3 | using Microsoft.CodeAnalysis.CSharp.Syntax;
4 |
5 | namespace SemanticColorizer
6 | {
7 | public static class CSharpExtensions
8 | {
9 | public static SyntaxKind CSharpKind(this SyntaxNode node) {
10 | return node.Kind();
11 | }
12 |
13 | public static bool IsCSharpPredefinedTypeSyntax(this SyntaxNode node)
14 | {
15 | return node is PredefinedTypeSyntax;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/SemanticColorizer/ClassificationDefinitions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Text.Classification;
2 | using Microsoft.VisualStudio.Utilities;
3 | using System.ComponentModel.Composition;
4 |
5 | namespace SemanticColorizer
6 | {
7 | internal static class ClassificationTypes
8 | {
9 | #pragma warning disable CS0649
10 | [Export(typeof(ClassificationTypeDefinition))]
11 | [Name(Constants.FieldFormat)]
12 | internal static ClassificationTypeDefinition FieldType;
13 |
14 | [Export(typeof(ClassificationTypeDefinition))]
15 | [Name(Constants.EnumFieldFormat)]
16 | internal static ClassificationTypeDefinition EnumFieldType;
17 |
18 | [Export(typeof(ClassificationTypeDefinition))]
19 | [Name(Constants.ExtensionMethodFormat)]
20 | internal static ClassificationTypeDefinition ExtensionMethodType;
21 |
22 | [Export(typeof(ClassificationTypeDefinition))]
23 | [Name(Constants.StaticMethodFormat)]
24 | internal static ClassificationTypeDefinition StaticMethodType;
25 |
26 | [Export(typeof(ClassificationTypeDefinition))]
27 | [Name(Constants.NormalMethodFormat)]
28 | internal static ClassificationTypeDefinition NormalMethodType;
29 |
30 | [Export(typeof(ClassificationTypeDefinition))]
31 | [Name(Constants.LocalFunctionFormat)]
32 | internal static ClassificationTypeDefinition LocalFunctionType;
33 |
34 | [Export(typeof(ClassificationTypeDefinition))]
35 | [Name(Constants.ConstructorFormat)]
36 | internal static ClassificationTypeDefinition ConstructorType;
37 |
38 | [Export(typeof(ClassificationTypeDefinition))]
39 | [Name(Constants.ParameterFormat)]
40 | internal static ClassificationTypeDefinition ParameterType;
41 |
42 | [Export(typeof(ClassificationTypeDefinition))]
43 | [Name(Constants.NamespaceFormat)]
44 | internal static ClassificationTypeDefinition NamespaceType;
45 |
46 | [Export(typeof(ClassificationTypeDefinition))]
47 | [Name(Constants.PropertyFormat)]
48 | internal static ClassificationTypeDefinition PropertyType;
49 |
50 | [Export(typeof(ClassificationTypeDefinition))]
51 | [Name(Constants.LocalFormat)]
52 | internal static ClassificationTypeDefinition LocalType;
53 |
54 | [Export(typeof(ClassificationTypeDefinition))]
55 | [Name(Constants.TypeSpecialFormat)]
56 | internal static ClassificationTypeDefinition TypeSpecialType;
57 |
58 | [Export(typeof(ClassificationTypeDefinition))]
59 | [Name(Constants.EventFormat)]
60 | internal static ClassificationTypeDefinition EventType;
61 | #pragma warning restore CS0649
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/SemanticColorizer/Constants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SemanticColorizer
4 | {
5 | public static class Constants
6 | {
7 | public const String FieldFormat = "s.semantic-colorizer.field";
8 | public const String EnumFieldFormat = "s.semantic-colorizer.enum-field";
9 | public const String ExtensionMethodFormat = "s.semantic-colorizer.extension-method";
10 | public const String StaticMethodFormat = "s.semantic-colorizer.static-method";
11 | public const String NormalMethodFormat = "s.semantic-colorizer.normal-method";
12 | public const String LocalFunctionFormat = "s.semantic-colorizer.local-function";
13 | public const String ConstructorFormat = "s.semantic-colorizer.constructor";
14 | public const String ParameterFormat = "s.semantic-colorizer.parameter";
15 | public const String NamespaceFormat = "s.semantic-colorizer.namespace";
16 | public const String PropertyFormat = "s.semantic-colorizer.property";
17 | public const String LocalFormat = "s.semantic-colorizer.local";
18 | public const String TypeSpecialFormat = "s.semantic-colorizer.type-special";
19 | public const String EventFormat = "s.semantic-colorizer.event";
20 |
21 | // Built in VS by default
22 | public const String BuiltInClassTypeFormat = "class name";
23 | public const String BuildInStructTypeFormat = "struct name";
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/SemanticColorizer/EditorFormats.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.Classification;
2 | using Microsoft.VisualStudio.Text.Classification;
3 | using Microsoft.VisualStudio.Utilities;
4 | using System.ComponentModel.Composition;
5 | using System.Windows.Media;
6 |
7 | namespace SemanticColorizer
8 | {
9 | [Export(typeof(EditorFormatDefinition))]
10 | [ClassificationType(ClassificationTypeNames = Constants.FieldFormat)]
11 | [Name(Constants.FieldFormat)]
12 | [UserVisible(true)]
13 | [Order(After = ClassificationTypeNames.Identifier)]
14 | internal sealed class SemanticFieldFormat : ClassificationFormatDefinition
15 | {
16 | public SemanticFieldFormat()
17 | {
18 | DisplayName = "Semantic Field";
19 | ForegroundColor = Colors.SaddleBrown;
20 | }
21 | }
22 |
23 | [Export(typeof(EditorFormatDefinition))]
24 | [ClassificationType(ClassificationTypeNames = Constants.EnumFieldFormat)]
25 | [Name(Constants.EnumFieldFormat)]
26 | [UserVisible(true)]
27 | [Order(After = ClassificationTypeNames.Identifier)]
28 | internal sealed class SemanticEnumFieldFormat : ClassificationFormatDefinition
29 | {
30 | public SemanticEnumFieldFormat()
31 | {
32 | DisplayName = "Semantic Enum Field";
33 | }
34 | }
35 |
36 | [Export(typeof(EditorFormatDefinition))]
37 | [ClassificationType(ClassificationTypeNames = Constants.ExtensionMethodFormat)]
38 | [Name(Constants.ExtensionMethodFormat)]
39 | [UserVisible(true)]
40 | [Order(After = ClassificationTypeNames.Identifier)]
41 | internal sealed class SemanticExtensionMethodFormat : ClassificationFormatDefinition
42 | {
43 | public SemanticExtensionMethodFormat()
44 | {
45 | DisplayName = "Semantic Extension Method";
46 | IsItalic = true;
47 | }
48 | }
49 |
50 | [Export(typeof(EditorFormatDefinition))]
51 | [ClassificationType(ClassificationTypeNames = Constants.StaticMethodFormat)]
52 | [Name(Constants.StaticMethodFormat)]
53 | [UserVisible(true)]
54 | [Order(After = ClassificationTypeNames.Identifier)]
55 | internal sealed class SemanticStaticMethodFormat : ClassificationFormatDefinition
56 | {
57 | public SemanticStaticMethodFormat()
58 | {
59 | DisplayName = "Semantic Static Method";
60 | }
61 | }
62 |
63 | [Export(typeof(EditorFormatDefinition))]
64 | [ClassificationType(ClassificationTypeNames = Constants.NormalMethodFormat)]
65 | [Name(Constants.NormalMethodFormat)]
66 | [UserVisible(true)]
67 | [Order(After = ClassificationTypeNames.Identifier)]
68 | internal sealed class SemanticNormalMethodFormat : ClassificationFormatDefinition
69 | {
70 | public SemanticNormalMethodFormat()
71 | {
72 | DisplayName = "Semantic Normal Method";
73 | }
74 | }
75 | [Export(typeof(EditorFormatDefinition))]
76 | [ClassificationType(ClassificationTypeNames = Constants.LocalFunctionFormat)]
77 | [Name(Constants.LocalFunctionFormat)]
78 | [UserVisible(true)]
79 | [Order(After = ClassificationTypeNames.Identifier)]
80 | internal sealed class SemanticLocalFunctionFormat : ClassificationFormatDefinition
81 | {
82 | public SemanticLocalFunctionFormat()
83 | {
84 | DisplayName = "Semantic Local Function";
85 | }
86 | }
87 |
88 | [Export(typeof(EditorFormatDefinition))]
89 | [ClassificationType(ClassificationTypeNames = Constants.ConstructorFormat)]
90 | [Name(Constants.ConstructorFormat)]
91 | [UserVisible(true)]
92 | [Order(After = ClassificationTypeNames.Identifier)]
93 | internal sealed class SemanticConstructorFormat : ClassificationFormatDefinition
94 | {
95 | public SemanticConstructorFormat()
96 | {
97 | DisplayName = "Semantic Constructor";
98 | }
99 | }
100 |
101 | [Export(typeof(EditorFormatDefinition))]
102 | [ClassificationType(ClassificationTypeNames = Constants.ParameterFormat)]
103 | [Name(Constants.ParameterFormat)]
104 | [UserVisible(true)]
105 | [Order(After = ClassificationTypeNames.Identifier)]
106 | internal sealed class SemanticParameterFormat : ClassificationFormatDefinition
107 | {
108 | public SemanticParameterFormat()
109 | {
110 | DisplayName = "Semantic Parameter";
111 | ForegroundColor = Colors.SlateGray;
112 | }
113 | }
114 |
115 | [Export(typeof(EditorFormatDefinition))]
116 | [ClassificationType(ClassificationTypeNames = Constants.NamespaceFormat)]
117 | [Name(Constants.NamespaceFormat)]
118 | [UserVisible(true)]
119 | [Order(After = ClassificationTypeNames.Identifier)]
120 | internal sealed class SemanticNamespaceFormat : ClassificationFormatDefinition
121 | {
122 | public SemanticNamespaceFormat()
123 | {
124 | DisplayName = "Semantic Namespace";
125 | ForegroundColor = Colors.LimeGreen;
126 | }
127 | }
128 |
129 | [Export(typeof(EditorFormatDefinition))]
130 | [ClassificationType(ClassificationTypeNames = Constants.PropertyFormat)]
131 | [Name(Constants.PropertyFormat)]
132 | [UserVisible(true)]
133 | [Order(After = ClassificationTypeNames.Identifier)]
134 | internal sealed class SemanticPropertyFormat : ClassificationFormatDefinition
135 | {
136 | public SemanticPropertyFormat()
137 | {
138 | DisplayName = "Semantic Property";
139 | }
140 | }
141 |
142 | [Export(typeof(EditorFormatDefinition))]
143 | [ClassificationType(ClassificationTypeNames = Constants.LocalFormat)]
144 | [Name(Constants.LocalFormat)]
145 | [UserVisible(true)]
146 | [Order(After = ClassificationTypeNames.Identifier)]
147 | internal sealed class SemanticLocalFormat : ClassificationFormatDefinition
148 | {
149 | public SemanticLocalFormat()
150 | {
151 | DisplayName = "Semantic Local";
152 | }
153 | }
154 |
155 | [Export(typeof(EditorFormatDefinition))]
156 | [ClassificationType(ClassificationTypeNames = Constants.TypeSpecialFormat)]
157 | [Name(Constants.TypeSpecialFormat)]
158 | [UserVisible(true)]
159 | [Order(After = ClassificationTypeNames.Identifier)]
160 | internal sealed class SemanticTypeSpecialFormat : ClassificationFormatDefinition
161 | {
162 | public SemanticTypeSpecialFormat()
163 | {
164 | DisplayName = "Semantic Special Type";
165 | }
166 | }
167 |
168 | [Export(typeof(EditorFormatDefinition))]
169 | [ClassificationType(ClassificationTypeNames = Constants.EventFormat)]
170 | [Name(Constants.EventFormat)]
171 | [UserVisible(true)]
172 | [Order(After = ClassificationTypeNames.Identifier)]
173 | internal sealed class SemanticEventFormat : ClassificationFormatDefinition
174 | {
175 | public SemanticEventFormat()
176 | {
177 | DisplayName = "Semantic Event";
178 | }
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/SemanticColorizer/Extensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.Text;
2 | using Microsoft.VisualStudio.Text;
3 | using Microsoft.VisualStudio.Text.Classification;
4 | using Microsoft.VisualStudio.Text.Tagging;
5 | using System;
6 |
7 | namespace SemanticColorizer
8 | {
9 | public static class Extensions
10 | {
11 | public static ITagSpan ToTagSpan(this TextSpan span, ITextSnapshot snapshot, IClassificationType classificationType)
12 | {
13 | return new TagSpan(
14 | new SnapshotSpan(snapshot, span.Start, span.Length),
15 | new ClassificationTag(classificationType)
16 | );
17 | }
18 | public static String GetText(this ITextSnapshot snapshot, TextSpan span)
19 | {
20 | return snapshot.GetText(new Span(span.Start, span.Length));
21 | }
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/SemanticColorizer/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/SemanticColorizer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("SemanticColorizer")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("HicknHack Software GmbH")]
11 | [assembly: AssemblyProduct("SemanticColorizer")]
12 | [assembly: AssemblyCopyright("")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // Version information for an assembly consists of the following four values:
22 | //
23 | // Major Version
24 | // Minor Version
25 | // Build Number
26 | // Revision
27 | //
28 | // You can specify all the values or you can default the Build and Revision Numbers
29 | // by using the '*' as shown below:
30 | // [assembly: AssemblyVersion("1.0.*")]
31 | [assembly: AssemblyVersion("1.4.0.*")]
32 | [assembly: AssemblyFileVersion("1.0.0.0")]
33 |
--------------------------------------------------------------------------------
/SemanticColorizer/ReleaseNotes.txt:
--------------------------------------------------------------------------------
1 | 2022-01-09 V1.4.0
2 | * Added VS2022 support (thx @darress)
3 | * Colorize struct/class type keywords (thx @darress)
4 |
5 | 2018-06-01 V1.3.2
6 | * Fixed keyword issue (thx @Liminiens)
7 |
8 | 2018-05-14 V1.3.1
9 | * Fixed VS2017 15.7 compatibility (thx @Liminiens)
10 | * Detailed classifications of special types
11 |
12 | some missing versions
13 |
14 | 2015-11-11 V1.1.4
15 | * More Robust Handling (thx @Wakusei)
16 |
17 | 2015-07-22 V1.1.3 Added License
18 | * Added Apache license
19 | * Added ReleaseNotes
20 | * No feature changes
21 |
22 | 2015-07-22 V1.1.0 First Release
23 | * Class fields
24 | * Enum fields
25 | * Static methods
26 | * Regular methods
27 | * Constructors
28 | * Type parameters
29 | * Parameters
30 | * Namespaces
31 | * Class properties
32 | * Local variables
33 | * Special types (built in)
34 | * Normal types
35 |
--------------------------------------------------------------------------------
/SemanticColorizer/SemanticColorizer.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.Classification;
3 | using Microsoft.CodeAnalysis.Text;
4 | using Microsoft.VisualStudio.Text;
5 | using Microsoft.VisualStudio.Text.Classification;
6 | using Microsoft.VisualStudio.Text.Tagging;
7 | using Microsoft.VisualStudio.Utilities;
8 | using System;
9 | using System.Collections.Generic;
10 | using System.ComponentModel.Composition;
11 | using System.Linq;
12 | using System.Threading.Tasks;
13 | using CSharp = Microsoft.CodeAnalysis.CSharp;
14 | using VB = Microsoft.CodeAnalysis.VisualBasic;
15 |
16 | namespace SemanticColorizer
17 | {
18 |
19 | [Export(typeof(ITaggerProvider))]
20 | [ContentType("CSharp")]
21 | [ContentType("Basic")]
22 | [TagType(typeof(IClassificationTag))]
23 | internal class SemanticColorizerProvider : ITaggerProvider
24 | {
25 | #pragma warning disable CS0649
26 | [Import]
27 | internal IClassificationTypeRegistryService ClassificationRegistry; // Set via MEF
28 | #pragma warning restore CS0649
29 |
30 | public ITagger CreateTagger(ITextBuffer buffer) where T : ITag
31 | {
32 | return (ITagger)new SemanticColorizer(buffer, ClassificationRegistry);
33 | }
34 | }
35 |
36 | class SemanticColorizer : ITagger
37 | {
38 | private static readonly HashSet SupportedClassificationTypeNames;
39 | private readonly ITextBuffer _theBuffer;
40 | private readonly IClassificationType _fieldType;
41 | private readonly IClassificationType _enumFieldType;
42 | private readonly IClassificationType _extensionMethodType;
43 | private readonly IClassificationType _staticMethodType;
44 | private readonly IClassificationType _normalMethodType;
45 | private readonly IClassificationType _localFunctionType;
46 | private readonly IClassificationType _constructorType;
47 | private readonly IClassificationType _parameterType;
48 | private readonly IClassificationType _namespaceType;
49 | private readonly IClassificationType _propertyType;
50 | private readonly IClassificationType _localType;
51 | private readonly IClassificationType _typeSpecialType;
52 | private readonly IClassificationType _eventType;
53 |
54 | // Built in VS by default
55 | private readonly IClassificationType _builtInClassType;
56 | private readonly IClassificationType _builtInStructType;
57 |
58 | private Cache _cache;
59 | #pragma warning disable CS0067
60 | public event EventHandler TagsChanged;
61 | #pragma warning restore CS0067
62 |
63 | static class NewClassificationTypeNames
64 | {
65 | public const string PropertyName = "property name";
66 | public const string EventName = "event name";
67 | public const string ExtensionMethodName = "extension method name";
68 | public const string MethodName = "method name";
69 | public const string ParameterName = "parameter name";
70 | public const string LocalName = "local name";
71 | public const string FieldName = "field name";
72 | public const string EnumMemberName = "enum member name";
73 | public const string ConstantName = "constant name";
74 | }
75 | public const MethodKind LocalMethodKind = (MethodKind)17;
76 |
77 | static SemanticColorizer()
78 | {
79 | SupportedClassificationTypeNames = new HashSet
80 | {
81 | NewClassificationTypeNames.FieldName,
82 | NewClassificationTypeNames.PropertyName,
83 | NewClassificationTypeNames.EnumMemberName,
84 | ClassificationTypeNames.Identifier,
85 | ClassificationTypeNames.Keyword,
86 | NewClassificationTypeNames.EventName,
87 | NewClassificationTypeNames.LocalName,
88 | NewClassificationTypeNames.ParameterName,
89 | NewClassificationTypeNames.ExtensionMethodName,
90 | NewClassificationTypeNames.ConstantName,
91 | NewClassificationTypeNames.MethodName
92 | };
93 | }
94 |
95 | internal SemanticColorizer(ITextBuffer buffer, IClassificationTypeRegistryService registry)
96 | {
97 | _theBuffer = buffer;
98 | _fieldType = registry.GetClassificationType(Constants.FieldFormat);
99 | _enumFieldType = registry.GetClassificationType(Constants.EnumFieldFormat);
100 | _extensionMethodType = registry.GetClassificationType(Constants.ExtensionMethodFormat);
101 | _staticMethodType = registry.GetClassificationType(Constants.StaticMethodFormat);
102 | _normalMethodType = registry.GetClassificationType(Constants.NormalMethodFormat);
103 | _localFunctionType = registry.GetClassificationType(Constants.LocalFunctionFormat);
104 | _constructorType = registry.GetClassificationType(Constants.ConstructorFormat);
105 | _parameterType = registry.GetClassificationType(Constants.ParameterFormat);
106 | _namespaceType = registry.GetClassificationType(Constants.NamespaceFormat);
107 | _propertyType = registry.GetClassificationType(Constants.PropertyFormat);
108 | _localType = registry.GetClassificationType(Constants.LocalFormat);
109 | _typeSpecialType = registry.GetClassificationType(Constants.TypeSpecialFormat);
110 | _eventType = registry.GetClassificationType(Constants.EventFormat);
111 |
112 | // Built in VS by default
113 | _builtInClassType = registry.GetClassificationType(Constants.BuiltInClassTypeFormat);
114 | _builtInStructType = registry.GetClassificationType(Constants.BuildInStructTypeFormat);
115 | }
116 |
117 | public IEnumerable> GetTags(NormalizedSnapshotSpanCollection spans)
118 | {
119 | if (spans.Count == 0)
120 | {
121 | return Enumerable.Empty>();
122 | }
123 | if (_cache == null || _cache.Snapshot != spans[0].Snapshot)
124 | {
125 | // this makes me feel dirty, but otherwise it will not
126 | // work reliably, as TryGetSemanticModel() often will return false
127 | // should make this into a completely async process somehow
128 | var task = Cache.Resolve(_theBuffer, spans[0].Snapshot);
129 | try
130 | {
131 | task.Wait();
132 | }
133 | catch (Exception)
134 | {
135 | // TODO: report this to someone.
136 | return Enumerable.Empty>();
137 | }
138 | _cache = task.Result;
139 | if (_cache == null)
140 | {
141 | // TODO: report this to someone.
142 | return Enumerable.Empty>();
143 | }
144 | }
145 | return GetTagsImpl(_cache, spans);
146 | }
147 |
148 | private IEnumerable> GetTagsImpl(
149 | Cache doc,
150 | NormalizedSnapshotSpanCollection spans)
151 | {
152 | var snapshot = spans[0].Snapshot;
153 |
154 | IEnumerable classifiedSpans =
155 | GetClassifiedSpans(doc.Workspace, doc.SemanticModel, spans);
156 |
157 | foreach (var span in classifiedSpans)
158 | {
159 | var node = GetExpression(doc.SyntaxRoot.FindNode(span.TextSpan));
160 | var symbol = doc.SemanticModel.GetSymbolInfo(node).Symbol;
161 | if (symbol == null) symbol = doc.SemanticModel.GetDeclaredSymbol(node);
162 | if (symbol == null)
163 | {
164 | continue;
165 | }
166 | switch (symbol.Kind)
167 | {
168 | case SymbolKind.Field:
169 | switch (span.ClassificationType)
170 | {
171 | case NewClassificationTypeNames.ConstantName:
172 | case NewClassificationTypeNames.FieldName:
173 | yield return span.TextSpan.ToTagSpan(snapshot, _fieldType);
174 | break;
175 | case NewClassificationTypeNames.EnumMemberName:
176 | yield return span.TextSpan.ToTagSpan(snapshot, _enumFieldType);
177 | break;
178 | }
179 | break;
180 | case SymbolKind.Method:
181 | var methodSymbol = (IMethodSymbol)symbol;
182 | switch (span.ClassificationType)
183 | {
184 | case ClassificationTypeNames.Identifier:
185 | if (IsConstructor(methodSymbol))
186 | {
187 | yield return span.TextSpan.ToTagSpan(snapshot, _constructorType);
188 | }
189 | //local function definition
190 | else if (methodSymbol.MethodKind == LocalMethodKind)
191 | {
192 | yield return span.TextSpan.ToTagSpan(snapshot, _localFunctionType);
193 | }
194 | else if (methodSymbol.IsExtensionMethod)
195 | {
196 | yield return span.TextSpan.ToTagSpan(snapshot, _extensionMethodType);
197 | }
198 | break;
199 | case NewClassificationTypeNames.ExtensionMethodName:
200 | yield return span.TextSpan.ToTagSpan(snapshot, _extensionMethodType);
201 | break;
202 | case NewClassificationTypeNames.MethodName:
203 | //local function call
204 | if (methodSymbol.MethodKind == LocalMethodKind)
205 | {
206 | yield return span.TextSpan.ToTagSpan(snapshot, _localFunctionType);
207 | }
208 | //static method call
209 | else if (methodSymbol.MethodKind == MethodKind.Ordinary && methodSymbol.IsStatic)
210 | {
211 | yield return span.TextSpan.ToTagSpan(snapshot, _staticMethodType);
212 | }
213 | //other method call
214 | else
215 | {
216 | yield return span.TextSpan.ToTagSpan(snapshot, _normalMethodType);
217 | }
218 | break;
219 | }
220 | break;
221 | case SymbolKind.Parameter:
222 | yield return span.TextSpan.ToTagSpan(snapshot, _parameterType);
223 | break;
224 | case SymbolKind.Namespace:
225 | yield return span.TextSpan.ToTagSpan(snapshot, _namespaceType);
226 | break;
227 | case SymbolKind.Property:
228 | yield return span.TextSpan.ToTagSpan(snapshot, _propertyType);
229 | break;
230 | case SymbolKind.Local:
231 | yield return span.TextSpan.ToTagSpan(snapshot, _localType);
232 | break;
233 | case SymbolKind.Event:
234 | yield return span.TextSpan.ToTagSpan(snapshot, _eventType);
235 | break;
236 | case SymbolKind.NamedType:
237 | switch (span.ClassificationType)
238 | {
239 | case ClassificationTypeNames.Keyword:
240 | if (node.IsCSharpPredefinedTypeSyntax())
241 | {
242 | var type = (INamedTypeSymbol)symbol;
243 | if (type.SpecialType == SpecialType.System_Void)
244 | continue;
245 | if (type.TypeKind == TypeKind.Struct)
246 | {
247 | yield return span.TextSpan.ToTagSpan(snapshot, _builtInStructType);
248 | }
249 | if (type.TypeKind == TypeKind.Class)
250 | {
251 | yield return span.TextSpan.ToTagSpan(snapshot, _builtInClassType);
252 | }
253 | }
254 | break;
255 | default:
256 | if (IsSpecialType(symbol))
257 | {
258 | yield return span.TextSpan.ToTagSpan(snapshot, _typeSpecialType);
259 | }
260 | break;
261 |
262 | }
263 | break;
264 | }
265 | }
266 | }
267 |
268 | private bool IsSpecialType(ISymbol symbol)
269 | {
270 | var type = (INamedTypeSymbol)symbol;
271 | return type.SpecialType != SpecialType.None;
272 | }
273 |
274 | private SyntaxNode GetExpression(SyntaxNode node)
275 | {
276 | if (node.CSharpKind() == CSharp.SyntaxKind.Argument)
277 | {
278 | return ((CSharp.Syntax.ArgumentSyntax)node).Expression;
279 | }
280 | else if (node.CSharpKind() == CSharp.SyntaxKind.AttributeArgument)
281 | {
282 | return ((CSharp.Syntax.AttributeArgumentSyntax)node).Expression;
283 | }
284 | else if (node.VbKind() == VB.SyntaxKind.SimpleArgument)
285 | {
286 | return ((VB.Syntax.SimpleArgumentSyntax)node).Expression;
287 | }
288 | return node;
289 | }
290 |
291 | private bool IsConstructor(IMethodSymbol methodSymbol)
292 | {
293 | return methodSymbol.MethodKind == MethodKind.Constructor ||
294 | methodSymbol.MethodKind == MethodKind.StaticConstructor ||
295 | methodSymbol.MethodKind == MethodKind.SharedConstructor;
296 | }
297 |
298 | private IEnumerable GetClassifiedSpans(
299 | Workspace workspace, SemanticModel model,
300 | NormalizedSnapshotSpanCollection spans)
301 | {
302 | var comparer = StringComparer.InvariantCultureIgnoreCase;
303 | var classifiedSpans =
304 | spans.SelectMany(span =>
305 | {
306 | var textSpan = TextSpan.FromBounds(span.Start, span.End);
307 | return Classifier.GetClassifiedSpans(model, textSpan, workspace);
308 | });
309 | return classifiedSpans.Where(span =>
310 | SupportedClassificationTypeNames.Contains(span.ClassificationType, comparer));
311 | }
312 |
313 | private class Cache
314 | {
315 | public Workspace Workspace { get; private set; }
316 | public Document Document { get; private set; }
317 | public SemanticModel SemanticModel { get; private set; }
318 | public SyntaxNode SyntaxRoot { get; private set; }
319 | public ITextSnapshot Snapshot { get; private set; }
320 |
321 | private Cache() { }
322 |
323 | public static async Task Resolve(ITextBuffer buffer, ITextSnapshot snapshot)
324 | {
325 | var workspace = buffer.GetWorkspace();
326 | var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
327 | if (document == null)
328 | {
329 | // Razor cshtml returns a null document for some reason.
330 | return null;
331 | }
332 |
333 | // the ConfigureAwait() calls are important,
334 | // otherwise we'll deadlock VS
335 | var semanticModel = await document.GetSemanticModelAsync().ConfigureAwait(false);
336 | var syntaxRoot = await document.GetSyntaxRootAsync().ConfigureAwait(false);
337 | return new Cache
338 | {
339 | Workspace = workspace,
340 | Document = document,
341 | SemanticModel = semanticModel,
342 | SyntaxRoot = syntaxRoot,
343 | Snapshot = snapshot
344 | };
345 | }
346 | }
347 | }
348 | }
349 |
--------------------------------------------------------------------------------
/SemanticColorizer/SemanticColorizer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 2.0
6 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
7 |
8 |
9 | 4.0
10 |
11 | publish\
12 | true
13 | Disk
14 | false
15 | Foreground
16 | 7
17 | Days
18 | false
19 | false
20 | true
21 | 0
22 | 1.0.0.%2a
23 | false
24 | false
25 | true
26 |
27 |
28 |
29 |
30 | {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
31 | {1EC486EE-EE95-4159-A186-84EDF5B2EC29}
32 | Library
33 | Properties
34 | SemanticColorizer
35 | SemanticColorizer
36 | v4.6
37 | 512
38 | false
39 |
40 |
41 | $(VsSDKInstall)\Microsoft.VsSDK.targets
42 |
43 |
44 |
45 | 11.0
46 |
47 |
48 |
49 | 12.0
50 |
51 |
52 | 14.0
53 |
54 |
55 | 15.0
56 |
57 |
58 | false
59 |
60 |
61 |
62 |
63 |
64 |
65 | True
66 | True
67 |
68 |
69 | True
70 | True
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | Designer
87 |
88 |
89 |
90 |
91 | Always
92 | true
93 |
94 |
95 | Always
96 | true
97 |
98 |
99 | Always
100 | true
101 |
102 |
103 | Always
104 | true
105 |
106 |
107 |
108 |
109 | ..\packages\Microsoft.CodeAnalysis.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.dll
110 |
111 |
112 | ..\packages\Microsoft.CodeAnalysis.CSharp.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll
113 |
114 |
115 | ..\packages\Microsoft.CodeAnalysis.EditorFeatures.Text.1.3.2\lib\net46\Microsoft.CodeAnalysis.EditorFeatures.Text.dll
116 |
117 |
118 | ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll
119 |
120 |
121 | ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll
122 |
123 |
124 | ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll
125 |
126 |
127 | ..\packages\Microsoft.VisualStudio.CoreUtility.14.3.25407\lib\net45\Microsoft.VisualStudio.CoreUtility.dll
128 | True
129 |
130 |
131 | ..\packages\Microsoft.VisualStudio.Text.Data.14.3.25407\lib\net45\Microsoft.VisualStudio.Text.Data.dll
132 | True
133 |
134 |
135 | ..\packages\Microsoft.VisualStudio.Text.Logic.14.3.25407\lib\net45\Microsoft.VisualStudio.Text.Logic.dll
136 | True
137 |
138 |
139 | ..\packages\Microsoft.VisualStudio.Text.UI.14.3.25407\lib\net45\Microsoft.VisualStudio.Text.UI.dll
140 | True
141 |
142 |
143 | ..\packages\Microsoft.VisualStudio.Text.UI.Wpf.14.3.25407\lib\net45\Microsoft.VisualStudio.Text.UI.Wpf.dll
144 | True
145 |
146 |
147 |
148 |
149 | ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll
150 |
151 |
152 | ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
153 |
154 |
155 |
156 | ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll
157 |
158 |
159 | ..\packages\System.Diagnostics.FileVersionInfo.4.3.0\lib\net46\System.Diagnostics.FileVersionInfo.dll
160 |
161 |
162 | ..\packages\System.Diagnostics.StackTrace.4.3.0\lib\net46\System.Diagnostics.StackTrace.dll
163 |
164 |
165 | ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll
166 |
167 |
168 | ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll
169 |
170 |
171 |
172 | ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll
173 |
174 |
175 | ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net46\System.Security.Cryptography.Algorithms.dll
176 |
177 |
178 | ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll
179 |
180 |
181 | ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll
182 |
183 |
184 | ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net46\System.Security.Cryptography.X509Certificates.dll
185 |
186 |
187 | ..\packages\System.Text.Encoding.CodePages.4.3.0\lib\net46\System.Text.Encoding.CodePages.dll
188 |
189 |
190 | ..\packages\System.Threading.Thread.4.3.0\lib\net46\System.Threading.Thread.dll
191 |
192 |
193 | ..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll
194 |
195 |
196 |
197 |
198 |
199 | ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll
200 |
201 |
202 | ..\packages\System.Xml.XmlDocument.4.3.0\lib\net46\System.Xml.XmlDocument.dll
203 |
204 |
205 | ..\packages\System.Xml.XPath.4.3.0\lib\net46\System.Xml.XPath.dll
206 |
207 |
208 | ..\packages\System.Xml.XPath.XDocument.4.3.0\lib\net46\System.Xml.XPath.XDocument.dll
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
224 |
--------------------------------------------------------------------------------
/SemanticColorizer/SemanticColorizerExample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hicknhack-software/semantic-colorizer/af9bc4524af93440b8da76afb350d6d6a7e3fabe/SemanticColorizer/SemanticColorizerExample.png
--------------------------------------------------------------------------------
/SemanticColorizer/VisualBasicExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.VisualBasic;
2 | using Microsoft.CodeAnalysis;
3 |
4 | namespace SemanticColorizer
5 | {
6 | public static class VbExtensions
7 | {
8 | public static SyntaxKind VbKind(this SyntaxNode node) {
9 | return node.Kind();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/SemanticColorizer/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/SemanticColorizer/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/SemanticColorizer/rainbow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hicknhack-software/semantic-colorizer/af9bc4524af93440b8da76afb350d6d6a7e3fabe/SemanticColorizer/rainbow.png
--------------------------------------------------------------------------------
/SemanticColorizer/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Semantic Colorizer
6 | A semantic syntax classifier extension based on Roslyn for C# and Visual Basic.
7 | https://github.com/hicknhack-software/semantic-colorizer
8 | LICENSE.txt
9 | ReleaseNotes.txt
10 | rainbow.png
11 | SemanticColorizerExample.png
12 | Semantic Syntax Highlighting Color
13 |
14 |
15 |
18 |
21 |
22 | x86
23 |
24 |
25 | amd64
26 |
27 |
28 | x86
29 |
30 |
31 | amd64
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/TestFile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Test
4 | {
5 | internal enum Enum
6 | {
7 | Value,
8 | Second = 2
9 | }
10 |
11 | internal struct Data
12 | {
13 | public int field { get; set; }
14 | private readonly string privately;
15 |
16 | public Data(int p)
17 | {
18 | field = p;
19 | privately = "Hello";
20 | }
21 | }
22 |
23 | internal static class ClassExt
24 | {
25 | public static int Sum(this Enum @enum, int num = 5)
26 | {
27 | return num + 2;
28 | }
29 | }
30 | internal interface Base
31 | {
32 | int Run(string arg);
33 | }
34 |
35 | internal class Class1 : Base
36 | {
37 | private Data data;
38 | Enum Runner {
39 | get => Enum.Value;
40 | }
41 |
42 | public Class1() // construct
43 | {
44 | var x = Enum.Value;
45 | x.Sum(3);
46 | }
47 |
48 | public static int NoWay() => 42;
49 |
50 | public int Run(string arg) => throw new NotImplementedException();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Semantic Syntax Colorizer
2 |
3 | [](https://marketplace.visualstudio.com/items?itemName=AndreasReischuck.SemanticColorizer)
4 |
5 | A Visual Studio 2015, 2017, 2019 and 2022 editor extension for semantic syntax highlighting.
6 |
7 | It uses the Roslyn APIs to highlight the following syntax types in distinctive colors to make them easily recognizable.
8 |
9 | To change the colors use the regular Visual Studio "Font and Colors" Options. Look for `Semantic *` in the "Display items".
10 |
11 | * Class fields
12 | * Enum fields
13 | * Static methods
14 | * Regular methods
15 | * Constructors
16 | * Type parameters
17 | * Parameters
18 | * Namespaces
19 | * Class properties
20 | * Local variables
21 | * Special types (built in)
22 |
23 | The code is fairly simple, but it is not currently written using the Async APIs in Roslyn.
24 |
25 | This extension works for the first final version of Visual Studio 2015 and all successors.
26 |
27 | You might want to combine this extension with:
28 | * Viasfora - color access modifiers, control flow
29 | * Build in `User Types - *` Display Items - to change color for regular types `class`, `enum`, `delegate` etc.
30 |
31 | ## License
32 |
33 | Apache License Version 2.0
34 | See LICENSE file for more details
35 |
36 | ## Contribute
37 |
38 | If you like this project give it a star.
39 | If you don't like it or found a bug, please write an issue.
40 |
--------------------------------------------------------------------------------
/root.marker:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hicknhack-software/semantic-colorizer/af9bc4524af93440b8da76afb350d6d6a7e3fabe/root.marker
--------------------------------------------------------------------------------