diff --git a/lua/lazyvim/plugins/extras/lang/typescript.lua b/lua/lazyvim/plugins/extras/lang/typescript.lua index 414f11da..95014677 100644 --- a/lua/lazyvim/plugins/extras/lang/typescript.lua +++ b/lua/lazyvim/plugins/extras/lang/typescript.lua @@ -1,14 +1,3 @@ -local inlay_hints_settings = { - includeInlayEnumMemberValueHints = true, - includeInlayFunctionLikeReturnTypeHints = true, - includeInlayFunctionParameterTypeHints = true, - includeInlayParameterNameHints = "literals", - includeInlayParameterNameHintsWhenArgumentMatchesName = false, - includeInlayPropertyDeclarationTypeHints = true, - includeInlayVariableTypeHints = false, - includeInlayVariableTypeHintsWhenTypeMatchesName = false, -} - return { recommended = function() return LazyVim.extras.wants({ @@ -24,13 +13,12 @@ return { }) end, - -- add typescript to treesitter { - "nvim-treesitter/nvim-treesitter", - opts = function(_, opts) - if type(opts.ensure_installed) == "table" then - vim.list_extend(opts.ensure_installed, { "typescript", "tsx" }) - end + "yioneko/nvim-vtsls", + lazy = true, + opts = {}, + config = function(_, opts) + require("vtsls").config(opts) end, }, @@ -40,52 +28,85 @@ return { opts = { -- make sure mason installs the server servers = { - ---@type lspconfig.options.tsserver tsserver = { + enabled = false, + }, + vtsls = { + settings = { + complete_function_calls = true, + typescript = { + updateImportsOnFileMove = { enabled = "always" }, + enableMoveToFileCodeAction = true, + experimental = { + completion = { + enableServerSideFuzzyMatch = true, + }, + }, + suggest = { + completeFunctionCalls = true, + }, + inlayHints = { + enumMemberValues = { enabled = true }, + functionLikeReturnTypes = { enabled = true }, + parameterNames = { enabled = "literals" }, + parameterTypes = { enabled = true }, + propertyDeclarationTypes = { enabled = true }, + variableTypes = { enabled = false }, + }, + }, + }, keys = { + { + "gD", + function() + require("vtsls").commands.goto_source_definition(0) + end, + desc = "Goto Source Definition", + }, { "co", function() - vim.lsp.buf.code_action({ - apply = true, - context = { - only = { "source.organizeImports.ts" }, - diagnostics = {}, - }, - }) + require("vtsls").commands.organize_imports(0) end, desc = "Organize Imports", }, { - "cR", + "cM", function() - vim.lsp.buf.code_action({ - apply = true, - context = { - only = { "source.removeUnused.ts" }, - diagnostics = {}, - }, - }) + require("vtsls").commands.add_missing_imports(0) end, - desc = "Remove Unused Imports", + desc = "Add missing imports", }, - }, - settings = { - typescript = { - inlayHints = inlay_hints_settings, - }, - javascript = { - inlayHints = inlay_hints_settings, - }, - completions = { - completeFunctionCalls = true, + { + "cD", + function() + require("vtsls").commands.fix_all(0) + end, + desc = "Fix all diagnostics", }, }, }, }, + setup = { + tsserver = function() + -- disable tsserver + return true + end, + }, }, }, + { + "neovim/nvim-lspconfig", + opts = function(_, opts) + -- copy typescript settings to javascript + opts.servers.vtsls.settings.javascript = vim.deepcopy(opts.servers.vtsls.settings.typescript) + + -- add vtsls to lspconfig + require("lspconfig.configs").vtsls = require("vtsls").lspconfig + end, + }, + { "mfussenegger/nvim-dap", optional = true, diff --git a/lua/lazyvim/plugins/extras/lang/vue.lua b/lua/lazyvim/plugins/extras/lang/vue.lua index 2ce87c03..36bac9a2 100644 --- a/lua/lazyvim/plugins/extras/lang/vue.lua +++ b/lua/lazyvim/plugins/extras/lang/vue.lua @@ -26,14 +26,18 @@ return { volar = {}, -- Volar 2.0 has discontinued their "take over mode" which in previous version provided support for typescript in vue files. -- The new approach to get typescript support involves using the typescript language server along side volar. - tsserver = { - init_options = { - plugins = { - -- Use typescript language server along with vue typescript plugin - { - name = "@vue/typescript-plugin", - location = vue_typescript_plugin, - languages = { "javascript", "typescript", "vue" }, + vtsls = { + settings = { + vtsls = { + tsserver = { + globalPlugins = { + -- Use typescript language server along with vue typescript plugin + { + name = "@vue/typescript-plugin", + location = vue_typescript_plugin, + languages = { "vue" }, + }, + }, }, }, }, diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index 105e7108..a2e5286a 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -225,11 +225,13 @@ return { for server, server_opts in pairs(servers) do if server_opts then server_opts = server_opts == true and {} or server_opts - -- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig - if server_opts.mason == false or not vim.tbl_contains(all_mslp_servers, server) then - setup(server) - elseif server_opts.enabled ~= false then - ensure_installed[#ensure_installed + 1] = server + if server_opts.enabled ~= false then + -- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig + if server_opts.mason == false or not vim.tbl_contains(all_mslp_servers, server) then + setup(server) + else + ensure_installed[#ensure_installed + 1] = server + end end end end