vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.56k stars 373 forks source link

No "Element is missing end tag" error when using hybrid mode #4371

Closed b-erhart closed 1 month ago

b-erhart commented 1 month ago

Description

In the <template> section of .vue files, I don't get "Element is missing end tag" errors by the LSP if I use volar in hybrid mode. They are displayed if hybrid mode is disabled.

Other errors like wrong variable names are displayed in both configurations.

More Info

Volar version: 2.0.17 Editor: Neovim with Volar integration via lspconfig

Faulty configuration (hybrid mode enabled)

local lspconfig = require('lspconfig')
lspconfig.tsserver.setup({
    init_options = {
        plugins = {
            {
                name = '@vue/typescript-plugin',
                location = '<location>',
                languages = { 'vue' }
            },
        },
    },
    filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
})
lspconfig.volar.setup({})

This results in: grafik

Working configuration (hybrid mode disabled)

local lspconfig = require('lspconfig')
lspconfig.tsserver.setup({
    init_options = {
        plugins = {
            {
                name = '@vue/typescript-plugin',
                location = '<location>',
                languages = { 'vue' }
            },
        },
    },
})
lspconfig.volar.setup({
    init_options = {
        vue = {
            hybridMode = false,
        },
    },
})

This results in: grafik

RayGuo-ergou commented 1 month ago

I cannot reproduce this with same config. image

are you running volar and ts plugin under same version?

b-erhart commented 1 month ago

Both volar and the TS plugin are running version 2.0.17:

$ npm list -g @vue/language-server   
/home/b-erhart/.local/share/npm/lib
└── @vue/language-server@2.0.17

$ npm list -g @vue/typescript-plugin
/home/b-erhart/.local/share/npm/lib
├─┬ @vue/language-server@2.0.17
│ ├─┬ @vue/language-service@2.0.17
│ │ └── @vue/typescript-plugin@2.0.17 deduped
│ └── @vue/typescript-plugin@2.0.17
└── @vue/typescript-plugin@2.0.17

Installing the typescript plugin for the project instead of globally doesn't change anything. Setting up the LSP with Mason instead of installing it globally with npm also doesn't change the behavior. If I find the time, I will check if I can replicate this on a different machine with a minimal neovim config.

hkeidesen commented 1 month ago

I have the same config as OP, but I don't get "Element is missing end tag" with either Hybrid mode on or off.

RayGuo-ergou commented 1 month ago

hybrid mode should not matter at all as it's purely provided by vue-language-server, e.g. I can get that error even without javascript support (hybrid mode on, tsserver disabled) image image

Could you check the lspinfo and lsplog to see if there has any error/warnings?

hkeidesen commented 1 month ago

I tried your neovim config (from your repo), so that we could at least eliminate any configuration errors.

LspInfo:

 8 client(s) attached to this buffer: 
 Client: typos_lsp (id: 1, bufnr: [38, 16])
    filetypes:       *
    autostart:       true
    root directory:  Running in single file mode.
    cmd:             /Users/hk/.local/share/nvim/mason/bin/typos-lsp

 Client: tailwindcss (id: 2, bufnr: [38, 16])
    filetypes:       aspnetcorerazor, astro, astro-markdown, blade, clojure, django-html, htmldjango, edge, eelixir, elixir, ejs, erb, eruby, gohtml, gohtmltmpl, haml, handlebars, hbs, html, html-eex, heex, jade, leaf, liquid, markdown, mdx, mustache, njk, nunjucks, php, razor, slim, twig, css, less, postcss, sass, scss, stylus, sugarss, javascript, javascriptreact, reason, rescript, typescript, typescriptreact, vue, svelte, templ
    autostart:       true
    root directory:  /Users/hk/Projects/mlink-vue3-frontend/webapp
    cmd:             /Users/hk/.local/share/nvim/mason/bin/tailwindcss-language-server --stdio

 Client: eslint (id: 3, bufnr: [38, 16])
    filetypes:       typescript, javascript, javascriptreact, typescriptreact, vue, json, jsonc, markdown, yaml, yaml.docker-compose, yaml.gitlab
    autostart:       true
    root directory:  /Users/hk/Projects/mlink-vue3-frontend/webapp
    cmd:             /Users/hk/.local/share/nvim/mason/bin/vscode-eslint-language-server --stdio

 Client: tsserver (id: 4, bufnr: [38, 16])
    filetypes:       javascript, javascriptreact, javascript.jsx, typescript, typescriptreact, typescript.tsx, vue
    autostart:       true
    root directory:  /Users/hk/Projects/mlink-vue3-frontend/webapp
    cmd:             /Users/hk/.local/share/nvim/mason/bin/typescript-language-server --stdio

 Client: null-ls (id: 5, bufnr: [38, 16])
    filetypes:       php, zsh
    autostart:       false
    root directory:  /Users/hk/Projects/mlink-vue3-frontend
    cmd:             <function>

 Client: copilot (id: 6, bufnr: [38, 16])
    filetypes:       
    autostart:       false
    root directory:  /Users/hk/Projects/mlink-vue3-frontend/webapp
    cmd:             node /Users/hk/.local/share/nvim/lazy/copilot.lua/copilot/index.js

 Client: emmet_ls (id: 7, bufnr: [38])
    filetypes:       astro, css, eruby, html, htmldjango, javascriptreact, less, pug, sass, scss, svelte, typescriptreact, vue
    autostart:       true
    root directory:  /Users/hk/Projects/mlink-vue3-frontend
    cmd:             /Users/hk/.local/share/nvim/mason/bin/emmet-ls --stdio

 Client: volar (id: 8, bufnr: [38])
    filetypes:       vue
    autostart:       true
    root directory:  /Users/hk/Projects/mlink-vue3-frontend/webapp
    cmd:             /Users/hk/.local/share/nvim/mason/bin/vue-language-server --stdio

 Other clients that match the filetype: vue

 Config: unocss
    filetypes:         html, javascriptreact, rescript, typescriptreact, vue, svelte
    root directory:    Not found.
    cmd:               /Users/hk/.local/share/nvim/mason/bin/unocss-language-server --stdio
    cmd is executable: true
    autostart:         true
    custom handlers:   

LspLog:

[START][2024-05-15 12:50:34] LSP logging initiated
[WARN][2024-05-15 12:50:34] ...lsp/handlers.lua:137 "The language server eslint triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[WARN][2024-05-15 12:50:34] ...lsp/handlers.lua:137 "The language server copilot triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[WARN][2024-05-15 12:52:55] ...lsp/handlers.lua:137 "The language server emmet_ls triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[WARN][2024-05-15 12:52:55] ...lsp/handlers.lua:137 "The language server emmet_ls triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"

I notice when I leave Insert mode after I remove the end tag, I get this error: [

Screenshot 2024-05-15 at 13 04 32

](url)

And no error in the buffer itself:

image
b-erhart commented 1 month ago

Could you check the lspinfo and lsplog to see if there has any error/warnings?

I don't see any errors or warnings there.


To isolate the issue, I've created the following minimal Neovim configuration that I can reproduce the issue with:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
  { "neovim/nvim-lspconfig", lazy = false },
})

local lspconfig = require("lspconfig")
lspconfig.tsserver.setup({
  init_options = {
    plugins = {
      {
        name = "@vue/typescript-plugin",
        location = "/home/b-erhart/.local/share/npm/lib/node_modules/@vue/typescript-plugin",
        languages = {"javascript", "typescript", "vue"},
      },
    },
  },
  filetypes = { "javascript", "typescript", "vue" },
})
lspconfig.volar.setup({})

Maybe you can reproduce the issue with this configuration (+ Volar and TS plugin version 2.0.17) @RayGuo-ergou?

If it can't be reproduced with that config, I think its safe to say that the issue is not with the neovim configuration but occurs somewhere else.

RayGuo-ergou commented 1 month ago

I probably know where's the issue is. I am running nightly neovim:

vim -v
NVIM v0.10.0-dev-3135+g7acf39dda
Build type: RelWithDebInfo
LuaJIT 2.1.1713484068
Run "nvim -V1 -v" for more info

It might be new vue-language-server uses lsp event 0.9.5 does not support yet.

Can you guys try with nightly neovim and see if the problem solved? ( download binary problem the quickest way)

RayGuo-ergou commented 1 month ago

Maybe you can reproduce the issue with this configuration (+ Volar and TS plugin version 2.0.17) @RayGuo-ergou?

Lazy to do things here and there to make this config working, but I tried with nvim.kickstater ( should be minimal enough) and still cannot reproduce this. image image

My best guess as mentioned above is neovim version

b-erhart commented 1 month ago

Can confirm, using the nightly version of Neovim solves the issue. I guess we'll have to use that, wait for the next stable release, or use non-hybrid mode in the mean time.

b-erhart commented 1 month ago

Thank you very much for your support @RayGuo-ergou :)