Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Volar (currently called Vue Language Tools) to v2.0 #728

Merged
merged 6 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ You can change the directory to install servers by set `g:lsp_settings_servers_d
| Vim | vim-language-server | Yes | Yes |
| Vala | vala-language-server | No | No |
| Veryl | veryl-ls | Yes | Yes |
| Vue | volar-server | Yes | Yes |
| Vue | volar-server (Vue Language Tools) | Yes | Yes |
| Vue | vls | Yes | Yes |
| V | v-analyzer | Yes | Yes |
| V | vlang-vls | Yes | Yes |
Expand Down Expand Up @@ -315,6 +315,14 @@ To use sorbet, you need to install rubocop in your Ruby project using bundler.
Also, [Watchman](https://facebook.github.io/watchman/) is required to watch file changes.
For more details, please see [Sorbet](https://sorbet.org/docs/vscode#installing-and-enabling-the-sorbet-extension) and [Watchman](https://facebook.github.io/watchman/docs/install.html) documentations.

### [volar (Vue Language Tools)](https://github.com/vuejs/language-tools)

To enable full Vue support, both `typescript-language-server` and `volar-server` should be installed and enabled in `vue` filetype.

```vim
let g:lsp_settings_filetype_vue = ['typescript-language-server', 'volar-server']
```

## Extra Configurations

Most of the configurations are not required.
Expand Down
4 changes: 2 additions & 2 deletions installer/install-volar-server.cmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off

call "%~dp0\npm_install.cmd" vue-language-server @vue/language-server@~1.8.0
call "%~dp0\npm_install.cmd" vue-language-server @vue/language-server@~2.0.0
ren vue-language-server.cmd volar-server.cmd
call npm install typescript@5.0.2
call npm install typescript@5.4.2
4 changes: 2 additions & 2 deletions installer/install-volar-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -e

"$(dirname "$0")/npm_install.sh" vue-language-server @vue/language-server@~1.8.0
"$(dirname "$0")/npm_install.sh" vue-language-server @vue/language-server@~2.0.0
mv vue-language-server volar-server
npm install typescript@5.0.2
npm install typescript@5.4.2
12 changes: 12 additions & 0 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,18 @@
"name": "leafOfTree/vim-vue-plugin"
}
},
{
"command": "typescript-language-server",
"url": "https://github.com/typescript-language-server/typescript-language-server",
"description": "TypeScript & JavaScript Language Server",
"requires": [
"npm"
],
"root_uri_patterns": [
"package.json",
"tsconfig.json"
]
},
{
"command": "vls",
"url": "https://github.com/vuejs/vetur",
Expand Down
29 changes: 27 additions & 2 deletions settings/typescript-language-server.vim
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
function! s:find_vue_plugin() abort
let plugin_location = lsp_settings#servers_dir() .. '/volar-server/node_modules/@vue/typescript-plugin'

Check failure on line 2 in settings/typescript-language-server.vim

View workflow job for this annotation

GitHub Actions / runner / vint

[vint] reported by reviewdog 🐶 unexpected token: . (see vim-jp/vim-vimlparser) Raw Output: settings/typescript-language-server.vim:2:53: unexpected token: . (see vim-jp/vim-vimlparser)
if !isdirectory(plugin_location)
return v:null
endif

return {
\ 'name': '@vue/typescript-plugin',
\ 'location': plugin_location,
\ 'languages': ['vue'],
\ }
endfunction

function! Vim_lsp_settings_typescript_language_server_setup_plugins() abort
let plugins = []

let vue_plugin = s:find_vue_plugin()
if !empty(vue_plugin)
call add(plugins, vue_plugin)
endif

return plugins
endfunction

augroup vim_lsp_settings_typescript_language_server
au!
LspRegisterServer {
Expand All @@ -14,9 +38,10 @@
\ 'includeInlayEnumMemberValueHints': v:true,
\ 'includeInlayFunctionLikeReturnTypeHints': v:true
\ },
\ 'plugins': Vim_lsp_settings_typescript_language_server_setup_plugins(),
\ }),
\ 'allowlist': lsp_settings#get('typescript-language-server', 'allowlist', ['javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'typescript.tsx']),
\ 'blocklist': lsp_settings#get('typescript-language-server', 'blocklist', {c->empty(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'node_modules/')) ? ['typescript', 'javascript', 'typescriptreact', 'javascriptreact'] : []}),
\ 'allowlist': lsp_settings#get('typescript-language-server', 'allowlist', ['javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'typescript.tsx', 'vue']),
\ 'blocklist': lsp_settings#get('typescript-language-server', 'blocklist', {c->empty(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'node_modules/')) ? ['typescript', 'javascript', 'typescriptreact', 'javascriptreact', 'vue'] : []}),
\ 'config': lsp_settings#get('typescript-language-server', 'config', lsp_settings#server_config('typescript-language-server')),
\ 'workspace_config': lsp_settings#get('typescript-language-server', 'workspace_config', {}),
\ 'semantic_highlight': lsp_settings#get('typescript-language-server', 'semantic_highlight', {}),
Expand Down
16 changes: 14 additions & 2 deletions settings/volar-server.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
let ts_path = '/node_modules/typescript/lib'

let project_dir = lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'package.json')
let tsserverlibrary_path = project_dir . ts_path
let tsserverlibrary_path = project_dir .. ts_path

Check failure on line 5 in settings/volar-server.vim

View workflow job for this annotation

GitHub Actions / runner / vint

[vint] reported by reviewdog 🐶 unexpected token: . (see vim-jp/vim-vimlparser) Raw Output: settings/volar-server.vim:5:43: unexpected token: . (see vim-jp/vim-vimlparser)

let server_dir = lsp_settings#servers_dir() . '/volar-server'
let server_dir = lsp_settings#servers_dir() .. '/volar-server'
let fallback_path = server_dir . ts_path

let path = filereadable(tsserverlibrary_path) ? tsserverlibrary_path : fallback_path
Expand Down Expand Up @@ -52,6 +52,18 @@
let l:capabilities.signatureHelpProvider = v:true
let l:capabilities.workspaceSymbolProvider = v:true
endif

" check typescript-language-server
let ts_server_dir = lsp_settings#servers_dir() .. '/typescript-language-server'
if !isdirectory(ts_server_dir)
call lsp_settings#utils#warning('Please install typescript-language-server to enable Vue support')
endif

if !exists('g:lsp_settings_filetype_vue') ||
\ index(g:lsp_settings_filetype_vue, 'volar-server') == -1 ||
\ index(g:lsp_settings_filetype_vue, 'typescript-language-server') == -1
call lsp_settings#utils#warning('Both ''volar-server'' and ''typescript-language-server'' should be included in g:lsp_settings_filetype_vue to enable Vue support')
endif
endfunction

augroup lsp_install_volar_server
Expand Down
Loading