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" },
},
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,
},
},

View file

@ -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}",
},
},

View file

@ -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,
location = LazyVim.get_pkg_path("vue-language-server", "/node_modules/@vue/language-server"),
languages = { "vue" },
configNamespace = "typescript",
enableForWorkspaceTypeScriptVersions = true,
},
})
end,
},

View file

@ -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,
},
}

View file

@ -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,

View file

@ -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