diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2025-04-18 17:44:38 +0200 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2025-04-18 17:44:38 +0200 |
| commit | f8b5cbe6312b568def1f91d747e2cdb8984fdf2e (patch) | |
| tree | c1baf319b22d8ccc7d3468276b5ba9a26dfa2775 /lsp/volar.lua | |
| parent | feat: angularls #3746 (diff) | |
| download | nvim-lspconfig-f8b5cbe6312b568def1f91d747e2cdb8984fdf2e.tar nvim-lspconfig-f8b5cbe6312b568def1f91d747e2cdb8984fdf2e.tar.gz nvim-lspconfig-f8b5cbe6312b568def1f91d747e2cdb8984fdf2e.tar.bz2 nvim-lspconfig-f8b5cbe6312b568def1f91d747e2cdb8984fdf2e.tar.lz nvim-lspconfig-f8b5cbe6312b568def1f91d747e2cdb8984fdf2e.tar.xz nvim-lspconfig-f8b5cbe6312b568def1f91d747e2cdb8984fdf2e.tar.zst nvim-lspconfig-f8b5cbe6312b568def1f91d747e2cdb8984fdf2e.zip | |
docs: cleanup
- brief should live at the top of each file
- fix indentation for some docs
Diffstat (limited to 'lsp/volar.lua')
| -rw-r--r-- | lsp/volar.lua | 149 |
1 files changed, 75 insertions, 74 deletions
diff --git a/lsp/volar.lua b/lsp/volar.lua index 70e8690d..99682977 100644 --- a/lsp/volar.lua +++ b/lsp/volar.lua @@ -1,3 +1,78 @@ +---@brief +--- +--- 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. +--- For Vue 2 projects, [additional configuration](https://github.com/vuejs/language-tools/blob/master/extensions/vscode/README.md?plain=1#L19) are required. +--- +--- **Hybrid Mode (by default)** +--- +--- 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 +--- +--- **No Hybrid Mode** +--- +--- Volar will run embedded `ts_ls` therefore there is no need to run it separately. +--- ```lua +--- 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 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 { +--- init_options = { +--- typescript = { +--- -- 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 +--- 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 +--- } +--- ``` + local function get_typescript_server_path(root_dir) local project_root = vim.fs.dirname(vim.fs.find('node_modules', { path = root_dir, upward = true })[1]) return project_root and vim.fs.joinpath(project_root, 'node_modules', 'typescript', 'lib') or '' @@ -10,80 +85,6 @@ local volar_init_options = { }, } ----@brief ---- --- 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. --- For Vue 2 projects, [additional configuration](https://github.com/vuejs/language-tools/blob/master/extensions/vscode/README.md?plain=1#L19) are required. --- --- **Hybrid Mode (by default)** --- --- 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 --- --- **No Hybrid Mode** --- --- Volar will run embedded `ts_ls` therefore there is no need to run it separately. --- ```lua --- 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 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 { --- init_options = { --- typescript = { --- -- 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 --- 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 --- } --- ``` return { cmd = { 'vue-language-server', '--stdio' }, filetypes = { 'vue' }, |
