From b9563799bedf55d740730d817d2c0242afd7a577 Mon Sep 17 00:00:00 2001 From: Iordanis Petkakis Date: Sun, 24 Dec 2023 21:17:01 +0200 Subject: [PATCH] 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. --- .../plugins/extras/lang/typescript.lua | 101 +++++++++--------- 1 file changed, 49 insertions(+), 52 deletions(-) diff --git a/lua/lazyvim/plugins/extras/lang/typescript.lua b/lua/lazyvim/plugins/extras/lang/typescript.lua index 4f53ae8c..fdb1859d 100644 --- a/lua/lazyvim/plugins/extras/lang/typescript.lua +++ b/lua/lazyvim/plugins/extras/lang/typescript.lua @@ -13,62 +13,59 @@ return { -- correctly setup lspconfig { "neovim/nvim-lspconfig", - opts = { - -- make sure mason installs the server - servers = { - ---@type lspconfig.options.tsserver - tsserver = { - keys = { - { - "co", - function() - vim.lsp.buf.code_action({ - apply = true, - context = { - only = { "source.organizeImports.ts" }, - diagnostics = {}, - }, - }) - end, - desc = "Organize Imports", - }, - { - "cR", - function() - vim.lsp.buf.code_action({ - apply = true, - context = { - only = { "source.removeUnused.ts" }, - diagnostics = {}, - }, - }) - end, - desc = "Remove Unused Imports", - }, + opts = function(_, opts) + opts.servers.tsserver = { + keys = { + { + "co", + function() + vim.lsp.buf.code_action({ + apply = true, + context = { + only = { "source.organizeImports.ts" }, + diagnostics = {}, + }, + }) + end, + desc = "Organize Imports", }, - 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, - }, + { + "cR", + function() + vim.lsp.buf.code_action({ + apply = true, + context = { + only = { "source.removeUnused.ts" }, + diagnostics = {}, + }, + }) + end, + desc = "Remove Unused Imports", }, }, - }, - }, + 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", optional = true,