Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

semantic highlighting, coloring unused code differently #25

Open
ssoher opened this issue Nov 20, 2022 · 12 comments
Open

semantic highlighting, coloring unused code differently #25

ssoher opened this issue Nov 20, 2022 · 12 comments

Comments

@ssoher
Copy link

ssoher commented Nov 20, 2022

Consider the following code, I want to "dim" or use custom coloring on the unreachable or unused code. Couldn't find a way to achieve this with semantic highlighting, the LSP documentation doesn't provide a semantic token specifically for this it seems, or I did not notice it. Is this possible and supported and if so what is the correct way to add this to a custom color scheme?

#if false
// Some code that does not get compiled because it's wrapped within #if false
#endif
@rchl
Copy link
Member

rchl commented Nov 20, 2022

This is typically handled through diagnostics with "unnecessary" tag. Does server report relevant diagnostic for that part of the code? If it does then https://lsp.sublimetext.io/customization/#diagnostics has information how to modify color scheme to support that.

@ssoher
Copy link
Author

ssoher commented Nov 20, 2022

They are neither reported as diagnostics nor the coloring works on the tags markup.unnecessary.lsp and markup.deprecated.lsp. It'd be cool if this feature is added, compilation directives are used quite commonly, especially for cross platform work. Would help having the non-compiled code "greyed out".

@rchl
Copy link
Member

rchl commented Nov 20, 2022

If not supported right now then it would need to be added in https://github.com/OmniSharp/omnisharp-roslyn. This is just a think wrapper package that makes it easy to use it in Sublime.

@rchl
Copy link
Member

rchl commented Nov 20, 2022

nor the coloring works on the tags markup.unnecessary.lsp and markup.deprecated.lsp

I'm not sure what exactly doesn't work. If server doesn't provide diagnostics with those tags then it will obviously not work. Otherwise it obviously should work if your color scheme is extended accordingly.

@ssoher
Copy link
Author

ssoher commented Nov 20, 2022

nor the coloring works on the tags markup.unnecessary.lsp and markup.deprecated.lsp

I'm not sure what exactly doesn't work. If server doesn't provide diagnostics with those tags then it will obviously not work. Otherwise it obviously should work if your color scheme is extended accordingly.

Adding the little snippet I've mentioned in my first comment does not produce a diagnostic.

@rchl
Copy link
Member

rchl commented Nov 20, 2022

Does it work in VSCode?

And also you might want to try to disable this seemingly relevant option:

// Suppress 'hidden' diagnostics (such as 'unnecessary using directives') from appearing in
// the editor or the Problems pane.
"csharp.suppressHiddenDiagnostics": true,

@ssoher
Copy link
Author

ssoher commented Nov 20, 2022

It does work in VSCode.

Changing "csharp.suppressHiddenDiagnostics": true to false did not change the result. Still no diagnostics produced for false resulting compiler directive blocks.

@rchl
Copy link
Member

rchl commented Nov 23, 2022

Should be checked with latest Omnisharp version also.
Related I guess: #24

@ssoher
Copy link
Author

ssoher commented Nov 23, 2022

@rchl yes, already did. couldn't get it to work.
#24 is resolved by the latest omnisharp though.

@rchl
Copy link
Member

rchl commented Nov 23, 2022

Then it would need to be investigated how VSCode extension does it. Whether through LSP server, syntax file or maybe even some custom code in the extension.

@rchl
Copy link
Member

rchl commented Dec 30, 2022

I'm not smart enough to get this whole server to run on my mac so I'm not gonna look into it but if you want to debug a bit then you could post here the response to the textDocument/codeAction request while in a file that should report unnecessary code (and where VSCode does report it).

@rchl
Copy link
Member

rchl commented Dec 30, 2022

But after brief look it seems like the server reports code actions with Unnecessary tag for unused imports, for example, but there is also some custom code in the VSCode extension that triggers a custom codeCheck request to the server and maps certain results to diagnostics with Unnecessary tags.

This silly server has so much custom logic in the extension that it almost defeats the purpose of having an LSP server... It would be a full time job to get this mapped to our package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants