Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in header file with using clangd #495

Closed
arwtyxouymz opened this issue Jul 3, 2018 · 2 comments
Closed

Error in header file with using clangd #495

arwtyxouymz opened this issue Jul 3, 2018 · 2 comments

Comments

@arwtyxouymz
Copy link

arwtyxouymz commented Jul 3, 2018

Summary

Hi all!
Firstly i apologize my poor English and please laugh at me!

I use this plugin to develop my c++ app.
I develop it with the libraries, vtk and integrate with cmake and I use this plugin with clangd for c/c++ language server.

I have the serious problem...
When i include the library header file, in my header file it becomes error while in my source file success to include.
It's strange isn't it?

I show you my strange problem pictures.
The left file is my header file, and the right one is my source file.
2018-07-03 17 03 35

In addition, in header file, libraries functions aren't be complemented while in source file they are complemented.
In header file,
2018-07-03 17 06 36

In source file,
2018-07-03 17 06 48

My LanguageClient-neovim configuration is here:

[[plugins]]
repo = 'autozimu/LanguageClient-neovim'
build = ['./install.sh']
hook_add = '''
    let g:LanguageClient_serverCommands = {
        \ 'c': ['clangd', '-compile-commands-dir=' . getcwd() . '/build'],
        \ 'cpp': ['clangd', '-compile-commands-dir=' . getcwd() . '/build'],
    \ }
    let g:LanguageClient_hoverPreview = "Never"
    " not stop completion $ & /
    set hidden
    set signcolumn=yes
    nnoremap <F5> :call LanguageClient_contextMenu()<CR>
    " Or map each action separately
    nnoremap <silent> K :call LanguageClient#textDocument_hover()<CR>
    nnoremap <silent> gd :call LanguageClient#textDocument_definition()<CR>
    nnoremap <silent> <F2> :call LanguageClient#textDocument_rename()<CR>
'''

Is this problem a Language-Client bug or is my configuration wrong?
I think CMake's settings(CMakeLists.txt) is not wrong because in source file correctly completion work.

Please help me!

Reproduction

  • neovim/vim version (nvim --version or vim --version): nvim v0.3.0
  • This plugin version (git rev-parse --short HEAD): 6c94b3e
  • This plugin's binary version (bin/languageclient --version):0.1.93 6c94b3e
  • Minimal vimrc content (A minimal vimrc is the smallest vimrc that could
    reproduce the issue. Refer to an example [[here][min-init.vim]):]: My Minimal init.vim
  • Language server link and version:
  • Steps to reproduce the issue from clean state
    1. download vtk and build + install it.
    2. clone this repository and mkdir -p build && cd build && cmake ..
    3. in project root, nvim src/UI/Window.hpp

Current Behavior

In header file, error has occurred and libraries function completion doesn't work.

Expected Behavior

In header file, error doesn't occur like source file above, and completion work.

@MartenBE
Copy link

MartenBE commented Jul 5, 2018

I think this has to do with the fact that cmake only exports information for cpp files, not for headers, into compile_commands.json when using the CMAKE_EXPORT_COMPILE_COMMANDS=ON flag. This is a known issue and I am not sure if they will/can solve it (soon); I remember they discussed it on the mailing list of clangd, but I can't find it anymore.
I solved this by using compdb (https://github.com/Sarcasm/compdb), which appends the necessary information to the compile_commands.json for the header files.

An example of the files I use to set up projects can be found here (disclaimer: I'm not sure if it is best practice as I am not exactly an expert on CMake): https://github.com/MartenBE/gevorderde-algoritmen/tree/master/generic-project-files:

  1. Put the files CMakeLists.txt, CMakeLists.txt.in and generate_makefile.sh in your project root (.clang-format is only necessary for formatting)
  2. Add your cpp and header files in the SOURCES or TEST_SOURCES sets in CMakeLists.txt (ADDITIONAL_INPUT_FILES and ADDITIONAL_TEST_FILES only need to contains files you want to copy to the build directory when generating the makefiles, e.g. csv or json files or cetera)
  3. Run generate_makefile.sh to start CMake and let it generate the makefiles

More examples can be found in the repo. CMakeLists.txt.in is only necessary to download and link GoogleTest when you specify source files in TEST_SOURCES, and does not need any changes

@arwtyxouymz
Copy link
Author

@MartenBE

Thanks! It worked!
I really hope cmake solve this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants