vuejs / language-tools

โšก High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.7k stars 385 forks source link

Version 2 stop working with nvim lsp #3925

Closed RayGuo-ergou closed 5 months ago

RayGuo-ergou commented 5 months ago

Update: check readme.


tldr:

local mason_registry = require('mason-registry')
local ts_plugin_path = mason_registry.get_package('vue-language-server'):get_install_path() .. '/node_modules/@vue/language-server/node_modules/@vue/typescript-plugin'

local servers = {
  tsserver = {
    init_options = {
      plugins = {
        {
          name = '@vue/typescript-plugin',
          location = ts_plugin_path,
          -- If .vue file cannot be recognized in either js or ts file try to add `typescript` and `javascript` in languages table.
          languages = { 'vue' },
        },
      },
    },
    filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
  },
  volar = {},
}

local mason_lspconfig = require('mason-lspconfig')

-- Auto cmd (LspAttach) to setup keybind, codelens, and formatting stuff
-- I assume everyone should have this configured already but just for reference
-- @see https://github.com/RayGuo-ergou/dotfiles/blob/cdf866790b1daa27444bd9991025740c8eb74c5b/nvim/lua/ergou/util/lsp.lua#L43
Util.lsp.lsp_autocmd()

local capabilities = vim.lsp.protocol.make_client_capabilities()
-- If you need cmp
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
mason_lspconfig.setup({
ensure_installed = vim.tbl_keys(servers),
handlers = {
    function(server_name)
    local server = servers[server_name] or {}
    server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
    require('lspconfig')[server_name].setup(server)
    end,
},
})

Hi,

I am having issue to run volar@2.0.1 with neovim lsp.

cmd: vue-language-server --stdio

With 1.8.27: image image image

With 2.0.1: image image image

CofCat456 commented 5 months ago

It seems that both installing Volar and @vue/typescript-plugin is necessary for normal usage.

However, enabling two language server may cause performance issues and they may interfere with each other, affecting the operation of the cmp.

It seems to be faster to use than before ๐Ÿค”

ogios commented 5 months ago

@CofCat456 for me it feels slower, i have to wait for 1to3 seconds for one autocompletion, sometimes slower than codeium suggestions, and hints sometimes just stick at the old place, especially when i change the lang of <script> in SFC files, it takes way too long to recover and won't diagnose the file again. Also, no package or file name of the auto-imports in cmp.

chaozwn commented 5 months ago

typescript-tool.nvim error link: https://github.com/pmizio/typescript-tools.nvim/issues/250

haug1 commented 5 months ago

I'm noob at configuring neovim, what do I need to do to get version > 2 working on my end? After installing LazyVim and installing the vue-language-server plugin with Mason, it's not working. After downgrading to 1.8.27, it's working. What do I need to do to get the latest version working in LazyVim?

sungkang commented 5 months ago

I'm noob at configuring neovim, what do I need to do to get version > 2 working on my end? After installing LazyVim and installing the vue-language-server plugin with Mason, it's not working. After downgrading to 1.8.27, it's working. What do I need to do to get the latest version working in LazyVim?

Follow the instructions to add vue support in tsserver: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#tsserver

and npm install -D @vue/typescript-plugin in your project and then the location property can be whatever string you want, but has to be populated. OR you can install that globally and add that path in location.

haug1 commented 5 months ago

I'm noob at configuring neovim, what do I need to do to get version > 2 working on my end? After installing LazyVim and installing the vue-language-server plugin with Mason, it's not working. After downgrading to 1.8.27, it's working. What do I need to do to get the latest version working in LazyVim?

Follow the instructions to add vue support in tsserver: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#tsserver

and npm install -D @vue/typescript-plugin in your project and then the location property can be whatever string you want, but has to be populated. OR you can install that globally and add that path in location.

Thanks. But will these manual steps always be required from now on? It makes the user experience worse. Maybe it's a Mason issue and not a Volar issue, I don't know? Hope it will not require additional user config in the future!

RayGuo-ergou commented 5 months ago

I think it's neither Volar or Mason's "issue". Before 2.0 Volar cannot co-op with Typescript server, that's why there's a take over mode. To me the take over mode is more like a "work around". The new approach is more ideal in my opinion, and it should be clear for everyone as long as it documented properly.

tmillsonco commented 5 months ago

Even with the recommended settings, on a fresh Vue project with typescript configured, I still cannot get Go to Definition or Go to Reference to work for my custom components in either the <template> or <script> part of a Vue SFC -- it just points to vite-env.d.ts. Go to Definition and Go to Reference both work fine for purely TypeScript references and I even get proper diagnostics in both the <template> and <script> sections for both Vue and TS entities.

When I run :LspInfo I can see that both tsserver and volar are running (which I think is correct?) because without volar running I don't seem to get proper diagnostics in the