nvim: lsp: Enable clangd for C and C++

This commit is contained in:
Sanchayan Maity 2021-09-10 13:56:25 +05:30
parent ccb4b4343d
commit 5b6685b165

View file

@ -3,6 +3,7 @@ local protocol = require('vim.lsp.protocol')
local signature = require('lsp_signature')
local ts_utils = require("nvim-lsp-ts-utils")
local null_ls = require("null-ls")
local util = require("lspconfig/util")
-- Taken from https://www.reddit.com/r/neovim/comments/gyb077/nvimlsp_peek_defination_javascript_ttserver/
function preview_location(location, context, before_context)
@ -199,6 +200,21 @@ for _, lsp in ipairs(servers) do
}
end
nvim_lsp.clangd.setup {
on_attach = on_attach,
default_config = {
cmd = { "clangd", "--background-index", "--pch-storage=memory", "--clang-tidy", "--suggest-missing-includes" },
filetypes = { 'c', 'cpp' },
root_dir = function(fname)
-- We specify build/compile_commands.json as that is where the compile_commands.json
-- gets generated automatically for meson projects.
local root_pattern = util.root_pattern('build/compile_commands.json', 'compile_commands.json', 'compile_flags.txt', '.git')
local filename = util.path.is_absolute(fname) and fname or util.path.join(vim.loop.cwd(), fname)
return root_pattern(filename) or util.path.dirname(filename)
end,
}
}
-- See https://github.com/sumneko/lua-language-server/wiki/Setting-without-VSCode#neovim-with-built-in-lsp-client
-- on why we do this library thing
-- Idea taken from https://gist.github.com/folke/fe5d28423ea5380929c3f7ce674c41d8