OmniSharp / omnisharp-vim

Vim omnicompletion (intellisense) and more for C#
http://www.omnisharp.net
MIT License
1.72k stars 168 forks source link

Incosistency with used highlight groups / How to change colors #677

Closed RononDex closed 3 years ago

RononDex commented 3 years ago

So I found issues with the way omnisharp-vim marks the text in different "highlight" classes:

For example, the highlight class on the usings is not set: image

Whereas the "async" keyword for example is being set as csAsync and Keyword: image

And variable names are set as "lv14" ?? image

Although I tried to set the lv14, lv15 etc (it seems kinda random which one gets used, it seems to even change between files) and was unable to do so. It seems the "hi" commands such like

hi lv14 ctermfg=190 guifg=#d7ff00

gets ignored.

Funny thing is, when I open a .cs file for the first time in vim, it first shows the correctly defined colors. However, as soon as omnisharp server started the colors change back to default.

I used this command to get the highlight class below the cursor:

map <F1> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
RononDex commented 3 years ago

With :OmniSharpHighlightEcho I just keep getting "Identifier" pretty much everywhere. Meaning the highlighting groups that Omnisharp overlays are actually less detailed than the default ones

Is there any way to get more specific highlighting groups?

nickspoons commented 3 years ago

The semantic OmniSharp-vim highlighting uses text properties (Vim) and namespaces (neovim) to add server-provided highlighting on top of the standard vim syntax highlighting. So that's what you're seeing when you load vim: for the first few seconds, the server is not yet available as it spins up, and there is just the vim syntax highlighting available. Once the server is available, OmniSharp-vim provides semantic highlighting on top, and that is what :OmniSharpHighlightEcho is displaying.

If you want to turn off the semantic highlighting and just keep syntax highlighting, add this to your .vimrc:

let g:OmniSharp_highlighting = 0

If you are using semantic highlighting, you can fine-tune which groups are highlighted with which colours, this is described in the README: https://github.com/OmniSharp/omnisharp-vim#semantic-highlighting

I don't know what those lv14 and lv15 highlight groups are, I suspect they are coming from another plugin.

With :OmniSharpHighlightEcho I just keep getting "Identifier" pretty much everywhere. Meaning the highlighting groups that Omnisharp overlays are actually less detailed than the default ones

Is there any way to get more specific highlighting groups?

No, we just have what the server provides (the same groups that vscode has access to).

RononDex commented 3 years ago

Ah tanks, that's useful. So basically Omnisharp can create a dictionary of Roslyn tags to highlighting groups :+1:

nickspoons commented 3 years ago

Yep, that's it

RononDex commented 3 years ago

I found the predefined default mapping here: https://github.com/OmniSharp/omnisharp-vim/blob/master/autoload/OmniSharp/actions/highlight.vim

Would it be okay for me to create a PR with some "better" default mappings? Like "EnumName", "ClassName" , ... mapped to "Type" by default instead of "Identifier"?

nickspoons commented 3 years ago

That sounds pretty subjective...

Perhaps if you do it, include the words "Feedback wanted" and we can leave it open for a while, and see anyone else has strong feelings on the issue?

RononDex commented 3 years ago

That sounds pretty subjective...

Yeah I agree.

Perhaps if you do it, include the words "Feedback wanted" and we can leave it open for a while, and see anyone else has strong feelings on the issue?

I can see if I can put something together in the next few days

nickspoons commented 3 years ago

Actually after trying some things out I agree. I'm just playing with these currently, and different colours for NamespaceName/ClassName do help with code readability:

let g:OmniSharp_highlight_groups = {
\ 'ExcludedCode': 'NonText',
\ 'ClassName': 'Type',
\ 'EnumName': 'Type',
\ 'NamespaceName': 'Include',
\ 'RegexComment': 'Comment',
\ 'RegexCharacterClass': 'Character',
\ 'RegexAnchor': 'Type',
\ 'RegexQuantifier': 'Number',
\ 'RegexGrouping': 'Macro',
\ 'RegexAlternation': 'Identifier',
\ 'RegexText': 'String',
\ 'RegexSelfEscapedCharacter': 'Delimiter',
\ 'RegexOtherEscape': 'Delimiter'
\}

Edit: Added Regex groups

Where there others you had been considering?

RononDex commented 3 years ago

The ones I came up with so far are

let g:OmniSharp_highlight_groups = {
\ 'Comment': 'Comment',
\ 'Keyword': 'Keyword',
\ 'StringLiteral': 'String',
\ 'ClassName': 'StorageClass',
\ 'DelegateName': 'StorageClass',
\ 'EnumName': 'StorageClass',
\ 'InterfaceName': 'StorageClass',
\ 'ModuleName': 'StorageClass',
\ 'StructName': 'StorageClass',
\ 'ConstantName': 'Constant',
\ 'NamespaceName': 'Include',
\ 'ExcludedCode': 'NonText'
\}
nickspoons commented 3 years ago

I disagree with several of these.

Have you found any problems with the standard highlighting for the above?

Then you have most of the remaining groups highlighted as StorageClass, meaning there is no differentiation between classes/enums/interfaces, which I find much more useful.

After reading over :help group-name I think we should highlight classes and structs as Typedef and delegates/enums/interfaces/modules as Structure:

let g:OmniSharp_highlight_groups = {
\ 'ExcludedCode': 'NonText',
\ 'ClassName': 'Typedef',
\ 'StructName': 'Typedef',
\ 'DelegateName': 'Structure',
\ 'EnumName': 'Structure',
\ 'InterfaceName': 'Structure',
\ 'ModuleName': 'Structure',
\ 'NamespaceName': 'Include',
\ 'RegexComment': 'Comment',
\ 'RegexCharacterClass': 'Character',
\ 'RegexAnchor': 'Type',
\ 'RegexQuantifier': 'Number',
\ 'RegexGrouping': 'Macro',
\ 'RegexAlternation': 'Identifier',
\ 'RegexText': 'String',
\ 'RegexSelfEscapedCharacter': 'Delimiter',
\ 'RegexOtherEscape': 'Delimiter'
\}
RononDex commented 3 years ago

I agree with pretty much everything you said, its just what I found to work well with my colorscheme :)

edujtm commented 3 years ago

Is there any way to turn off highlighting only for specific groups? What I want is to turn off highlighting for the Identifier group, but I couldn't figure out how to do this from the documentation. Essentially, I want to have them in the white color instead of blue from the color scheme.

I've tried doing this but it didn't work:

highlight Identifier guibg=Black guifg=White

I'm not the most experienced with vim configuration, so I don't know exactly what I'm doing.

nickspoons commented 3 years ago

If you want to stop OmniSharp-vim from highlighting any particular semantic types, set them to 0 like this:

let g:OmniSharp_highlight_groups = {
\ 'Comment': 'NonText',
\ 'XmlDocCommentName': 'Identifier',
\ 'XmlDocCommentText': 'NonText',
\ 'LocalName': 0,
\ 'PropertyName': 0
\}

To actually change a vim highlight group as you're describing, you are actually overriding part of your colorscheme, so make sure you do it after setting the colorscheme in your .vimrc:

highlight link Identifier Normal
" or
highlight Identifier ctermfg=white guifg=white ctermbg=black guibg=black

There's a bit more info about highlighting configuration in our wiki article: https://github.com/OmniSharp/omnisharp-vim/wiki/Highlighting-configuration