From 683aaeb75b46f182f2a2dca3b8416151de296626 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 1 Jun 2024 08:33:24 +0200 Subject: [PATCH] feat(astro): added support for ts-plugin, but won't work till mason-registry PR is merged. See #3364 --- lua/lazyvim/plugins/extras/lang/astro.lua | 22 ++++++++++++++++++++++ lua/lazyvim/util/init.lua | 7 +++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/plugins/extras/lang/astro.lua b/lua/lazyvim/plugins/extras/lang/astro.lua index 67af3e4d..c4192e27 100644 --- a/lua/lazyvim/plugins/extras/lang/astro.lua +++ b/lua/lazyvim/plugins/extras/lang/astro.lua @@ -10,6 +10,9 @@ return { }) end, + -- depends on the typescript extra + { import = "lazyvim.plugins.extras.lang.typescript" }, + { "nvim-treesitter/nvim-treesitter", opts = function(_, opts) @@ -19,6 +22,7 @@ return { end, }, + -- LSP Servers { "neovim/nvim-lspconfig", opts = { @@ -27,4 +31,22 @@ return { }, }, }, + + -- Configure tsserver plugin + { + "neovim/nvim-lspconfig", + opts = function(_, opts) + LazyVim.extend(opts.servers.vtsls, "settings.vtsls.tsserver.globalPlugins", { + { + name = "@astrojs/ts-plugin", + location = LazyVim.get_pkg_path( + "astro-language-server", + "/node_modules/@astrojs/ts-plugin", + { warn = false } + ), + enableForWorkspaceTypeScriptVersions = true, + }, + }) + end, + }, } diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 9b2135f5..12c7abd4 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -221,10 +221,13 @@ end --- available yet and trigger errors. ---@param pkg string ---@param path? string -function M.get_pkg_path(pkg, path) +---@param opts? { warn?: boolean } +function M.get_pkg_path(pkg, path, opts) + opts = opts or {} + opts.warn = opts.warn == nil and true or opts.warn path = path or "" local ret = vim.env.MASON .. "/packages/" .. pkg .. "/" .. path - if not vim.loop.fs_stat(ret) then + if opts.warn and not vim.loop.fs_stat(ret) then M.warn(("Mason package path not found for **%s**:\n- `%s`"):format(pkg, path)) end return ret