sublimelsp / LSP-OmniSharp

Convenience plugin to install/update OmniSharp for LSP
MIT License
20 stars 9 forks source link

semantic highlighting, coloring unused code differently #25

Open ssoher opened 1 year ago

ssoher commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Does it work in VSCode?

And also you might want to try to disable this seemingly relevant option: https://github.com/sublimelsp/LSP-OmniSharp/blob/73285c66290afbf2d35b5532fa04ea88cc81c556/LSP-OmniSharp.sublime-settings#L21-L23

ssoher commented 1 year ago

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 commented 1 year ago

Should be checked with latest Omnisharp version also. Related I guess: https://github.com/sublimelsp/LSP-OmniSharp/issues/24

ssoher commented 1 year ago

@rchl yes, already did. couldn't get it to work.

24 is resolved by the latest omnisharp though.

rchl commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.