Add volar support for vue (#3992)

* feat-draft: inital volar setup

* feat(volar): add documentation

* feat(volar): include default init opts

* feat(volar): add initial tests

* fix(volar): add possible project roots

* fix(volar): tests - use empty files
This commit is contained in:
Arnold Chand 2021-11-21 07:02:09 -04:00 committed by GitHub
parent 072750137f
commit de67f4743d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 141 additions and 0 deletions

80
ale_linters/vue/volar.vim Normal file
View File

@ -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'),
\})

View File

@ -620,6 +620,7 @@ Notes:
* `cspell`
* `prettier`
* `vls`
* `volar`
* XHTML
* `alex`
* `cspell`

View File

@ -33,5 +33,36 @@ g:ale_vue_vls_use_global *g:ale_vue_vls_use_global*
See |ale-integrations-local-executables|
===============================================================================
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:

View File

@ -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|

View File

@ -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)

View File

@ -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

0
test/test-files/volar/node_modules/.bin/volar-server generated vendored Executable file
View File

View File

View File

View File