1
Fork 0

nvim: Add support for clangd for C++ and ccls for C

clangd doesn't work the way I want it to with C.
ccls doesn't work the way I want it to with C++.

So now I use both for each ones they work well with.
This commit is contained in:
caem 2024-12-11 14:39:07 +01:00
parent b5d3970e71
commit 9a59dfb308
Signed by: caem
GPG key ID: 69A830D03203405F
4 changed files with 51 additions and 2 deletions

View file

@ -1,5 +1,8 @@
return function () return function ()
require"lspconfig".clangd.setup { require"lspconfig".ccls.setup {
capabilities = require"cmp_nvim_lsp".default_capabilities() capabilities = require"cmp_nvim_lsp".default_capabilities(),
filetypes = {
"c"
}
} }
end end

View file

@ -0,0 +1,8 @@
return function ()
require"lspconfig".clangd.setup {
capabilities = require"cmp_nvim_lsp".default_capabilities(),
filetypes = {
"cpp", "objc", "objcpp", "cuda", "proto"
}
}
end

View file

@ -0,0 +1,37 @@
vim.api.nvim_create_autocmd("BufReadPost", {
pattern = "*.h",
callback = function()
-- Toggle .h files between being interpreted as C and C++
-- in case I have to work on a C++ header that was saved
-- (incorrectly) as a C header file.
vim.api.nvim_create_user_command("Fytwmmrt", function()
if not vim.b.fu then
vim.b.fu = true
vim.bo.filetype = "cpp"
vim.cmd([[
LspStop ccls
LspStart clangd
]])
else
vim.b.fu = false
vim.bo.filetype = "c"
vim.cmd([[
LspStop ccls
LspStart clangd
]])
end
end, { desc = "Fuck you to whoever made me run this."})
-- Set all .h files to be interpreted as C by default instead
-- of C++. If you use .h for your C++ headers instead of .hpp
-- you should be ashamed of yourself and change and grow as a
-- person as to not repeat such heretical offenses.
if not vim.b.fu then
vim.bo.filetype = "c"
vim.cmd([[
LspStop clangd
LspStart ccls
]])
end
end,
})

View file

@ -21,6 +21,7 @@
(llvmPackages_19.clang-tools.override { (llvmPackages_19.clang-tools.override {
enableLibcxx = true; enableLibcxx = true;
}) })
ccls
ripgrep ripgrep
nil nil
gcc14 gcc14