Skip to content

Commit f807421

Browse files
creativenullmnikulin
authored andcommitted
fix(vue): volar v1 support (dense-analysis#4552)
* fix: volar v1 support * fix: volar linter errors
1 parent 3ff7094 commit f807421

File tree

3 files changed

+27
-48
lines changed

3 files changed

+27
-48
lines changed

ale_linters/vue/volar.vim

+23-44
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,21 @@
33
" nvim-lspconfig and volar/packages/shared/src/types.ts
44

55
call ale#Set('vue_volar_executable', 'vue-language-server')
6-
call ale#Set('vue_volar_use_global', get(g:, 'ale_use_global_executables', 0))
6+
call ale#Set('vue_volar_use_global', 1)
77
call ale#Set('vue_volar_init_options', {
8-
\ 'documentFeatures': {
9-
\ 'documentColor': v:false,
10-
\ 'documentFormatting': {
11-
\ 'defaultPrintWidth': 100,
12-
\ },
13-
\ 'documentSymbol': v:true,
14-
\ 'foldingRange': v:true,
15-
\ 'linkedEditingRange': v:true,
16-
\ 'selectionRange': v:true,
17-
\ },
18-
\ 'languageFeatures': {
19-
\ 'callHierarchy': v:true,
20-
\ 'codeAction': v:true,
21-
\ 'codeLens': v:true,
22-
\ 'completion': {
23-
\ 'defaultAttrNameCase': 'kebabCase',
24-
\ 'defaultTagNameCase': 'both',
25-
\ 'getDocumentNameCaseRequest': v:false,
26-
\ 'getDocumentSelectionRequest': v:false,
27-
\ },
28-
\ 'definition': v:true,
29-
\ 'diagnostics': v:true,
30-
\ 'documentHighlight': v:true,
31-
\ 'documentLink': v:true,
32-
\ 'hover': v:true,
33-
\ 'references': v:true,
34-
\ 'rename': v:true,
35-
\ 'renameFileRefactoring': v:true,
36-
\ 'schemaRequestService': v:true,
37-
\ 'semanticTokens': v:false,
38-
\ 'signatureHelp': v:true,
39-
\ 'typeDefinition': v:true,
40-
\ 'workspaceSymbol': v:false,
41-
\ },
42-
\ 'typescript': {
43-
\ 'serverPath': '',
44-
\ 'localizedPath': v:null,
45-
\ },
8+
\ 'typescript': { 'tsdk': '' },
469
\})
4710

4811
function! ale_linters#vue#volar#GetProjectRoot(buffer) abort
49-
let l:project_roots = ['package.json', 'vite.config.js', '.git', bufname(a:buffer)]
12+
let l:project_roots = [
13+
\ 'package.json',
14+
\ 'vite.config.js',
15+
\ 'vite.config.mjs',
16+
\ 'vite.config.cjs',
17+
\ 'vite.config.ts',
18+
\ '.git',
19+
\ bufname(a:buffer)
20+
\]
5021

5122
for l:project_root in l:project_roots
5223
let l:nearest_filepath = ale#path#FindNearestFile(a:buffer, l:project_root)
@@ -60,11 +31,19 @@ function! ale_linters#vue#volar#GetProjectRoot(buffer) abort
6031
endfunction
6132

6233
function! ale_linters#vue#volar#GetInitializationOptions(buffer) abort
63-
let l:tsserver_path = ale#path#FindNearestExecutable(a:buffer, [
64-
\ 'node_modules/typescript/lib/tsserverlibrary.js'
65-
\ ])
34+
let l:tsserver_path = ale#path#FindNearestDirectory(a:buffer, 'node_modules/typescript/lib')
35+
36+
if l:tsserver_path is# ''
37+
" no-custom-checks
38+
echohl WarningMsg
39+
" no-custom-checks
40+
echom '[volar] Must have typescript installed in project, please install via `npm install -D typescript`.'
41+
" no-custom-checks
42+
echohl None
43+
endif
44+
6645
let l:init_options = ale#Var(a:buffer, 'vue_volar_init_options')
67-
let l:init_options.typescript.serverPath = l:tsserver_path
46+
let l:init_options.typescript.tsdk = l:tsserver_path
6847

6948
return l:init_options
7049
endfunction

doc/ale-vue.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ g:ale_vue_volar_executable *g:ale_vue_volar_executable*
5050
g:ale_vue_volar_use_global *g:ale_vue_volar_use_global*
5151
*b:ale_vue_volar_use_global*
5252
Type: |Number|
53-
Default: `get(g:, 'ale_use_global_executables', 0)`
53+
Default: `1`
5454

5555
See |ale-integrations-local-executables|
5656

5757

5858
g:vue_volar_init_options *g:ale_vue_volar_init_options*
5959
*b:ale_vue_volar_init_options*
6060
Type: |Dictionary|
61-
Default: `{ ... }`
61+
Default: `{ 'typescript': 'tsdk': '' }`
6262

6363
Default is too long to show here, take a look at it over
6464
`ale_linters/vue/volar.vim`

test/linter/test_volar.vader

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Execute(Assert proper tsserverlibrary for Volar LSP):
2121
call ale#test#SetFilename('../test-files/volar/src/App.vue')
2222

2323
let g:init_opts = ale_linters#vue#volar#GetInitializationOptions(bufnr(''))
24-
let g:tsserver_path = init_opts.typescript.serverPath
25-
let g:actual_path = ale#path#Simplify(g:dir . '/../test-files/volar/node_modules/typescript/lib/tsserverlibrary.js')
24+
let g:tsserver_path = init_opts.typescript.tsdk
25+
let g:actual_path = ale#path#Simplify(g:dir . '/../test-files/volar/node_modules/typescript/lib/')
2626

2727
AssertEqual g:tsserver_path, g:actual_path

0 commit comments

Comments
 (0)