fix(typescript): don't hardcode values in lua table

When a user changes `vim.opt.shiftwidth` with some auto-command, it's
not taken into account. Make `opts` a function, so that values get
evaluated when `lspconfig` loads instead.
This commit is contained in:
Iordanis Petkakis 2023-12-24 21:17:01 +02:00
parent 879e29504d
commit b9563799be

View file

@ -13,62 +13,59 @@ return {
-- correctly setup lspconfig -- correctly setup lspconfig
{ {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
opts = { opts = function(_, opts)
-- make sure mason installs the server opts.servers.tsserver = {
servers = { keys = {
---@type lspconfig.options.tsserver {
tsserver = { "<leader>co",
keys = { function()
{ vim.lsp.buf.code_action({
"<leader>co", apply = true,
function() context = {
vim.lsp.buf.code_action({ only = { "source.organizeImports.ts" },
apply = true, diagnostics = {},
context = { },
only = { "source.organizeImports.ts" }, })
diagnostics = {}, end,
}, desc = "Organize Imports",
})
end,
desc = "Organize Imports",
},
{
"<leader>cR",
function()
vim.lsp.buf.code_action({
apply = true,
context = {
only = { "source.removeUnused.ts" },
diagnostics = {},
},
})
end,
desc = "Remove Unused Imports",
},
}, },
settings = { {
typescript = { "<leader>cR",
format = { function()
indentSize = vim.o.shiftwidth, vim.lsp.buf.code_action({
convertTabsToSpaces = vim.o.expandtab, apply = true,
tabSize = vim.o.tabstop, context = {
}, only = { "source.removeUnused.ts" },
}, diagnostics = {},
javascript = { },
format = { })
indentSize = vim.o.shiftwidth, end,
convertTabsToSpaces = vim.o.expandtab, desc = "Remove Unused Imports",
tabSize = vim.o.tabstop,
},
},
completions = {
completeFunctionCalls = true,
},
}, },
}, },
}, settings = {
}, typescript = {
format = {
indentSize = vim.o.shiftwidth,
convertTabsToSpaces = vim.o.expandtab,
tabSize = vim.o.tabstop,
},
},
javascript = {
format = {
indentSize = vim.o.shiftwidth,
convertTabsToSpaces = vim.o.expandtab,
tabSize = vim.o.tabstop,
},
},
completions = {
completeFunctionCalls = true,
},
},
}
end,
}, },
{ {
"mfussenegger/nvim-dap", "mfussenegger/nvim-dap",
optional = true, optional = true,