Skip to content

Commit 8caa6d8

Browse files
authored
docs: update readme with neovim lspconfig setup (#4134)
* docs: update readme with neovim lspconfig setup * docs: add italic to hint * docs: nvim configured with lspconfig and drop mason As not everyone is using mason, it's better to use plain lspconfig * docs: indent of code block * docs: nvim configuration tweak * docs: add hybridMode default value to README.md * docs: update readme for nvim lsp * docs: readme nvim lsp tweak
1 parent ef908e2 commit 8caa6d8

File tree

1 file changed

+83
-2
lines changed

1 file changed

+83
-2
lines changed

README.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,89 @@
2727
*Vue language client for coc.nvim*
2828

2929
[neovim/nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) ⚡ 🤝 \
30-
*Vue language server configuration for Neovim* \
31-
[[Volar 2.0 version set up tutorial](https://github.com/vuejs/language-tools/issues/3925)]
30+
*Vue language server configuration for Neovim*
31+
32+
<details>
33+
<summary>How to configure vue language server with neovim and lsp?</summary>
34+
35+
### Hybrid mode configuration (Requires `@vue/language-server` version `^2.0.0`)
36+
37+
Note: The "Take Over" mode has been discontinued. Instead, a new "Hybrid" mode has been introduced. In this mode, the Vue Language Server exclusively manages the CSS/HTML sections. As a result, you must run `@vue/language-server` in conjunction with a TypeScript server that employs `@vue/typescript-plugin`. Below is a streamlined configuration for Neovim's LSP, updated to accommodate the language server following the upgrade to version `2.0.0`.
38+
39+
```lua
40+
-- If you are using mason.nvim, you can get the ts_plugin_path like this
41+
-- local mason_registry = require('mason-registry')
42+
-- local vue_language_server_path = mason_registry.get_package('vue-language-server'):get_install_path() .. '/node_modules/@vue/language-server'
43+
44+
local vue_language_server_path = '/path/to/@vue/language-server'
45+
46+
local lspconfig = require('lspconfig')
47+
48+
lspconfig.tsserver.setup {
49+
init_options = {
50+
plugins = {
51+
{
52+
name = '@vue/typescript-plugin',
53+
location = vue_language_server_path,
54+
languages = { 'vue' },
55+
},
56+
},
57+
},
58+
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
59+
}
60+
61+
-- No need to set `hybridMode` to `true` as it's the default value
62+
lspconfig.volar.setup {}
63+
```
64+
65+
### None-Hybrid mode(similar to takeover mode) configuration (Requires `@vue/language-server` version `^2.0.7`)
66+
67+
Note: If `hybridMode` is set to `false` `Volar` will run embedded `tsserver` therefore there is no need to run it separately.
68+
69+
For more information see [#4119](https://github.com/vuejs/language-tools/pull/4119)
70+
71+
*Make sure you have typescript installed globally or pass the location to volar*
72+
73+
Use volar for all `.{vue,js,ts,tsx,jsx}` files.
74+
```lua
75+
local lspconfig = require('lspconfig')
76+
77+
-- lspconfig.tsserver.setup {}
78+
lspconfig.volar.setup {
79+
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
80+
init_options = {
81+
vue = {
82+
hybridMode = false,
83+
},
84+
},
85+
}
86+
```
87+
88+
Use `volar` for only `.vue` files and `tsserver` for `.ts` and `.js` files.
89+
```lua
90+
local lspconfig = require('lspconfig')
91+
92+
lspconfig.tsserver.setup {
93+
init_options = {
94+
plugins = {
95+
{
96+
name = '@vue/typescript-plugin',
97+
location = '/path/to/@vue/language-server',
98+
languages = { 'vue' },
99+
},
100+
},
101+
},
102+
103+
lspconfig.volar.setup {
104+
init_options = {
105+
vue = {
106+
hybridMode = false,
107+
},
108+
},
109+
},
110+
```
111+
112+
</details>
32113

33114
[mattn/vim-lsp-settings](https://github.com/mattn/vim-lsp-settings)\
34115
*Vue language server auto configuration for vim-lsp*

0 commit comments

Comments
 (0)