refactor: refactored mason/typescript/vue support

This commit is contained in:
Folke Lemaitre 2024-06-01 08:31:10 +02:00
parent 135150307b
commit 9d999fa210
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
6 changed files with 70 additions and 37 deletions

View file

@ -106,8 +106,7 @@ return {
{ "<leader>dPc", function() require('dap-python').test_class() end, desc = "Debug Class", ft = "python" }, { "<leader>dPc", function() require('dap-python').test_class() end, desc = "Debug Class", ft = "python" },
}, },
config = function() config = function()
local path = require("mason-registry").get_package("debugpy"):get_install_path() require("dap-python").setup(LazyVim.get_pkg_path("debugpy", "/venv/bin/python"))
require("dap-python").setup(path .. "/venv/bin/python")
end, end,
}, },
}, },

View file

@ -32,10 +32,21 @@ return {
enabled = false, enabled = false,
}, },
vtsls = { vtsls = {
-- explicitly add default filetypes, so that we can extend
-- them in related extras
filetypes = {
"javascript",
"javascriptreact",
"javascript.jsx",
"typescript",
"typescriptreact",
"typescript.tsx",
},
settings = { settings = {
complete_function_calls = true, complete_function_calls = true,
vtsls = { vtsls = {
enableMoveToFileCodeAction = true, enableMoveToFileCodeAction = true,
autoUseWorkspaceTsdk = true,
experimental = { experimental = {
completion = { completion = {
enableServerSideFuzzyMatch = true, enableServerSideFuzzyMatch = true,
@ -147,8 +158,7 @@ return {
command = "node", command = "node",
-- 💀 Make sure to update this path to point to your installation -- 💀 Make sure to update this path to point to your installation
args = { args = {
require("mason-registry").get_package("js-debug-adapter"):get_install_path() LazyVim.get_pkg_path("js-debug-adapter", "/js-debug/src/dapDebugServer.js"),
.. "/js-debug/src/dapDebugServer.js",
"${port}", "${port}",
}, },
}, },

View file

@ -6,6 +6,9 @@ return {
}) })
end, end,
-- depends on the typescript extra
{ import = "lazyvim.plugins.extras.lang.typescript" },
{ {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
opts = function(_, opts) opts = function(_, opts)
@ -15,34 +18,30 @@ return {
end, end,
}, },
-- Add LSP servers
{
"neovim/nvim-lspconfig",
opts = {
servers = {
volar = {},
vtsls = {},
},
},
},
-- Configure tsserver plugin
{ {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
opts = function(_, opts) opts = function(_, opts)
local vue_typescript_plugin = require("mason-registry").get_package("vue-language-server"):get_install_path() table.insert(opts.servers.vtsls.filetypes, "vue")
.. "/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",
},
},
})
LazyVim.extend(opts.servers.vtsls, "settings.vtsls.tsserver.globalPlugins", { LazyVim.extend(opts.servers.vtsls, "settings.vtsls.tsserver.globalPlugins", {
name = "@vue/typescript-plugin", {
location = vue_typescript_plugin, name = "@vue/typescript-plugin",
languages = { "vue" }, location = LazyVim.get_pkg_path("vue-language-server", "/node_modules/@vue/language-server"),
configNamespace = "typescript", languages = { "vue" },
configNamespace = "typescript",
enableForWorkspaceTypeScriptVersions = true,
},
}) })
end, end,
}, },

View file

@ -284,19 +284,15 @@ return {
}) })
end, 100) end, 100)
end) end)
local function ensure_installed()
mr.refresh(function()
for _, tool in ipairs(opts.ensure_installed) do for _, tool in ipairs(opts.ensure_installed) do
local p = mr.get_package(tool) local p = mr.get_package(tool)
if not p:is_installed() then if not p:is_installed() then
p:install() p:install()
end end
end end
end end)
if mr.refresh then
mr.refresh(ensure_installed)
else
ensure_installed()
end
end, end,
}, },
} }

View file

@ -5,6 +5,7 @@ local prios = {
["lazyvim.plugins.extras.editor.aerial"] = 100, ["lazyvim.plugins.extras.editor.aerial"] = 100,
["lazyvim.plugins.extras.editor.outline"] = 100, ["lazyvim.plugins.extras.editor.outline"] = 100,
["lazyvim.plugins.extras.editor.trouble-v3"] = 100, ["lazyvim.plugins.extras.editor.trouble-v3"] = 100,
["lazyvim.plugins.extras.lang.typescript"] = 5,
["lazyvim.plugins.extras.ui.edgy"] = 2, ["lazyvim.plugins.extras.ui.edgy"] = 2,
["lazyvim.plugins.extras.test.core"] = 1, ["lazyvim.plugins.extras.test.core"] = 1,
["lazyvim.plugins.extras.dap.core"] = 1, ["lazyvim.plugins.extras.dap.core"] = 1,

View file

@ -72,7 +72,12 @@ function M.on_very_lazy(fn)
}) })
end 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 }) local keys = vim.split(key, ".", { plain = true })
for i = 1, #keys do for i = 1, #keys do
local k = keys[i] local k = keys[i]
@ -82,7 +87,7 @@ function M.extend(t, key, value)
end end
t = t[k] t = t[k]
end end
t[#t + 1] = value return vim.list_extend(t, values)
end end
---@param name string ---@param name string
@ -211,4 +216,27 @@ function M.create_undo()
end end
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 return M