jackguo380 / vim-lsp-cxx-highlight

Vim plugin for C/C++/ObjC semantic highlighting using cquery, ccls, or clangd
MIT License
337 stars 26 forks source link

Can't get highlighting at all #74

Closed nullromo closed 2 years ago

nullromo commented 2 years ago

Describe the bug The plugin does not seem to receive anything from the language server.

To Reproduce

  1. Add Plug 'jackguo380/vim-lsp-cxx-highlight' to .vimrc (and verify that :echo g:lsp_cxx_hl_loaded prints 1).
  2. Install coc-clangd (I have already been successfully using this for completions and error traversal, so I know the language server is running and working, at least at some level).
  3. Add "clangd.semanticHighlighting": true to coc-settings.json.
  4. Open a C file and see that there is no semantic highlighting.
  5. Run LspCxxHlDumpSyms and get the following:
    Debug Dump Symbols
    End of Debug Dump Symbols
    Press ENTER or type command to continue
  6. Add let g:lsp_cxx_hl_log_file = '/tmp/vim-lsp-cxx-hl.log' and let g:lsp_cxx_hl_verbose_log = 1 to .vimrc and launch vim again to open a C file. The log file contains:
    Thu Oct 14 10:20:59 2021: lsp_cxx_hl beginning initialization...
    Thu Oct 14 10:20:59 2021: vim-lsp not detected
    Thu Oct 14 10:20:59 2021: LanguageClient-neovim not detected
    Thu Oct 14 10:20:59 2021: coc.nvim successfully registered
    Thu Oct 14 10:20:59 2021: Not registering nvim-lsp as this is not Neovim

Expected behavior I expect the highlighting to work.

Configuration (Fill this out):

Log File:

Thu Oct 14 10:20:59 2021: lsp_cxx_hl beginning initialization...
Thu Oct 14 10:20:59 2021: vim-lsp not detected
Thu Oct 14 10:20:59 2021: LanguageClient-neovim not detected
Thu Oct 14 10:20:59 2021: coc.nvim successfully registered
Thu Oct 14 10:20:59 2021: Not registering nvim-lsp as this is not Neovim

Additional context I saw something in the other open issues about clang-format. I do use this clang-format plugin. Not sure if that matters here or not.

jackguo380 commented 2 years ago

Hi @nullromo

if your clangd is the latest (13?), chances are it no longer supports vim-lsp-cxx-highlight. The clangd developers are moving towards semantic tokens which is the officially standardized semantic highlighting protocol.

vim-lsp-cxx-highlight implements the non-standard protocols used by cquery and ccls. clangd support was added via a compatbility shim in the coc-clangd plugin.

I have probably mentioned this on another issue but vim-lsp-cxx-highlight will never support Semantic Tokens. It's simply too difficult as a third-party plugin to implement the standard as it requires many RPC calls back and forth. As it's officially standardized, there's no reason why your LSP client wouldn't implement it in time. Please wait for that to happen or better yet, contribute code towards it.

Or you can downgrade your clangd to a compatible version, I think 11 or 12 might work.

nullromo commented 2 years ago

Thank you for the response. That led me to check out coc.nvim and coc-clangd to see if they have addressed the issue of supporting semantic tokens, and I found out from this thread and this comment that I can add

"coc.preferences.semanticTokensHighlights": false

to my coc config. That makes this plugin work with coc-clangd and now I have beautiful highlighting ゚。・*.゚☆━⊂( ' ᴗ '∩)

jackguo380 commented 2 years ago

Wow great find. I'll update the README with this.

jackguo380 commented 2 years ago

@nullromo do you mind doing a quick check over #78 to see if my README changes reflect what you're using?

nullromo commented 2 years ago

I created a PR with a clarification. See #79.

Walton1128 commented 2 years ago

Thank you for the response. That led me to check out coc.nvim and coc-clangd to see if they have addressed the issue of supporting semantic tokens, and I found out from this thread and this comment that I can add

"coc.preferences.semanticTokensHighlights": false

to my coc config. That makes this plugin work with coc-clangd and now I have beautiful highlighting ゚。・*.゚☆━⊂( ' ᴗ '∩)

I am trying to use clangd for highlighting, but can not get it work.

this is my coc setting: cat ~/.vim/coc-settings.json

{ "clangd.semanticHighlighting": true, "coc.preferences.semanticTokensHighlights": false }

Can you share more info ? Thanks

nullromo commented 2 years ago

The latest version of coc-clangd supports semantic tokens now. To enable it, you need to disable vim-lsp-cxx-highlight and add

"semanticTokens.filetypes": ["c", "cpp"]

to your coc-settings.json. You can also use "*" to enable it for all files.

See this comment.

ssh352 commented 2 years ago

Hi @nullromo

if your clangd is the latest (13?), chances are it no longer supports vim-lsp-cxx-highlight. The clangd developers are moving towards semantic tokens which is the officially standardized semantic highlighting protocol.

vim-lsp-cxx-highlight implements the non-standard protocols used by cquery and ccls. clangd support was added via a compatbility shim in the coc-clangd plugin.

I have probably mentioned this on another issue but vim-lsp-cxx-highlight will never support Semantic Tokens. It's simply too difficult as a third-party plugin to implement the standard as it requires many RPC calls back and forth. As it's officially standardized, there's no reason why your LSP client wouldn't implement it in time. Please wait for that to happen or better yet, contribute code towards it.

Or you can downgrade your clangd to a compatible version, I think 11 or 12 might work.

tried clang 13 doesn't work this this plugin.