aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabien <vaga@users.noreply.github.com>2024-12-10 06:10:53 +0100
committerGitHub <noreply@github.com>2024-12-10 13:10:53 +0800
commitcef5a113b19b9d04729017efca2edffd16b884ae (patch)
treeab590e26b260512931b6637ff26dcfbf92390978
parentfix(volar & astro): remove duplicate node_modules (#3497) (diff)
downloadnvim-lspconfig-cef5a113b19b9d04729017efca2edffd16b884ae.tar
nvim-lspconfig-cef5a113b19b9d04729017efca2edffd16b884ae.tar.gz
nvim-lspconfig-cef5a113b19b9d04729017efca2edffd16b884ae.tar.bz2
nvim-lspconfig-cef5a113b19b9d04729017efca2edffd16b884ae.tar.lz
nvim-lspconfig-cef5a113b19b9d04729017efca2edffd16b884ae.tar.xz
nvim-lspconfig-cef5a113b19b9d04729017efca2edffd16b884ae.tar.zst
nvim-lspconfig-cef5a113b19b9d04729017efca2edffd16b884ae.zip
docs(volar): fix dead links and remove outdated content (#3498)
* docs(volar): refine Typescript SDK path lookup process * docs(volar): fix dead links and improve clarity
-rw-r--r--lua/lspconfig/configs/volar.lua82
1 files changed, 38 insertions, 44 deletions
diff --git a/lua/lspconfig/configs/volar.lua b/lua/lspconfig/configs/volar.lua
index 7628238b..529d851c 100644
--- a/lua/lspconfig/configs/volar.lua
+++ b/lua/lspconfig/configs/volar.lua
@@ -5,7 +5,7 @@ local function get_typescript_server_path(root_dir)
return project_root and (util.path.join(project_root, 'typescript', 'lib')) or ''
end
--- https://github.com/johnsoncodehk/volar/blob/20d713b/packages/shared/src/types.ts
+-- https://github.com/vuejs/language-tools/blob/master/packages/language-server/lib/types.ts
local volar_init_options = {
typescript = {
tsdk = '',
@@ -30,82 +30,76 @@ return {
},
docs = {
description = [[
-https://github.com/johnsoncodehk/volar/tree/20d713b/packages/vue-language-server
+https://github.com/vuejs/language-tools/tree/master/packages/language-server
Volar language server for Vue
Volar can be installed via npm:
-
```sh
npm install -g @vue/language-server
```
-Volar by default supports Vue 3 projects. Vue 2 projects need
-[additional configuration](https://github.com/vuejs/language-tools/tree/master/packages/vscode-vue#usage).
-
-**TypeScript support**
-As of release 2.0.0, Volar no longer wraps around ts_ls. For typescript
-support, `ts_ls` needs to be configured with the `@vue/typescript-plugin`
-plugin.
+Volar by default supports Vue 3 projects.
+For Vue 2 projects, [additional configuration](https://github.com/vuejs/language-tools/blob/master/extensions/vscode/README.md?plain=1#L19) are required.
-**Take Over Mode**
+**Hybrid Mode (by default)**
-Volar (prior to 2.0.0), can serve as a language server for both Vue and TypeScript via [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471).
+In this mode, the Vue Language Server exclusively manages the CSS/HTML sections.
+You need the `ts_ls` server with the `@vue/typescript-plugin` plugin to support TypeScript in `.vue` files.
+See `ts_ls` section for more information
-To enable Take Over Mode, override the default filetypes in `setup{}` as follows:
+**No Hybrid Mode**
+Volar will run embedded `ts_ls` therefore there is no need to run it separately.
```lua
-require'lspconfig'.volar.setup{
- filetypes = {'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json'}
+local lspconfig = require('lspconfig')
+
+lspconfig.volar.setup {
+ -- add filetypes for typescript, javascript and vue
+ filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
+ init_options = {
+ vue = {
+ -- disable hybrid mode
+ hybridMode = false,
+ },
+ },
}
+-- you must remove ts_ls setup
+-- lspconfig.ts_ls.setup {}
```
**Overriding the default TypeScript Server used by Volar**
-The default config looks for TS in the local `node_modules`. This can lead to issues
+The default config looks for TypeScript in the local `node_modules`. This can lead to issues
e.g. when working on a [monorepo](https://monorepo.tools/). The alternatives are:
- use a global TypeScript Server installation
-
```lua
-require'lspconfig'.volar.setup{
+require'lspconfig'.volar.setup {
init_options = {
typescript = {
- tsdk = '/path/to/.npm/lib/node_modules/typescript/lib'
- -- Alternative location if installed as root:
- -- tsdk = '/usr/local/lib/node_modules/typescript/lib'
+ -- replace with your global TypeScript library path
+ tsdk = '/path/to/node_modules/typescript/lib'
}
}
}
```
- use a local server and fall back to a global TypeScript Server installation
-
```lua
-local util = require 'lspconfig.util'
-local function get_typescript_server_path(root_dir)
-
- local global_ts = '/home/[yourusernamehere]/.npm/lib/node_modules/typescript/lib'
- -- Alternative location if installed as root:
- -- local global_ts = '/usr/local/lib/node_modules/typescript/lib'
- local found_ts = ''
- local function check_dir(path)
- found_ts = util.path.join(path, 'node_modules', 'typescript', 'lib')
- if vim.loop.fs_stat(found_ts) then
- return path
+require'lspconfig'.volar.setup {
+ init_options = {
+ typescript = {
+ -- replace with your global TypeScript library path
+ tsdk = '/path/to/node_modules/typescript/lib'
+ }
+ },
+ on_new_config = function(new_config, new_root_dir)
+ local lib_path = vim.fs.find('node_modules/typescript/lib', { path = new_root_dir, upward = true })[1]
+ if lib_path then
+ new_config.init_options.typescript.tsdk = lib_path
end
end
- if util.search_ancestors(root_dir, check_dir) then
- return found_ts
- else
- return global_ts
- end
-end
-
-require'lspconfig'.volar.setup{
- on_new_config = function(new_config, new_root_dir)
- new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir)
- end,
}
```
]],