nvim: lsp: Refactor configuration setting for clients

This commit is contained in:
Sanchayan Maity 2022-05-05 21:00:25 +05:30
parent 223ffe7505
commit ef00957fae

View file

@ -199,58 +199,49 @@ local rust_tool_opts = {
},
}
nvim_lsp.clangd.setup {
on_init = on_init,
on_attach = on_attach,
capabilities = capabilities,
default_config = {
cmd = { "clangd", "--background-index", "--pch-storage=memory", "--clang-tidy", "--suggest-missing-includes", "--header-insertion=never" },
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,
}
}
require('rust-tools').setup(rust_tool_opts)
nvim_lsp.hls.setup {
on_init = on_init,
on_attach = on_attach,
capabilities = capabilities
}
nvim_lsp.jedi_language_server.setup {
on_init = on_init,
on_attach = on_attach,
capabilities = capabilities,
init_options = {
completion = {
resolveEagerly = true,
},
jediSettings = {
caseInsensitiveCompletion = false,
},
workspace = {
symbols = {
maxSymbols = 50
local servers = {
clangd = {
default_config = {
cmd = { "clangd", "--background-index", "--pch-storage=memory", "--clang-tidy", "--suggest-missing-includes", "--header-insertion=never" },
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,
}
},
eslint = {},
hls = {},
jedi_language_server = {
init_options = {
completion = {
resolveEagerly = true,
},
jediSettings = {
caseInsensitiveCompletion = false,
},
workspace = {
symbols = {
maxSymbols = 50
},
},
},
},
tsserver = {},
}
require('rust-tools').setup(rust_tool_opts)
nvim_lsp.tsserver.setup {
on_init = on_init,
on_attach = on_attach,
capabilities = capabilities,
}
nvim_lsp.eslint.setup {
on_init = on_init,
on_attach = on_attach,
capabilities = capabilities
}
for client, config in pairs(servers) do
config.on_init = on_init
config.on_attach = on_attach
config.capabilities = vim.tbl_deep_extend(
'keep',
config.capabilities or {},
capabilities
)
nvim_lsp[client].setup(config)
end