Merge pull request #3117 from zoonfafer/vim-vimls

Add vim-language-server linter support
This commit is contained in:
Horacio Sanson 2020-04-21 13:36:57 +09:00 committed by GitHub
commit 36e5337e30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 195 additions and 0 deletions

61
ale_linters/vim/vimls.vim Normal file
View file

@ -0,0 +1,61 @@
" Author: Jeffrey Lau - https://github.com/zoonfafer
" Description: Vim Language Server integration for ALE
call ale#Set('vim_vimls_executable', 'vim-language-server')
call ale#Set('vim_vimls_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('vim_vimls_config', {})
function! ale_linters#vim#vimls#GetProjectRoot(buffer) abort
let l:trigger_file_candidates = [
\ '.vimrc',
\ 'init.vim',
\]
for l:candidate in l:trigger_file_candidates
let l:trigger_file = fnamemodify(bufname(a:buffer), ':t')
if l:trigger_file is# l:candidate
return fnamemodify(
\ bufname(a:buffer),
\ ':h',
\)
endif
endfor
let l:trigger_dir_candidates = [
\ 'autoload',
\ 'plugin',
\ '.git',
\]
let l:path_upwards = ale#path#Upwards(fnamemodify(bufname(a:buffer), ':p:h'))
for l:path in l:path_upwards
for l:candidate in l:trigger_dir_candidates
let l:trigger_dir = ale#path#Simplify(
\ l:path . '/' . l:candidate,
\)
if isdirectory(l:trigger_dir)
return fnamemodify(
\ l:trigger_dir,
\ ':p:h:h',
\)
endif
endfor
endfor
return ''
endfunction
call ale#linter#Define('vim', {
\ 'name': 'vimls',
\ 'lsp': 'stdio',
\ 'lsp_config': {b -> ale#Var(b, 'vim_vimls_config')},
\ 'executable': {b -> ale#node#FindExecutable(b, 'vim_vimls', [
\ 'node_modules/.bin/vim-language-server',
\ ])},
\ 'command': '%e --stdio',
\ 'language': 'vim',
\ 'project_root': function('ale_linters#vim#vimls#GetProjectRoot'),
\})

View file

@ -485,6 +485,7 @@ Notes:
* `vcom` * `vcom`
* `xvhdl` * `xvhdl`
* Vim * Vim
* `vimls`
* `vint` * `vint`
* Vim help^ * Vim help^
* `alex`!! * `alex`!!

View file

@ -2,6 +2,61 @@
ALE Vim Integration *ale-vim-options* ALE Vim Integration *ale-vim-options*
===============================================================================
vimls *ale-vim-vimls*
The `vim-language-server` is the engine that powers VimL editor support
using the Language Server Protocol. See the installation instructions:
https://github.com/iamcco/vim-language-server#install
g:ale_vim_vimls_executable *g:ale_vim_vimls_executable*
*b:ale_vim_vimls_executable*
Type: |String|
Default: `'vim-language-server'`
This option can be set to change the executable path for vimls.
g:ale_vim_vimls_config *g:ale_vim_vimls_config*
*b:ale_vim_vimls_config*
Type: |Dictionary|
Default: `{}`
Dictionary containing configuration settings that will be passed to the
language server. For example: >
{
\ 'vim': {
\ 'iskeyword': '@,48-57,_,192-255,-#',
\ 'vimruntime': '',
\ 'runtimepath': '',
\ 'diagnostic': {
\ 'enable': v:true
\ },
\ 'indexes': {
\ 'runtimepath': v:true,
\ 'gap': 100,
\ 'count': 3,
\ 'projectRootPatterns' : ['.git', 'autoload', 'plugin']
\ },
\ 'suggest': {
\ 'fromVimruntime': v:true,
\ 'fromRuntimepath': v:false
\ },
\ }
\}
<
Consult the vim-language-server documentation for more information about
settings.
g:ale_vim_vimls_use_global *g:ale_vim_vimls_use_global*
*b:ale_vim_vimls_use_global*
Type: |Number|
Default: `get(g:, 'ale_use_global_executables', 0)`
See |ale-integrations-local-executables|
=============================================================================== ===============================================================================
vint *ale-vim-vint* vint *ale-vim-vint*

View file

@ -2655,6 +2655,7 @@ documented in additional help files.
vcom..................................|ale-vhdl-vcom| vcom..................................|ale-vhdl-vcom|
xvhdl.................................|ale-vhdl-xvhdl| xvhdl.................................|ale-vhdl-xvhdl|
vim.....................................|ale-vim-options| vim.....................................|ale-vim-options|
vimls.................................|ale-vim-vimls|
vint..................................|ale-vim-vint| vint..................................|ale-vim-vint|
vim help................................|ale-vim-help-options| vim help................................|ale-vim-help-options|
write-good............................|ale-vim-help-write-good| write-good............................|ale-vim-help-write-good|

View file

@ -494,6 +494,7 @@ formatting.
* [vcom](https://www.mentor.com/products/fv/questa/) * [vcom](https://www.mentor.com/products/fv/questa/)
* [xvhdl](https://www.xilinx.com/products/design-tools/vivado.html) * [xvhdl](https://www.xilinx.com/products/design-tools/vivado.html)
* Vim * Vim
* [vimls](https://github.com/iamcco/vim-language-server)
* [vint](https://github.com/Kuniwak/vint) * [vint](https://github.com/Kuniwak/vint)
* Vim help * Vim help
* [alex](https://github.com/wooorm/alex) :warning: :floppy_disk: * [alex](https://github.com/wooorm/alex) :warning: :floppy_disk:

View file

@ -0,0 +1,76 @@
" Author: Jeffrey Lau https://github.com/zoonfafer
" Description: Tests for the Vim vimls linter
Before:
call ale#assert#SetUpLinterTest('vim', 'vimls')
After:
if isdirectory(g:dir . '/.git')
call delete(g:dir . '/.git', 'd')
endif
call ale#assert#TearDownLinterTest()
Execute(should set correct defaults):
AssertLinter 'vim-language-server', ale#Escape('vim-language-server') . ' --stdio'
Execute(should set correct LSP values):
call ale#test#SetFilename('vim_fixtures/path_with_autoload/test.vim')
AssertLSPLanguage 'vim'
AssertLSPOptions {}
AssertLSPConfig {}
AssertLSPProject ale#path#Simplify(g:dir . '/vim_fixtures/path_with_autoload')
Execute(should set correct project for .git/):
let b:parent_dir = ale#path#Simplify(g:dir . '/..')
let b:git_dir = b:parent_dir . '/.git'
call ale#test#SetFilename('vim_fixtures/test.vim')
if !isdirectory(b:git_dir)
call mkdir(b:git_dir)
endif
AssertLSPProject ale#path#Simplify(b:parent_dir)
call delete(b:git_dir, 'd')
unlet! b:git_dir
Execute(should set correct project for plugin/):
call ale#test#SetFilename('vim_fixtures/path_with_plugin/test.vim')
AssertLSPProject ale#path#Simplify(g:dir . '/vim_fixtures/path_with_plugin')
Execute(should accept configuration settings):
AssertLSPConfig {}
let b:ale_vim_vimls_config = {'vim': {'foobar': v:true}}
AssertLSPConfig {'vim': {'foobar': v:true}}
Execute(should set correct project for .vimrc):
call ale#test#SetFilename('vim_fixtures/path_with_vimrc/.vimrc')
AssertLSPProject ale#path#Simplify(g:dir . '/vim_fixtures/path_with_vimrc')
Execute(should set correct project for init.vim):
call ale#test#SetFilename('vim_fixtures/path_with_initvim/init.vim')
AssertLSPProject ale#path#Simplify(g:dir . '/vim_fixtures/path_with_initvim')
Execute(should use the local executable when available):
call ale#test#SetFilename('vim_fixtures/file.vim')
AssertLinter ale#path#Simplify(g:dir . '/vim_fixtures/node_modules/.bin/vim-language-server'),
\ ale#Escape(ale#path#Simplify(g:dir . '/vim_fixtures/node_modules/.bin/vim-language-server')) . ' --stdio'
Execute(should let the global executable to be used):
let g:ale_vim_vimls_use_global = 1
call ale#test#SetFilename('vim_fixtures/file.vim')
AssertLinter 'vim-language-server',
\ ale#Escape('vim-language-server') . ' --stdio'
Execute(should let the executable to be configured):
let g:ale_vim_vimls_executable = 'foobar'
AssertLinter 'foobar', ale#Escape('foobar') . ' --stdio'