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

Inserting or removing lines messes up highlighting #39

Closed Leo843 closed 4 years ago

Leo843 commented 4 years ago

Describe the bug When editing a file, as lines get inserted and removed, some lines are displayed with the colors of adjacent lines. Saving the file :w or refreshing the buffer :e do not correct the colors. I have to restart the language server :CocRestart to get back the right colors.

To Reproduce

1) Setup a working directory with the 2 following files:

${working-dir}/main.cpp

#include <cstdio>

int main(int argc, char **argv) {
  puts("Hello World");
  return 0;
}

${working-dir}/.vim/coc-settings.json

{
  "clangd.semanticHighlighting": true
}

2) Open main.cpp with vim

1

3) Insert a new line before the main function

2

4) Remove a line before the main function

3

The return keyword get the color of the puts function.

Expected behavior All lines keep the correct syntax highlight even while editing the file.

Configuration: vim: 8.2.1543 clangd: 9.0.0 coc: latest release vim-lsp-cxx-highlight: master

The following flag is set in my vimrc:

let g:lsp_cxx_hl_use_text_props = 1
jackguo380 commented 4 years ago

Hi, could you please provide a screenshot as well as some sample code + instructions to reproduce (e.g. delete line 5 then add text to line 8).

I thought this was already fixed on the coc-clangd side.

Leo843 commented 4 years ago

I have edited the post with instructions to reproduce the error.

jackguo380 commented 4 years ago

Great thanks. I do see the issue when using clangd 9, however I was not able to reproduce it with clangd 10. I'm not too willing to look further into this since it seems like there's some behavior from clangd 9 thats not handled by coc-clangd or vim-lsp-cxx-highlight which was fixed in clangd 10. I'm a little worried it could break clangd 10 or later if I add a workaround, newer versions take priority.

Could you try upgrading your clangd to version 10 and see if the problem is fixed?

I don't know what platform you are on but usually https://releases.llvm.org/download.html has binaries for most of them. If you are running debian based linux they have an apt repository as well at https://apt.llvm.org/.

Leo843 commented 4 years ago

The problem no longer appears with clang 10.

Thx!