coc-clangd
coc-clangd copied to clipboard
Include errors
Recently i've been migrating to work with cli text-editors for fun, but i got problems into using it. the problem is including libraries from linux modules api.
Result from CocInfo
versions:
node version: v18.7.0
coc.nvim version: 0.0.82-5fce9a51 2022-08-17 07:04:08 +0800
coc.nvim directory: /home/kalix/.local/share/nvim/site/pack/coc/start/coc.nvim
term: xterm-256color
platform: linux
Log of coc.nvim:
2022-08-18T19:21:12.579 INFO (pid:98204) [services] - registered service "clangd"
2022-08-18T19:21:12.580 INFO (pid:98204) [services] - clangd state change: stopped => starting
2022-08-18T19:21:12.585 INFO (pid:98204) [language-client-index] - Language server "clangd" started with 98216
2022-08-18T19:21:12.616 INFO (pid:98204) [services] - clangd state change: starting => running
2022-08-18T19:21:12.625 INFO (pid:98204) [services] - service clangd started
2022-08-18T19:24:24.350 INFO (pid:98204) [attach] - receive notification: showInfo []
Describe the bug
I added all include paths into both compile_flags.txt & compile_commands.json
compile_flags.txt:
-I/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.1/include -I/usr/lib/modules/5.18.16-arch1-1/build/arch/x86/include -I/usr/lib/modules/5.18.16-arch1-1/build/arch/x86/include/generated -I/usr/lib/modules/5.18.16-arch1-1/build/include -I/usr/lib/modules/5.18.16-arch1-1/build/arch/x86/include/uapi -I/usr/lib/modules/5.18.16-arch1-1/build/arch/x86/include/generated/uapi -I/usr/lib/modules/5.18.16-arch1-1/build/include/uapi -I/usr/lib/modules/5.18.16-arch1-1/build/include/generated/uapi
compile_commands.json:
[
{
"directory": "/home/kalix/rickroll-driver",
"command": "clang -std=c11 -I/home/kalix/rickroll-driver -I/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.1/include -I/usr/lib/modules/5.18.16-arch1-1/build/arch/x86/include -I/usr/lib/modules/5.18.16-arch1-1/build/arch/x86/include/generated -I/usr/lib/modules/5.18.16-arch1-1/build/include -I/usr/lib/modules/5.18.16-arch1-1/build/arch/x86/include/uapi -I/usr/lib/modules/5.18.16-arch1-1/build/arch/x86/include/generated/uapi -I/usr/lib/modules/5.18.16-arch1-1/build/include/uapi -I/usr/lib/modules/5.18.16-arch1-1/build/include/generated/uapi -I/usr/lib/modules/5.18.16-arch1-1/build/include/linux",
"file": "/home/kalix/rickroll-driver/rickroll.c"
}
]
i checked all of the directories, and they were okay, i can switch into, i can list the files inside, and it works on vscode already.
Reproduce the bug
.wimrc:
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
Screenshots:
inside init.h:
compiler.h:
compiler_types.h (no errors):
and whenever i try to include them inside the header itself (readonly) (just by testing to see if the completion works or not):
it just doesn't find it, while the init.h and compiler.h and compiler_types.h, together are exactly in the same directory.
last words: the code compiles, and works with no problems (CMake), it also can be edited by vscode with no errors, the code style is in C11 standard.
Where is your compile_commands.json
located? It should be in your project's root, or use clangd.compilationDatabasePath
to specifies the directory containing the compilation database.
Where is your
compile_commands.json
located? It should be in your project's root, or useclangd.compilationDatabasePath
to specifies the directory containing the compilation database.
it is in root path, yes i did, it has problem reading these two header files init.h and module.h, other ones are okay, the completion also works (for example netfilter header enums, etc), but it spits errors whenever i include init.h & module.h, if i delete compile_commands.json, they all would be red.
these two header files init.h and module.h, other ones are okay
it's clangd's issue, cc @sam-mccall
it's clangd's issue, cc
wait i think i found the issue, it says "C99", while i need C11 standard, i tried adding it to compile_commands.json
as i mentioned, but it doesn't work, it still thinks its C99, any solution?
Add it to clangd.arguments
and try again.
Add it to
clangd.arguments
and try again.
i tried this, but it doesn't even start at all
Try clangd.fallbackFlags
, https://github.com/clangd/coc-clangd/issues/20#issuecomment-670946925
Try
clangd.fallbackFlags
, #20 (comment)
i tried adding "clangd.fallbackFlags": [ "-std=c11" ]
to coc-settings.json
but still got back to the first place
i wonder does this even support changing c standard to c11 at all or just idk?
Looks like newer versions of clangd drop supporting -std option
You need to set -std
in compile_commands.json, https://github.com/clangd/coc-clangd/issues/516
To clarify clangd's behavior here:
-std is a clang flag (not a clangd flag) and can be set in any of the usual places, {compile_commands.json, compiler_flags.txt} (only ONE of these will be used), .clangd (can add flags), fallback flags (ONLY if there's no compile_commands or compile_flags)
https://clangd.llvm.org/design/compile-commands
If you're editing a header file, it's likely compile_commands.json didn't have flags for it. (Most build systems don't compile headers separately). Clangd will try to guess based on a similarly-named file that does have flags. Details are in the logs.
If you want to see which C version is being used, type __STDC_VERSION__
and hover over it. Checking to see whether there are any diagnostics is not a reliable method, as you could have several problems.