summaryrefslogtreecommitdiff
path: root/ale_linters/vim/vimls.vim
diff options
context:
space:
mode:
authorHoracio Sanson <hsanson@gmail.com>2020-04-21 13:36:57 +0900
committerGitHub <noreply@github.com>2020-04-21 13:36:57 +0900
commit36e5337e30095afb10d02ef2ae362c8d6055e70d (patch)
tree125bb0bc40f276f7be6e0497a61266d5c2ed04a0 /ale_linters/vim/vimls.vim
parentd2934ba017e01529f4b83b2995a62f884d30734f (diff)
parent60d683da3bfe3440cac4faa5072ecba4a1d2af98 (diff)
downloadale-36e5337e30095afb10d02ef2ae362c8d6055e70d.zip
Merge pull request #3117 from zoonfafer/vim-vimls
Add vim-language-server linter support
Diffstat (limited to 'ale_linters/vim/vimls.vim')
-rw-r--r--ale_linters/vim/vimls.vim61
1 files changed, 61 insertions, 0 deletions
diff --git a/ale_linters/vim/vimls.vim b/ale_linters/vim/vimls.vim
new file mode 100644
index 00000000..26014d66
--- /dev/null
+++ b/ale_linters/vim/vimls.vim
@@ -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'),
+\})