jackguo380 / vim-lsp-cxx-highlight

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

highlight not working in alpine container #68

Closed Leo843 closed 3 years ago

Leo843 commented 3 years ago

Describe the bug I setup a container as a portable development environment, but there is no syntax highlight in cpp files.

To Reproduce Here is a simplified version of the Dockerfile.

FROM alpine

# common tools
RUN true \
  && apk update \
  && apk add bash \
  && apk add curl \
  && apk add cmake \
  && apk add git \
  && apk add clang \
  && apk add g++ \
  && apk add clang-extra-tools \
  && rm -rf /var/cache/apk/*

# vim
RUN true \
  && apk update \
  && apk add python3 \
  && apk add nodejs \
  && apk add npm \
  && apk add vim \
  && rm -rf /var/cache/apk/*

# create user
ARG USER_NAME=leo
RUN adduser --disabled-password --gecos '' $USER_NAME

# change user
WORKDIR /home/${USER_NAME}
USER ${USER_NAME}
ENV USER=${USER_NAME} HOME=/home/${USER_NAME}

# vim configuration
RUN true \
  && curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim \
  && echo "set nocompatible" >> .vimrc \
  && echo "call plug#begin()" >> .vimrc \
  && echo "Plug 'neoclide/coc.nvim', {'branch': 'release'}" >> .vimrc \
  && echo "Plug 'jackguo380/vim-lsp-cxx-highlight'" >> .vimrc \
  && echo "call plug#end()" >> .vimrc \
  && echo "let g:lsp_cxx_hl_verbose_log = 1" >> .vimrc \
  && echo "let g:lsp_cxx_hl_log_file = '/tmp/vim-lsp-cxx-hl.log'" >> .vimrc \
  && vim +PlugInstall +qa

# install coc-clangd
RUN true \
  && mkdir -p .config/coc/extensions \
  && cd .config/coc/extensions \
  && echo '{"dependencies":{}}' >> package.json \
  && npm install coc-clangd --global-style --ignore-scripts --no-bin-links --no-package-lock --only=prod \
  && cd ${HOME}

# sample/main.cpp
RUN true \
  && mkdir sample \
  && echo "#include <cstdio>" >> sample/main.cpp \
  && echo "" >> sample/main.cpp \
  && echo "int main(int argc, char** argv){" >> sample/main.cpp \
  && echo "  puts(\"Hello World\");" >> sample/main.cpp \
  && echo "}" >> sample/main.cpp

# sample/.vim/coc-settings.json
RUN true \
  && mkdir sample/.vim \
  && echo "{" >> sample/.vim/coc-settings.json \
  && echo '  "clangd.semanticHighlighting": true' >> sample/.vim/coc-settings.json \
  && echo "}" >> sample/.vim/coc-settings.json

CMD ["/bin/bash"]

When sample/main.cpp is opened with vim in the running container, no highlight appears.

Expected behavior I expect symbols main and puts to be highlighted (function names are highlighted by default).

Screenshots From the container Screenshot from 2021-07-02 14-09-51 From the host (expected behavior) Screenshot from 2021-07-02 14-19-42

Configuration (Fill this out):

 - I am using clangd with coc.nvim and coc-clangd (see Dockerfile)
 - Content of the `.vimrc`  (see Dockerfile)

set nocompatible call plug#begin() Plug 'neoclide/coc.nvim', {'branch': 'release'} Plug 'jackguo380/vim-lsp-cxx-highlight' call plug#end() let g:lsp_cxx_hl_verbose_log = 1 let g:lsp_cxx_hl_log_file = '/tmp/vim-lsp-cxx-hl.log'


**Log File:**
- Here is the output of `:LspCxxHlDumpSyms`.

Debug Dump Symbols End of Debug Dump Symbols

- Here is the content of the log file.

Fri Jul 2 12:02:28 2021: lsp_cxx_hl beginning initialization... Fri Jul 2 12:02:28 2021: vim-lsp not detected Fri Jul 2 12:02:28 2021: LanguageClient-neovim not detected Fri Jul 2 12:02:28 2021: coc.nvim successfully registered Fri Jul 2 12:02:28 2021: Not registering nvim-lsp as this is not Neovim Fri Jul 2 12:05:30 2021: lsp_cxx_hl beginning initialization... Fri Jul 2 12:05:30 2021: vim-lsp not detected Fri Jul 2 12:05:30 2021: LanguageClient-neovim not detected Fri Jul 2 12:05:30 2021: coc.nvim successfully registered Fri Jul 2 12:05:30 2021: Not registering nvim-lsp as this is not Neovim Fri Jul 2 12:05:33 2021: operation hl_skipped (textprop) sample/main.cpp took 0.000117s to complete Fri Jul 2 12:05:33 2021: operation hl_symbols (textprop) sample/main.cpp took 0.000137s to complete



**Additional context**
none atm
unphased commented 3 years ago

I'm experiencing something similar to this but with not nearly as minimal a configuration. It only started happening this week for me, and what's curious is that I hadn't explicitly run PlugUpdate before it broke. Something weird is going on. It's not some change from this repo since it has been unchanged since April.

Currently am scrounging for additional debugging output from the related tools, because

let g:lsp_cxx_hl_log_file = '/tmp/vim-lsp-cxx-hl.log'
let g:lsp_cxx_hl_verbose_log = 1

is not providing any useful output for me. Is that the case for you as well? I see you're getting those operation __ took __s to complete in your log, but I'm not even getting that. (update: I can get that same output if I run :LspCxxHighlight.)

unphased commented 3 years ago

OK as has been noted elsewhere, https://github.com/clangd/coc-clangd/issues/287 contains a temporary fix. This fix is to revert coc.nvim to version 0.0.80 (I just went into plugged/, git fetch --unshallow there and checked this commit out, and I got my highlights back).

It seems like there is some general disarray around coc and clangd interoperation for semantic highlighting features being added. It seems like whatever lsp-cxx-highlight is listening for isn't being delivered by clangd when clangd detects coc supporting the new semantic highlight feature.

Luckily, for the time being, the workaround is to keep coc at the older release version for the time being and the previously working behavior continues. Hopefully soon we will get a better integrated system for this (which will work on all languages rather than using this plugin to get it just for C++).

janwaltl commented 3 years ago

Can confirm, highligting broke after :PlugUpdate for me, navigating to ~/.vim/plugged/coc.nvim and doing git checkout v0.0.80 fixed it for now.

xspeed1989 commented 3 years ago

git checkout v0.0.80

It doesn't works for me

janwaltl commented 3 years ago

git checkout v0.0.80

It doesn't works for me

I do not know what "doesn't work" mean.

xspeed1989 commented 3 years ago

git checkout v0.0.80

It doesn't works for me

I do not know what "doesn't work" mean.

highlight doesn't work after checkout to v0.0.80 too

fannheyward commented 3 years ago

Set coc.preferences.semanticTokensHighlights to false in your coc-settings.json to disable the new semanticTokens highlighting, to use the old semanticHighlighting protocol. You don't need to revert coc to 0.0.80.

The reason: clangd 12 supports both the two highlighting protocol, the new semanticTokens and the old semanticHighlighting. coc-clangd used the old protocol with vim-lsp-cxx-highlight to do highlighting. coc added semanticTokens support in latest, clangd will force use the new protocol, some highlighting group maybe broken. You need to disable the new protocol by coc.preferences.semanticTokensHighlights to use the old one.

Leo843 commented 3 years ago

The highlighting works after setting coc.preferences.semanticTokensHighlights to false in coc-settings.json.

{
  "clangd.semanticHighlighting": true,
  "coc.preferences.semanticTokensHighlights": false
}
unphased commented 3 years ago

Does anyone have an idea when the new approach to semantic highlighting can work for C++? What is the root cause of breakage that is leading us to have to pin our coc.nvim at 0.0.80? Although it is a working setup for now it feels very precarious. vim-lsp-cxx-highlight also has inherent problems where I regularly see comments exhibit residual messed up highlight colors within them, I expect that will be a thing of the past with the new approach.