Closed ofrades closed 4 years ago
That's pretty tricky to do in standard vim syntax highlighting, because it's all done using regular expressions.
So you can try adding lots of regular expression rules describing places where types are used but variables are not, but I'm not sure it's possible to do this perfectly, and the more advanced rules that are added to the syntax highlighting, the slower the highlighting becomes.
To get true, semantic highlighting, the only option is to get the semantic structure from a language server, and layer the semantic highlighting on top of (or instead of) normal highlighting. OmniSharp-vim, for example, (which uses the same language server that vscode uses for C# semantic highlighting and other language services) uses text properties (Vim) or namespaces (neovim) to apply highlights to specific locations, not regular expressions, and in this way can easily differentiate between types and variables. The OmniSharp-vim version allows you to set the highlight group for every semantic "kind", see here
Other LSP plugins have started advertising semantic highlighting like this, but I haven't seen one that works for C# yet. And YCM has also just announced they are trialling similar feature.
Thanks for the information @nickspoons Do you think this project - https://github.com/nvim-treesitter/nvim-treesitter and the related repo https://github.com/tree-sitter/tree-sitter-c-sharp - will try to resolve some of this questions?
I think treesitter is basically a different way of doing the same thing. My (limited, quite possibly flawed) understanding of treesitter is that it builds a semantic picture of the file and uses that to highlight it. Which is the same thing you get from a language server, but treesitter is faster/lighter because it doesn't need to know about the context (project/solution) and can work on a single file on it's own.
So if you're using a language server anyway, for navigation, usages, documentation, formatting etc., then it makes sense to me to let the language server perform the semantic highlighting. If you're not using a language server then it might make more sense to let treesitter do that work. I have never tried it, it may be fast and light enough that it can run happily beside a language server? No idea sorry.
Not sure if this is the right place to ask. I was trying to port theme https://github.com/Geri-Borbas/VSCode.Extension.eppz_Code to vim.
But one major difficulty I am facing is the
Identifier
that, I think, overrule a bunch of stuff.e.g.
How can I have
List
with a different color from the typeList<T>
?public Info Info
where the type is different from the variable?