Neovim Setup Guide: Vue Language Server v3.0+ #5931
Replies: 3 comments
-
|
I was just trying to set up vue_ls, which kept saying it couldn't find ts_ls or vtsls, and I came across your instructions. They seemed a bit off to me. So I did some more googling and found this: https://github.com/vuejs/language-tools/wiki/Neovim. Based on that guide and partly on yours, I’ve put together a working config: return {
"neovim/nvim-lspconfig",
dependencies = {
-- opts передается для автоматического вызова setup
{ "mason-org/mason.nvim", opts = {} },
"williamboman/mason-lspconfig.nvim",
"neovim/nvim-lspconfig",
"saghen/blink.cmp",
},
config = function()
-- Обзяательно должен вызываться первым
require("mason-lspconfig").setup({
-- Тут объявлены языковые сервера, которые нужно поставить через Mason
ensure_installed = {
"bashls",
"biome",
"cssls",
"docker_language_server",
"html",
"jsonls",
"lua_ls",
"ruff",
"stylua",
-- "ts_ls",
"vimls",
"vtsls",
"vue_ls",
"yamlls",
},
})
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = vim.tbl_deep_extend(
"force",
capabilities,
require("blink.cmp").get_lsp_capabilities()
)
-- Мы тут задаем настройки для всех серверов, и подгружаем пользовательские конфиги
vim.lsp.config("*", {
capabilities = capabilities,
root_markers = { ".git" },
})
-- https://github.com/vuejs/language-tools/wiki/Neovim
local vue_language_server_path = vim.fn.stdpath("data")
.. "/mason/packages/vue-language-server/node_modules/@vue/language-server"
local tsserver_filetypes = {
"typescript",
"javascript",
"javascriptreact",
"typescriptreact",
"vue",
}
local vue_plugin = {
name = "@vue/typescript-plugin",
location = vue_language_server_path,
languages = { "vue" },
configNamespace = "typescript",
}
local vtsls_config = {
settings = {
vtsls = {
tsserver = {
globalPlugins = {
vue_plugin,
},
},
},
},
filetypes = tsserver_filetypes,
}
local ts_ls_config = {
init_options = {
plugins = {
vue_plugin,
},
},
filetypes = tsserver_filetypes,
}
vim.lsp.config("vtsls", vtsls_config)
vim.lsp.config("ts_ls", ts_ls_config)
-- ...
end,
} |
Beta Was this translation helpful? Give feedback.
-
|
But it's better to define language server settings in separate files.
-- vue_ls не будет работать без этих настроек
-- @see <https://github.com/vuejs/language-tools/wiki/Neovim>
local vue_language_server_path = vim.fn.stdpath("data")
.. "/mason/packages/vue-language-server/node_modules/@vue/language-server"
local tsserver_filetypes = {
"typescript",
"javascript",
"javascriptreact",
"typescriptreact",
"vue",
}
local vue_plugin = {
name = "@vue/typescript-plugin",
location = vue_language_server_path,
languages = { "vue" },
configNamespace = "typescript",
}
return {
settings = {
vtsls = {
tsserver = {
globalPlugins = {
vue_plugin,
},
},
},
},
filetypes = tsserver_filetypes,
} |
Beta Was this translation helpful? Give feedback.
-
Why is this necessary? I have my lsp configuration in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Neovim Setup Guide: Vue Language Server v3.0+ (Hybrid Mode)
Quick Navigation
Background
This guide is for Neovim users setting up Vue 3/Nuxt 3 LSP support. Neovim uses Language Server Protocol (LSP) for features like go-to-definition, autocomplete, and type checking.
Common tools:
Problem
After upgrading to Vue Language Server v3.0+, LSP navigation (
gd= go-to-definition,gr= find references) stops working in.vuefiles.Error message:
Cause
Vue Language Server v3.0+ removed take-over mode (#5248).
Old setup (take-over mode):
vue_lshandled everythingNew setup (hybrid mode):
vue_lshandles template + CSSts_lshandles TypeScript/JavaScript (including<script>in.vuefiles)Understanding Your LSP Setup
Before applying the fix, you need to identify how your Neovim LSP is configured. There are three common patterns:
Pattern 1: Mason + lspconfig with Handlers (Most Common)
Your LSP servers are configured in a
serverstable and installed automatically via Mason handlers.Key files:
lua/plugins/lsp.luaor similar - Contains theserverstablerequire('mason-lspconfig').setup { handlers = { ... } }Pattern 2: Manual lspconfig Setup
Each LSP server is manually configured with
require('lspconfig').server_name.setup().Key files:
lua/plugins/lsp.luaorinit.luarequire('lspconfig').ts_ls.setup({ ... })Pattern 3: Custom LSP Configuration
You have a custom setup with
vim.lsp.start()or other patterns.How to Identify Your Setup Pattern
Not sure which pattern you have? Run these commands in Neovim:
Find your LSP configuration file:
Then search for:
lsp.luaorlspconfigOpen the file and look for these patterns:
Pattern 1 indicators:
require('mason-lspconfig').setuphandlers = { function(server_name) ... }serverstable (usually near the top)Pattern 2 indicators:
require('lspconfig').ts_ls.setup({ ... })require('lspconfig').lua_ls.setup({ ... })Still not sure?
williamboman/mason-lspconfig.nvim, you're probably using Pattern 1Solution for Neovim
Choose the solution that matches your setup pattern:
Solution A: Mason + lspconfig with Handlers (Recommended)
If your config uses
mason-lspconfigwith handlers (Pattern 1), modify your LSP configuration file:1. Add Vue plugin to ts_ls server configuration:
Find your
serverstable (usually inlua/plugins/lsp.lua) and add/modify thets_lsentry:2. Add autocmd to ensure ts_ls attaches to Vue files:
Add this after your
mason-lspconfig.setup()call (but still inside your config function):Complete example for Pattern 1:
Click to see full lsp.lua example (lazy.nvim + mason-lspconfig)
Solution B: Manual lspconfig Setup
If you manually call
require('lspconfig').server_name.setup()for each server (Pattern 2):Solution C: Project-local node_modules
If you installed Vue Language Server in your project (not via Mason):
Installation
Using Mason (recommended):
Install:
vue-language-servertypescript-language-serverOr using npm in your project:
Verification
.vuefile in Neovim:LspInfo(in normal mode, type:LspInfothen Enter)gd(should jump to definition)For Nuxt 3 Users
Ensure
tsconfig.jsonextends Nuxt's generated types:{ "extends": "./.nuxt/tsconfig.json" }Generate type definitions:
Troubleshooting
Still not working?
Check plugin path is correct:
Should show the
@vue/typescript-pluginwith a valid location path.Check LSP logs:
Adjust the
locationpath ininit_optionsbased on where@vue/language-serveris installed on your system.Environment Tested
References
Beta Was this translation helpful? Give feedback.
All reactions