nvim: lsp: Enable clangd for C and C++
This commit is contained in:
parent
ccb4b4343d
commit
5b6685b165
1 changed files with 16 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue