omnisharp-roslyn: Semantic tokens do not conform to the LSP specification
Semantic highlighting was recently merged into Neovim. Unfortunately the token types provided by Omnisharp don’t conform to the LSP semantic tokens specification so Neovim cannot support it (neovim/neovim#21391).
To demonstrate the issue, here’s a comparison of Lua Language Server’s tokens to Omnisharp’s tokens. Omnisharp’s tokens are fundamentally wrong as well as having illegal formatting.
Lua Language Server (correct tokens)
{
full = true,
legend = {
tokenModifiers = {
"declaration",
"definition",
"readonly",
"static",
"deprecated",
"abstract",
"async",
"modification",
"documentation",
"defaultLibrary",
"global",
},
tokenTypes = {
"namespace",
"type",
"class",
"enum",
"interface",
"struct",
"typeParameter",
"parameter",
"variable",
"property",
"enumMember",
"event",
"function",
"method",
"macro",
"keyword",
"modifier",
"comment",
"string",
"number",
"regexp",
"operator",
"decorator",
},
},
range = true,
}
Omnisharp-roslyn (incorrect Tokens)
{
full = vim.empty_dict(),
legend = {
tokenModifiers = { "static symbol" },
tokenTypes = {
"comment",
"excluded code",
"identifier",
"keyword",
"keyword - control",
"number",
"operator",
"operator - overloaded",
"preprocessor keyword",
"string",
"whitespace",
"text",
"static symbol",
"preprocessor text",
"punctuation",
"string - verbatim",
"string - escape character",
"class name",
"delegate name",
"enum name",
"interface name",
"module name",
"struct name",
"type parameter name",
"field name",
"enum member name",
"constant name",
"local name",
"parameter name",
"method name",
"extension method name",
"property name",
"event name",
"namespace name",
"label name",
"xml doc comment - attribute name",
"xml doc comment - attribute quotes",
"xml doc comment - attribute value",
"xml doc comment - cdata section",
"xml doc comment - comment",
"xml doc comment - delimiter",
"xml doc comment - entity reference",
"xml doc comment - name",
"xml doc comment - processing instruction",
"xml doc comment - text",
"xml literal - attribute name",
"xml literal - attribute quotes",
"xml literal - attribute value",
"xml literal - cdata section",
"xml literal - comment",
"xml literal - delimiter",
"xml literal - embedded expression",
"xml literal - entity reference",
"xml literal - name",
"xml literal - processing instruction",
"xml literal - text",
"regex - comment",
"regex - character class",
"regex - anchor",
"regex - quantifier",
"regex - grouping",
"regex - alternation",
"regex - text",
"regex - self escaped character",
"regex - other escape",
},
},
range = true,
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 61
- Comments: 33 (1 by maintainers)
Commits related to this issue
- Switching to csharp_ls from omnisharp due to https://github.com/OmniSharp/omnisharp-roslyn/issues/2483 — committed to gwendolyngoetz/dotfiles by gwendolyngoetz a year ago
- lsp: workaround for OmniSharp/omnisharp-roslyn#2483 Signed-off-by: Serowy, Alexander (EXT/ADMIN) <Alexander.Serowy.ADMIN@union-investment.de> — committed to aserowy/neocode by deleted user a year ago
- add omnisharp lsp for csharp development (including a nasty hack for fixing the broken semantic tokens, see: https://github.com/OmniSharp/omnisharp-roslyn/issues/2483) — committed to deforde/dotfiles by deforde a year ago
- Revert "replace omnisharp-roslyn with csharp-ls" This reverts commit a97e296861e223f28cd30c692ae7a456c1cf33b0. omnisharp-roslyn issue seems resolved, see: https://github.com/OmniSharp/omnisharp-rosly... — committed to gautaz/phoenix by gautaz a year ago
- Revert "replace omnisharp-roslyn with csharp-ls" This reverts commit a97e296861e223f28cd30c692ae7a456c1cf33b0. omnisharp-roslyn issue seems resolved, see: https://github.com/OmniSharp/omnisharp-rosly... — committed to gautaz/phoenix by gautaz a year ago
- Revert "replace omnisharp-roslyn with csharp-ls" This reverts commit a97e296861e223f28cd30c692ae7a456c1cf33b0. omnisharp-roslyn issue seems resolved, see: https://github.com/OmniSharp/omnisharp-rosly... — committed to gautaz/phoenix by gautaz a year ago
Sure! In my LSP handler
on_attachI added the following:Basically just replacing the invalid tokens with valid ones. Not very future proof if that list changes, obviously.
You are in fact wrong, omnisharp doesn’t conform to Microsoft’s own LSP spec, how ironic 😆
Switched to csharp-language-server after this whole mess, no complaints on my end so far
We can make it a little bit more future proof:
Attempted to fix it in #2520 but my C# isn’t great 😉
Ok I merged 2 workarounds* (@ateoi & @daephx ) and it seems to be working well:
Released in 1.39.8: https://github.com/OmniSharp/omnisharp-roslyn/releases/tag/v1.39.8
when I see the stars of Omnisharp git repository, it may be so remarkable. Now I changed my opinion.
Works well, don’t forget to place this code to load after lsp.
@natanncosta The on_attach function can be defined anywhere in your
init.lua. It just needs to be passed tolspconfig["omnisharp"].setup({on_attach = on_attach}).You could get similar results using the
LspAttachautocmd.The fix didn’t work for me so I just turned off semantic tokens for the time being.
@sid-6581 do you have to set up custom highlighting for new tokens? I was not sure and just remapped everything to a standard ones.
If it can be solved with what is discussed above, I think it is a problem with the neovim/nvim-lspconfig plugin, not omnisharp. Am I wrong?
As a follow-up to @ateoi’s workaround, here is what I use to override my “global”
on_attachfunction with one for OmniSharp that fixes the tokens:Hm, this workaround doesn’t seem to work anymore. Maybe something changed or was added. Could you explain how you made this workaround list? I don’t see any of those tokens in the official doc.
No, I had that too but I don’t write much C# code so it wasn’t a huge issue for me. Ideally omnisharp-roslyn would fix this issue and conform to proper semantic token naming.