nvim: rework lspconfig
This commit is contained in:
parent
c59527e2f2
commit
aa8d7c6901
2 changed files with 185 additions and 152 deletions
|
@ -33,7 +33,10 @@ in
|
|||
plugins = with pkgs.vimPlugins; [
|
||||
catppuccin-nvim
|
||||
cmp-nvim-lsp
|
||||
cmp_luasnip
|
||||
dashboard-nvim
|
||||
lsp_lines-nvim
|
||||
luasnip
|
||||
neogit
|
||||
noice-nvim
|
||||
nui-nvim # for noice-nvim
|
||||
|
@ -44,9 +47,6 @@ in
|
|||
plenary-nvim # for telescope, neogit
|
||||
telescope-nvim
|
||||
which-key-nvim
|
||||
cmp_luasnip
|
||||
luasnip
|
||||
lsp_lines-nvim
|
||||
];
|
||||
};
|
||||
};
|
||||
|
|
|
@ -162,18 +162,57 @@ local on_attach_def = function(_, bufnr)
|
|||
}, { noremap = true, silent = true, buffer = bufnr })
|
||||
end
|
||||
|
||||
local servers = { "nil_ls", "pylsp" }
|
||||
for _, lsp in ipairs(servers) do
|
||||
lspconfig[lsp].setup({
|
||||
---merge tables
|
||||
---@param ... table[]
|
||||
---@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,
|
||||
capabilities = capabilities,
|
||||
flags = {
|
||||
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
|
||||
|
||||
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,
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
|
@ -196,13 +235,7 @@ lspconfig.sumneko_lua.setup({
|
|||
enable = false,
|
||||
},
|
||||
format = {
|
||||
enable = true,
|
||||
-- Put format options here
|
||||
-- NOTE: the value should be STRING!!
|
||||
defaultConfig = {
|
||||
indent_style = "space",
|
||||
indent_size = "2",
|
||||
},
|
||||
enable = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue