diff --git a/lua/lazyvim/plugins/extras/lang/python.lua b/lua/lazyvim/plugins/extras/lang/python.lua index ac59a543..7a716b3e 100644 --- a/lua/lazyvim/plugins/extras/lang/python.lua +++ b/lua/lazyvim/plugins/extras/lang/python.lua @@ -106,8 +106,7 @@ return { { "dPc", function() require('dap-python').test_class() end, desc = "Debug Class", ft = "python" }, }, config = function() - local path = require("mason-registry").get_package("debugpy"):get_install_path() - require("dap-python").setup(path .. "/venv/bin/python") + require("dap-python").setup(LazyVim.get_pkg_path("debugpy", "/venv/bin/python")) end, }, }, diff --git a/lua/lazyvim/plugins/extras/lang/typescript.lua b/lua/lazyvim/plugins/extras/lang/typescript.lua index e4fbd8f0..482af408 100644 --- a/lua/lazyvim/plugins/extras/lang/typescript.lua +++ b/lua/lazyvim/plugins/extras/lang/typescript.lua @@ -32,10 +32,21 @@ return { enabled = false, }, vtsls = { + -- explicitly add default filetypes, so that we can extend + -- them in related extras + filetypes = { + "javascript", + "javascriptreact", + "javascript.jsx", + "typescript", + "typescriptreact", + "typescript.tsx", + }, settings = { complete_function_calls = true, vtsls = { enableMoveToFileCodeAction = true, + autoUseWorkspaceTsdk = true, experimental = { completion = { enableServerSideFuzzyMatch = true, @@ -147,8 +158,7 @@ return { command = "node", -- 💀 Make sure to update this path to point to your installation args = { - require("mason-registry").get_package("js-debug-adapter"):get_install_path() - .. "/js-debug/src/dapDebugServer.js", + LazyVim.get_pkg_path("js-debug-adapter", "/js-debug/src/dapDebugServer.js"), "${port}", }, }, diff --git a/lua/lazyvim/plugins/extras/lang/vue.lua b/lua/lazyvim/plugins/extras/lang/vue.lua index f3bd0926..6c47d56e 100644 --- a/lua/lazyvim/plugins/extras/lang/vue.lua +++ b/lua/lazyvim/plugins/extras/lang/vue.lua @@ -6,6 +6,9 @@ return { }) end, + -- depends on the typescript extra + { import = "lazyvim.plugins.extras.lang.typescript" }, + { "nvim-treesitter/nvim-treesitter", opts = function(_, opts) @@ -15,34 +18,30 @@ return { end, }, + -- Add LSP servers + { + "neovim/nvim-lspconfig", + opts = { + servers = { + volar = {}, + vtsls = {}, + }, + }, + }, + + -- Configure tsserver plugin { "neovim/nvim-lspconfig", opts = function(_, opts) - local vue_typescript_plugin = require("mason-registry").get_package("vue-language-server"):get_install_path() - .. "/node_modules/@vue/language-server" - .. "/node_modules/@vue/typescript-plugin" - - opts.servers = vim.tbl_deep_extend("force", opts.servers, { - 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. - vtsls = { - filetypes = { - "javascript", - "javascriptreact", - "javascript.jsx", - "typescript", - "typescriptreact", - "typescript.tsx", - "vue", - }, - }, - }) + table.insert(opts.servers.vtsls.filetypes, "vue") LazyVim.extend(opts.servers.vtsls, "settings.vtsls.tsserver.globalPlugins", { - name = "@vue/typescript-plugin", - location = vue_typescript_plugin, - languages = { "vue" }, - configNamespace = "typescript", + { + name = "@vue/typescript-plugin", + location = LazyVim.get_pkg_path("vue-language-server", "/node_modules/@vue/language-server"), + languages = { "vue" }, + configNamespace = "typescript", + enableForWorkspaceTypeScriptVersions = true, + }, }) end, }, diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index 414bb655..ac84b743 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -284,19 +284,15 @@ return { }) end, 100) end) - local function ensure_installed() + + mr.refresh(function() for _, tool in ipairs(opts.ensure_installed) do local p = mr.get_package(tool) if not p:is_installed() then p:install() end end - end - if mr.refresh then - mr.refresh(ensure_installed) - else - ensure_installed() - end + end) end, }, } diff --git a/lua/lazyvim/plugins/xtras.lua b/lua/lazyvim/plugins/xtras.lua index 6c789b0f..87b11fb7 100644 --- a/lua/lazyvim/plugins/xtras.lua +++ b/lua/lazyvim/plugins/xtras.lua @@ -5,6 +5,7 @@ local prios = { ["lazyvim.plugins.extras.editor.aerial"] = 100, ["lazyvim.plugins.extras.editor.outline"] = 100, ["lazyvim.plugins.extras.editor.trouble-v3"] = 100, + ["lazyvim.plugins.extras.lang.typescript"] = 5, ["lazyvim.plugins.extras.ui.edgy"] = 2, ["lazyvim.plugins.extras.test.core"] = 1, ["lazyvim.plugins.extras.dap.core"] = 1, diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 1c677622..9b2135f5 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -72,7 +72,12 @@ function M.on_very_lazy(fn) }) end -function M.extend(t, key, value) +---@generic T +---@param t T[] +---@param key string +---@param values T[] +---@return T[]? +function M.extend(t, key, values) local keys = vim.split(key, ".", { plain = true }) for i = 1, #keys do local k = keys[i] @@ -82,7 +87,7 @@ function M.extend(t, key, value) end t = t[k] end - t[#t + 1] = value + return vim.list_extend(t, values) end ---@param name string @@ -211,4 +216,27 @@ function M.create_undo() end end +--- Gets a path to a package in the Mason registry. +--- Prefer this to `get_package`, since the package might not always be +--- available yet and trigger errors. +---@param pkg string +---@param path? string +function M.get_pkg_path(pkg, path) + path = path or "" + local ret = vim.env.MASON .. "/packages/" .. pkg .. "/" .. path + if not vim.loop.fs_stat(ret) then + M.warn(("Mason package path not found for **%s**:\n- `%s`"):format(pkg, path)) + end + return ret +end + +--- Override the default title for notifications. +for _, level in ipairs({ "info", "warn", "error" }) do + M[level] = function(msg, opts) + opts = opts or {} + opts.title = opts.title or "LazyVim" + return LazyUtil[level](msg, opts) + end +end + return M