Skip to content

Commit

Permalink
fix(vue): properly configure hybrid mode (#1071)
Browse files Browse the repository at this point in the history
* fix: hybridMode = false open two tsserver were started.

Now this latest version should be, tsserver supports vue, then enable hybridMode, volar provides the template prompt.

* Update init.lua

* refactor(vue): make vue config more robust

---------

Co-authored-by: Micah Halter <[email protected]>
  • Loading branch information
chaozwn and mehalter authored Jul 8, 2024
1 parent 7a29be0 commit 1349cda
Showing 1 changed file with 43 additions and 54 deletions.
97 changes: 43 additions & 54 deletions lua/astrocommunity/pack/vue/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,58 @@ return {
"AstroNvim/astrolsp",
optional = true,
---@type AstroLSPOpts
opts = {
---@diagnostic disable: missing-fields
config = {
volar = {
init_options = {
vue = {
hybridMode = false,
},
},
settings = {
typescript = {
updateImportsOnFileMove = { enabled = "always" },
inlayHints = {
parameterNames = { enabled = "all" },
parameterTypes = { enabled = true },
variableTypes = { enabled = true },
propertyDeclarationTypes = { enabled = true },
functionLikeReturnTypes = { enabled = true },
enumMemberValues = { enabled = true },
},
},
javascript = {
updateImportsOnFileMove = { enabled = "always" },
inlayHints = {
parameterNames = { enabled = "literals" },
parameterTypes = { enabled = true },
variableTypes = { enabled = true },
propertyDeclarationTypes = { enabled = true },
functionLikeReturnTypes = { enabled = true },
enumMemberValues = { enabled = true },
opts = function(_, opts)
local astrocore = require "astrocore"
local vtsls_ft = astrocore.list_insert_unique(vim.tbl_get(opts, "config", "vtsls", "filetypes") or {
"javascript",
"javascriptreact",
"javascript.jsx",
"typescript",
"typescriptreact",
"typescript.tsx",
}, { "vue" })
return astrocore.extend_tbl(opts, {
---@diagnostic disable: missing-fields
config = {
volar = {
init_options = {
vue = {
hybridMode = true,
},
},
},
},
vtsls = {
settings = {
vtsls = {
tsserver = {
globalPlugins = {},
vtsls = {
filetypes = vtsls_ft,
settings = {
vtsls = {
tsserver = {
globalPlugins = {},
},
},
},
},
before_init = function(_, config)
local astrocore_ok, astrocore = pcall(require, "astrocore")
local registry_ok, registry = pcall(require, "mason-registry")
if not astrocore_ok or not registry_ok then return end
before_init = function(_, config)
local registry_ok, registry = pcall(require, "mason-registry")
if not registry_ok then return end
local vuels = registry.get_package "vue-language-server"

local volar_install_path = registry.get_package("vue-language-server"):get_install_path()
.. "/node_modules/@vue/language-server"
if vuels:is_installed() then
local volar_install_path = vuels:get_install_path() .. "/node_modules/@vue/language-server"

local vue_plugin_config = {
name = "@vue/typescript-plugin",
location = volar_install_path,
languages = { "vue" },
configNamespace = "typescript",
enableForWorkspaceTypeScriptVersions = true,
}
local vue_plugin_config = {
name = "@vue/typescript-plugin",
location = volar_install_path,
languages = { "vue" },
configNamespace = "typescript",
enableForWorkspaceTypeScriptVersions = true,
}

astrocore.list_insert_unique(config.settings.vtsls.tsserver.globalPlugins, { vue_plugin_config })
end,
astrocore.list_insert_unique(config.settings.vtsls.tsserver.globalPlugins, { vue_plugin_config })
end
end,
},
},
},
},
})
end,
},
{
"nvim-treesitter/nvim-treesitter",
Expand Down

0 comments on commit 1349cda

Please sign in to comment.