dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.88k stars 676 forks source link

Incorrect semantic tokens for various cases #5516

Closed dmrowiec-pl closed 1 week ago

dmrowiec-pl commented 1 year ago

Environment data

.NET SDK (reflecting any global.json): Version: 6.0.400 Commit: 7771abd614

OS Name: linuxmint OS Version: 19.1 OS Platform: Linux RID: linuxmint.19.1-x64 Base Path: /usr/share/dotnet/sdk/6.0.400/

VS Code version: 1.70.1 C# Extension version: 1.25.0

Expected behavior

  1. Semantic token for values like "true" and "false" indicate it's a boolean type
  2. Semantic token for phrases like "int", "string", "bool" etc. indicate they are built in types or dedicated storage type keywords
  3. In simple using statement like: using System.Collections.Generic; semantic token for "System" indicate it's a namespace

Actual behavior

  1. Semantic token for boolean values indicate it's a keyword, which is actually not a real keyword
  2. Semantic token for phrases like "int", "string", "bool" etc. indicate they are keywords like any other language keyword
  3. In simple using statement like: using System.Collections.Generic; semantic token for "System" indicate it's a variable

Additional context

Current behavior of semantic tokens is very much limited and works incorrectly by not distinguish between built in types, boolean values and actual keywords. There are many other examples of inconsistencies like the ones mentioned above.

filipw commented 1 year ago

Did you enable "csharp.semanticHighlighting.enabled": true? by default only the static text mate grammar is enabled

dmrowiec-pl commented 1 year ago

Yes of course, otherwise I guess I none semantic tokens would be returned, just textmate. The issue addresses actual semantic tokens that are returned.

filipw commented 1 year ago

The semantic tokens are supplied by the Roslyn compiler, OmniSharp only surfaces them. It mostly matches what is defined by the LSP spec. You can see all the possibilities there. They are then mapped to VS Code display options here.

In case of true, false, int, bool and so on, those are keyword literals in C# so I would say they are intentionally classified as keywords.

However if you see a problem with the System.Collections.Generic, could you provide repro steps because it seems to work fine for me:

Bildschirm­foto 2023-01-07 um 19 25 31
dmrowiec-pl commented 1 year ago

The thing is, the point of semantic highlighting is to be more accurate and to improve the classification, since language server should have better understanding of the underlying symbols. However, in this case the bare textmate scopes are much more accurate and it seems the semantic classification is rather poor, making it less rich.

JoeRobich commented 1 week ago

This is a feature request for Roslyn who handles the semantic tagging. If you are still running into problems, you can open an issue at https://github.com/dotnet/roslyn/issues