nvim: rework lspconfig

nixos
Moritz Böhme 2023-02-17 22:09:13 +01:00
parent c59527e2f2
commit aa8d7c6901
Signed by: moritz
GPG Key ID: 970C6E89EB0547A9
2 changed files with 185 additions and 152 deletions

View File

@ -33,7 +33,10 @@ in
plugins = with pkgs.vimPlugins; [ plugins = with pkgs.vimPlugins; [
catppuccin-nvim catppuccin-nvim
cmp-nvim-lsp cmp-nvim-lsp
cmp_luasnip
dashboard-nvim dashboard-nvim
lsp_lines-nvim
luasnip
neogit neogit
noice-nvim noice-nvim
nui-nvim # for noice-nvim nui-nvim # for noice-nvim
@ -44,9 +47,6 @@ in
plenary-nvim # for telescope, neogit plenary-nvim # for telescope, neogit
telescope-nvim telescope-nvim
which-key-nvim which-key-nvim
cmp_luasnip
luasnip
lsp_lines-nvim
]; ];
}; };
}; };

View File

@ -162,18 +162,57 @@ local on_attach_def = function(_, bufnr)
}, { noremap = true, silent = true, buffer = bufnr }) }, { noremap = true, silent = true, buffer = bufnr })
end end
local servers = { "nil_ls", "pylsp" } ---merge tables
for _, lsp in ipairs(servers) do ---@param ... table[]
lspconfig[lsp].setup({ ---@return table
local function table_merge(...)
local tables_to_merge = { ... }
assert(#tables_to_merge > 1, "There should be at least two tables to merge them")
for k, t in ipairs(tables_to_merge) do
assert(type(t) == "table", string.format("Expected a table as function parameter %d", k))
end
local result = tables_to_merge[1]
for i = 2, #tables_to_merge do
local from = tables_to_merge[i]
for k, v in pairs(from) do
if type(v) == "table" then
result[k] = result[k] or {}
result[k] = table_merge(result[k], v)
else
result[k] = v
end
end
end
return result
end
local lspconfig_default_options = {
on_attach = on_attach_def, on_attach = on_attach_def,
capabilities = capabilities, capabilities = capabilities,
flags = { flags = {
debounce_text_changes = 100, debounce_text_changes = 100,
}, },
}) }
---function to add default options to lspconfig
---@param lsp string
---@param options table
---@return nil
local function lspconfig_setup(lsp, options)
local final_options = table_merge(lspconfig_default_options, options)
lspconfig[lsp].setup(final_options)
end end
lspconfig.sumneko_lua.setup({ local servers = { "nil_ls", "pylsp" }
for _, lsp in ipairs(servers) do
lspconfig_setup(lsp, {})
end
lspconfig_setup("lua_ls", {
on_attach = on_attach_def, on_attach = on_attach_def,
capabilities = capabilities, capabilities = capabilities,
settings = { settings = {
@ -196,13 +235,7 @@ lspconfig.sumneko_lua.setup({
enable = false, enable = false,
}, },
format = { format = {
enable = true, enable = false,
-- Put format options here
-- NOTE: the value should be STRING!!
defaultConfig = {
indent_style = "space",
indent_size = "2",
},
}, },
}, },
}, },