HamidMosalla / VisualStudio-ColorCoder

Visual Studio extension that helps with semantic highlighting in C# and VB.Net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom colors for "this", "null" and "Action"

Hurri04 opened this issue · comments

Would it be possible to add support for the keywords "this" and "null"?
They are currently being controlled by the "Text Editor -> Keyword -> Foreground" setting.
I'd like to be able to set them to different colors from other keywords ("public", "private", "protected", etc., "void", "int", "float", etc.)

Also there's the "Action" keyword, as in e.g. "public event Action OnMyStateChanged;".
While it's possible to set a custom color for delegates, I have not yet found an option (in the default VS settings) to change the color for this keyword.

I'm not sure if all of these are possible but they are certainly good ideas and I'm going to keep them in mind if I wanted to add more features in the future. I also appreciate and accept any help coming from the user of this extension ;)

I've started looking into the code for a bit.
If I understand correctly the key part would be in the ColorCoderTaggerServices.GetTagSpan method which parses ISpan.Kind and ClassificationSpan.ClassificationType values and returns TagSpan, correct?

What I'm not sure about is how this actually gets executed since the ColorCoder.ColorCoderCore.GetTags method only seems to get called from the ColorCoderTaggerTests class?

Because of this I'm also not sure about where the original data which gets parsed comes from. I'd assume the extension somehow gets this from the IDE's compiler (e.g. Roslyn) which then outputs a string (possibly html if that's why Span is used)? If so, is this a temporary string in memory or does it actually get saved to a file somewhere? If possible I'd like to look at its contents to understand the syntax better and to see if there's data in there which could be interpreted to allow for more custom colors.

The GetSpan method seems to use this enum to differentiate the different cases: https://docs.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.symbolkind?view=roslyn-dotnet
I've found this enum with the same name which contains 7 additional values, one of which is "Null": https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.languageserver.protocol.symbolkind?view=visualstudiosdk-2019
But I'm not sure if this can be used.

And finally there are the Preferences which need to be extended to allow setting additional colors but that's probably the easiest part.

Yes you are correct about GetTagSpan. The ColorCoderTagger class inherits from an interface ITagger, that method only fulfills the interface. What's important is that it going to be used by ColorCoderTaggerProvider which in turn is going to be pick up by the framework.

About the enum since ISymbol.Kind expects a type in Microsoft.CodeAnalysis I don't think we can use the second one that you've mentioned.

What's important is that it going to be used by ColorCoderTaggerProvider which in turn is going to be pick up by the framework.

Do you have any links describing this in more detail? I found this MS API page but it isnt very helpful: https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.text.tagging.itaggerprovider?view=visualstudiosdk-2019

Is it being called automatically like e.g. (since that's what I'm familiar with) Unity's Messages: https://docs.unity3d.com/ScriptReference/MonoBehaviour.html ?

I've found this page where at the bottom it says that Debugging should work by simply hitting F5: https://www.c-sharpcorner.com/article/creating-visual-studio-2019-extension/
Unfortunately I'm getting this error because of the way the project is set up:

A project with an Output Type of Class Library cannot be started directly.
In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project.

Do you maybe have a project set up which does this but which you didnt commit to the repository? This would be super helpful for testing!
If not, do you maybe have some references on how to set this up myself? I'm struggling a bit to find the entry point since I have no experience delevoping VS extensions so far.

Once that's set up it should allow using break points to look at the contents of certain variables and see if they contain values which can be used. I've found e.g. this stackoverflow answer where a simple string.Contains is used to check for a comment: https://stackoverflow.com/a/59855557

No I don't have any links, unfortunately the documentation for this kind of things are very hard to find. If you've installed the visual studio extension sdk and selected the primary (not the test) project it should run.