refactor(nvim): use builtin table merge function

This commit is contained in:
Moritz Böhme 2023-04-09 19:39:17 +02:00
parent 07e1294937
commit e154f827fd
Signed by: moritz
GPG key ID: 970C6E89EB0547A9

View file

@ -69,34 +69,6 @@ vim.api.nvim_create_autocmd("InsertEnter", {
end, end,
}) })
---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 lsp_lines = require("lsp_lines") local lsp_lines = require("lsp_lines")
lsp_lines.setup() lsp_lines.setup()
-- Disable virtual_text since it's redundant due to lsp_lines. -- Disable virtual_text since it's redundant due to lsp_lines.
@ -222,7 +194,7 @@ local lspconfig_default_options = {
---@param options table ---@param options table
---@return nil ---@return nil
local function lspconfig_setup(lsp, options) local function lspconfig_setup(lsp, options)
local final_options = table_merge(lspconfig_default_options, options) local final_options = vim.tbl_deep_extend("force", lspconfig_default_options, options)
lspconfig[lsp].setup(final_options) lspconfig[lsp].setup(final_options)
end end