Asked 1 month ago by CosmicSurveyor231
Why is Volar LSP inactive in Vue script sections and not previewing child components in Neovim?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by CosmicSurveyor231
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I recently started working with the vue3 framework using Neovim 10.0 and decided to integrate an LSP server into my workflow. I set up my configuration as shown below, which works perfectly for the template and style sections, providing completion and suggestions. However, the LSP remains inactive in the script section and I don't get a preview for imported child templates (e.g., when using RouterView in the parent template).
Below is my current configuration:
LUAlocal lspconfig = require "lspconfig" local mason = require "mason" local mason_lspconfig = require "mason-lspconfig" local mason_registry = require "mason-registry" mason.setup {} mason_lspconfig.setup { ensure_installed = { "ts_ls", "volar", }, handler = { function(server) lspconfig[server].setup {} end, volar = function() lspconfig.volar.setup {} end, ts_ls = function() local vue_typescript_server_path = mason_registry.get_package("vue-language-server"):get_install_path() .. "/node_modules/@vue/language-server" lspconfig.ts_ls.setup { init_options = { plugins = { { name = "@vue/typescript-plugin", location = vue_typescript_server_path, languages = { "vue", "javascript", "typescript" }, }, }, }, filetypes = { "javascript", "javascript.jsx", "javascriptreact", "typescript", "typescript.tsx", "typescriptreact", "vue", }, } end, }, } local servers = { "cssls", "html", "jsonls", "marksman", "ts_ls", -- typescript-language-server "volar", -- vue-language-server } for _, lsp in ipairs(servers) do local config = { on_attach = on_attach, on_init = on_init, capabilities = capabilities, } lspconfig[lsp].setup(config) end
In the script section of my Vue file, the LSP is inactive:
HTML// inside this section am on my own <script setup lang="ts"> import { ref } from "vue" import { RouterView } from "vue-router" // don't have preview for RouterView token let something = ref("data") </script>
Additionally, my main.ts file shows an error when importing the main Vue template, though it still compiles and launches the app:
TYPESCRIPTimport { createApp } from 'vue'; import App from './App.vue'; // Cannot find module './App.vue' or its corresponding type declarations. const app = createApp(App);
Any insights on resolving these issues?
Comments 0
•Answers 2
•Views 45
Answer by TychoAI Agent • 1 month ago
Below is some advice that should help resolve your issues:
When working with Vue SFCs, it’s best to let Volar handle the Vue files—including both the
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by MeteorScout267 • 1 month ago
I had a similar problem with my config. My solution was to pass the path of the @vue/typescript-plugin
to the location
field according to lspconfig. If you are using mason
, it is deeply nested in its packages directory.
LUAlocal vue_typescript_plugin_path = vim.fn.stdpath('data') .. '/mason/packages/vue-language-server/node_modules/@vue/language-server/node_modules/@vue/typescript-plugin' ts_ls = { init_options = { plugins = { { name = '@vue/typescript-plugin', location = vue_typescript_plugin_path, languages = { 'vue' }, }, }, }, filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' }, single_file_support = false, },
No comments yet.
No comments yet.