I have a massive C project that is build by cmake, I generate the compile_commands.json
and all the includes are there, but for example in main.c it cannot find libxml/parser.h
.
In the compile_commands.json
main.c
is compiled with
arm-none-eabi-gcc [...] -I[path/to/project]/sdk/include [...] -o CMakeFiles/standard_project.dir/main.c.obj -c C:/Users/gianl/Desktop/ite_sdk/project/standard_project/main.c
(I will not include the [...] because it has way to many options)
libxml/parser.h
is in [path/to/project]/sdk/include
yet still clangd can't find it.
I'm using clangd version Ubuntu clangd version 12.0.0-3ubuntu1~20.04.5
in Neovim v0.7.2
This is my init.vim for clangd (note that I'm using clangd-12)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap=true, silent=true, buffer=bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', '<alt>L', vim.lsp.buf.formatting, bufopts)
end
local lsp_flags = {
-- This is the default in Nvim 0.7+
debounce_text_changes = 150,
}
require('lspconfig')['pyright'].setup{
on_attach = on_attach,
flags = lsp_flags,
}
require('lspconfig')['tsserver'].setup{
on_attach = on_attach,
flags = lsp_flags,
}
require('lspconfig')['rust_analyzer'].setup{
on_attach = on_attach,
flags = lsp_flags,
-- Server-specific settings...
settings = {
["rust-analyzer"] = {}
}
}
require('lspconfig').clangd.setup{
on_attach = on_attach,
flags = lsp_flags,
cmd = {"clangd-12"}
}
I've had the same problem with ccls
it might be because the project is so big (1000 compile commands each with 5700 chars in length)
EDIT
Clangd log (not verbose if any one know how to enable it I will post the output)
[START][2022-08-12 06:28:15] LSP logging initiated
[ERROR][2022-08-12 06:28:18] .../vim/lsp/rpc.lua:420 "rpc" "clangd-12" "stderr" "I[06:28:18.108] Ubuntu clangd version 12.0.0-3ubuntu1~20.04.5\nI[06:28:18.108] PID: 185\n"
[ERROR][2022-08-12 06:28:18] .../vim/lsp/rpc.lua:420 "rpc" "clangd-12" "stderr" "I[06:28:18.109] Working directory: /mnt/c/Users/gianl/Desktop/ite_sdk\nI[06:28:18.109] argv[0]: clangd-12\n"
[ERROR][2022-08-12 06:28:18] .../vim/lsp/rpc.lua:420 "rpc" "clangd-12" "stderr" "I[06:28:18.109] Starting LSP over stdin/stdout\n"
[ERROR][2022-08-12 06:28:18] .../vim/lsp/rpc.lua:420 "rpc" "clangd-12" "stderr" "I[06:28:18.109] <-- initialize(1)\n"
[ERROR][2022-08-12 06:28:18] .../vim/lsp/rpc.lua:420 "rpc" "clangd-12" "stderr" "I[06:28:18.134] --> reply:initialize(1) 24 ms\n"
[ERROR][2022-08-12 06:28:33] .../vim/lsp/rpc.lua:420 "rpc" "clangd-12" "stderr" "I[06:28:33.828] <-- initialized\n"
[ERROR][2022-08-12 06:28:33] .../vim/lsp/rpc.lua:420 "rpc" "clangd-12" "stderr" "I[06:28:33.828] <-- textDocument/didOpen\n"
[ERROR][2022-08-12 06:28:33] .../vim/lsp/rpc.lua:420 "rpc" "clangd-12" "stderr" "I[06:28:33.857] Loaded compilation database from /mnt/c/Users/gianl/Desktop/ite_sdk/compile_commands.json\n"
[ERROR][2022-08-12 06:28:33] .../vim/lsp/rpc.lua:420 "rpc" "clangd-12" "stderr" "I[06:28:33.857] ASTWorker building file /mnt/c/Users/gianl/Desktop/ite_sdk/project/standard_project/main.c version 0 with command clangd fallback\n[/mnt/c/Users/gianl/Desktop/ite_sdk/project/standard_project]\n/usr/bin/clang /mnt/c/Users/gianl/Desktop/ite_sdk/project/standard_project/main.c -fsyntax-only -resource-dir=/usr/lib/llvm-12/lib/clang/12.0.0\n"
[ERROR][2022-08-12 06:28:33] .../vim/lsp/rpc.lua:420 "rpc" "clangd-12" "stderr" "I[06:28:33.997] --> textDocument/publishDiagnostics\n"
I've just found this error in an older log:
[ERROR][2022-08-12 06:25:57] .../vim/lsp/rpc.lua:420 "rpc" "clangd-12" "stderr" "V[06:25:57.138] Dex query tree: (LIMIT 10000 (& T=lex T=exi T=pio T=tpi T=itp T=xit T=oct T=ctl T=tle T=ioc S= ?=Restricted For Code Completion))\n"