diff options
-rw-r--r-- | ale_linters/vue/volar.vim | 80 | ||||
-rw-r--r-- | doc/ale-supported-languages-and-tools.txt | 1 | ||||
-rw-r--r-- | doc/ale-vue.txt | 31 | ||||
-rw-r--r-- | doc/ale.txt | 1 | ||||
-rw-r--r-- | supported-tools.md | 1 | ||||
-rw-r--r-- | test/linter/test_volar.vader | 27 | ||||
-rwxr-xr-x | test/test-files/volar/node_modules/.bin/volar-server | 0 | ||||
-rw-r--r-- | test/test-files/volar/node_modules/typescript/lib/tsserverlibrary.js | 0 | ||||
-rw-r--r-- | test/test-files/volar/package.json | 0 | ||||
-rw-r--r-- | test/test-files/volar/src/App.vue | 0 |
10 files changed, 141 insertions, 0 deletions
diff --git a/ale_linters/vue/volar.vim b/ale_linters/vue/volar.vim new file mode 100644 index 00000000..360b1aa5 --- /dev/null +++ b/ale_linters/vue/volar.vim @@ -0,0 +1,80 @@ +" Author: Arnold Chand <creativenull@outlook.com> +" Description: Volar Language Server integration for ALE adopted from +" nvim-lspconfig and volar/packages/shared/src/types.ts + +call ale#Set('vue_volar_executable', 'volar-server') +call ale#Set('vue_volar_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('vue_volar_init_options', { +\ 'documentFeatures': { +\ 'documentColor': v:false, +\ 'documentFormatting': { +\ 'defaultPrintWidth': 100, +\ }, +\ 'documentSymbol': v:true, +\ 'foldingRange': v:true, +\ 'linkedEditingRange': v:true, +\ 'selectionRange': v:true, +\ }, +\ 'languageFeatures': { +\ 'callHierarchy': v:true, +\ 'codeAction': v:true, +\ 'codeLens': v:true, +\ 'completion': { +\ 'defaultAttrNameCase': 'kebabCase', +\ 'defaultTagNameCase': 'both', +\ 'getDocumentNameCaseRequest': v:false, +\ 'getDocumentSelectionRequest': v:false, +\ }, +\ 'definition': v:true, +\ 'diagnostics': v:true, +\ 'documentHighlight': v:true, +\ 'documentLink': v:true, +\ 'hover': v:true, +\ 'references': v:true, +\ 'rename': v:true, +\ 'renameFileRefactoring': v:true, +\ 'schemaRequestService': v:true, +\ 'semanticTokens': v:false, +\ 'signatureHelp': v:true, +\ 'typeDefinition': v:true, +\ 'workspaceSymbol': v:false, +\ }, +\ 'typescript': { +\ 'serverPath': '', +\ 'localizedPath': v:null, +\ }, +\}) + +function! ale_linters#vue#volar#GetProjectRoot(buffer) abort + let l:project_roots = ['package.json', 'vite.config.js', '.git', bufname(a:buffer)] + + for l:project_root in l:project_roots + let l:nearest_filepath = ale#path#FindNearestFile(a:buffer, l:project_root) + + if !empty(l:nearest_filepath) + return fnamemodify(l:nearest_filepath, ':h') + endif + endfor + + return '' +endfunction + +function! ale_linters#vue#volar#GetInitializationOptions(buffer) abort + let l:tsserver_path = ale#path#FindNearestExecutable(a:buffer, [ + \ 'node_modules/typescript/lib/tsserverlibrary.js' + \ ]) + let l:init_options = ale#Var(a:buffer, 'vue_volar_init_options') + let l:init_options.typescript.serverPath = l:tsserver_path + + return l:init_options +endfunction + +call ale#linter#Define('vue', { +\ 'name': 'volar', +\ 'language': 'vue', +\ 'lsp': 'stdio', +\ 'executable': {b -> ale#path#FindExecutable(b, 'vue_volar', ['node_modules/.bin/volar-server'])}, +\ 'command': '%e --stdio', +\ 'project_root': function('ale_linters#vue#volar#GetProjectRoot'), +\ 'initialization_options': function('ale_linters#vue#volar#GetInitializationOptions'), +\}) diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 3324903f..df9b5dd6 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -620,6 +620,7 @@ Notes: * `cspell` * `prettier` * `vls` + * `volar` * XHTML * `alex` * `cspell` diff --git a/doc/ale-vue.txt b/doc/ale-vue.txt index 5bf1e28d..98ac5808 100644 --- a/doc/ale-vue.txt +++ b/doc/ale-vue.txt @@ -34,4 +34,35 @@ g:ale_vue_vls_use_global *g:ale_vue_vls_use_global* =============================================================================== +volar *ale-vue-volar* + + It is required to have typescript installed in your project as your dev + dependency: `npm i -D typescript` + +g:ale_vue_volar_executable *g:ale_vue_volar_executable* + *b:ale_vue_volar_executable* + Type: |String| + Default: `'volar-server'` + + See |ale-integrations-local-executables| + + +g:ale_vue_volar_use_global *g:ale_vue_volar_use_global* + *b:ale_vue_volar_use_global* + Type: |Number| + Default: `get(g:, 'ale_use_global_executables', 0)` + + See |ale-integrations-local-executables| + + +g:vue_volar_init_options *g:ale_vue_volar_init_options* + *b:ale_vue_volar_init_options* + Type: |Dictionary| + Default: `{ ... }` + + Default is too long to show here, take a look at it over + `ale_linters/vue/volar.vim` + + +=============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 178ce314..0ac01305 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -3168,6 +3168,7 @@ documented in additional help files. cspell................................|ale-vue-cspell| prettier..............................|ale-vue-prettier| vls...................................|ale-vue-vls| + volar.................................|ale-vue-volar| xhtml...................................|ale-xhtml-options| cspell................................|ale-xhtml-cspell| write-good............................|ale-xhtml-write-good| diff --git a/supported-tools.md b/supported-tools.md index 23d3dc72..96063205 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -629,6 +629,7 @@ formatting. * [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell) * [prettier](https://github.com/prettier/prettier) * [vls](https://github.com/vuejs/vetur/tree/master/server) + * [volar](https://github.com/johnsoncodehk/volar) * XHTML * [alex](https://github.com/get-alex/alex) * [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell) diff --git a/test/linter/test_volar.vader b/test/linter/test_volar.vader new file mode 100644 index 00000000..bef094be --- /dev/null +++ b/test/linter/test_volar.vader @@ -0,0 +1,27 @@ +Before: + call ale#assert#SetUpLinterTest('vue', 'volar') + + let g:tsserver_path = '' + let g:actual_path = '' + let g:init_opts = {} + +After: + call ale#assert#TearDownLinterTest() + + unlet g:tsserver_path + unlet g:actual_path + unlet g:init_opts + +Execute(Assert Volar LSP for Vue Project): + call ale#test#SetFilename('../test-files/volar/src/App.vue') + + AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/volar') + +Execute(Assert proper tsserverlibrary for Volar LSP): + call ale#test#SetFilename('../test-files/volar/src/App.vue') + + let g:init_opts = ale_linters#vue#volar#GetInitializationOptions(bufnr('')) + let g:tsserver_path = init_opts.typescript.serverPath + let g:actual_path = ale#path#Simplify(g:dir . '/../test-files/volar/node_modules/typescript/lib/tsserverlibrary.js') + + AssertEqual g:tsserver_path, g:actual_path diff --git a/test/test-files/volar/node_modules/.bin/volar-server b/test/test-files/volar/node_modules/.bin/volar-server new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/test/test-files/volar/node_modules/.bin/volar-server diff --git a/test/test-files/volar/node_modules/typescript/lib/tsserverlibrary.js b/test/test-files/volar/node_modules/typescript/lib/tsserverlibrary.js new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/test-files/volar/node_modules/typescript/lib/tsserverlibrary.js diff --git a/test/test-files/volar/package.json b/test/test-files/volar/package.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/test-files/volar/package.json diff --git a/test/test-files/volar/src/App.vue b/test/test-files/volar/src/App.vue new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/test-files/volar/src/App.vue |