diff options
author | w0rp <w0rp@users.noreply.github.com> | 2019-01-26 19:40:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-26 19:40:45 +0000 |
commit | 452460b8cdff8b2809d0226b60183dbda5ae605d (patch) | |
tree | b9e0b78d7f03bcb0d6380c6bb61ba6de96f19d94 /autoload | |
parent | cf14d0aa53e9b51f4987dbfd3913183901bb2805 (diff) | |
parent | 6fc016ad052725e0d6a474e80f817cb1853e98e2 (diff) | |
download | ale-452460b8cdff8b2809d0226b60183dbda5ae605d.zip |
Merge pull request #2241 from bk2204/lsp-detect-hook
Add a hook to detect LSP project root
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/assert.vim | 13 | ||||
-rw-r--r-- | autoload/ale/debugging.vim | 1 | ||||
-rw-r--r-- | autoload/ale/lsp_linter.vim | 35 |
3 files changed, 48 insertions, 1 deletions
diff --git a/autoload/ale/assert.vim b/autoload/ale/assert.vim index ed08ed09..7139f05c 100644 --- a/autoload/ale/assert.vim +++ b/autoload/ale/assert.vim @@ -109,6 +109,14 @@ function! ale#assert#LSPProject(expected_root) abort AssertEqual a:expected_root, l:root endfunction +function! ale#assert#LSPProjectFull(expected_root) abort + let l:buffer = bufnr('') + let l:linter = s:GetLinter() + let l:root = ale#lsp_linter#FindProjectRoot(l:buffer, l:linter) + + AssertEqual a:expected_root, l:root +endfunction + function! ale#assert#LSPAddress(expected_address) abort let l:buffer = bufnr('') let l:linter = s:GetLinter() @@ -158,6 +166,7 @@ function! ale#assert#SetUpLinterTest(filetype, name) abort command! -nargs=+ AssertLSPConfig :call ale#assert#LSPConfig(<args>) command! -nargs=+ AssertLSPLanguage :call ale#assert#LSPLanguage(<args>) command! -nargs=+ AssertLSPProject :call ale#assert#LSPProject(<args>) + command! -nargs=+ AssertLSPProjectFull :call ale#assert#LSPProjectFull(<args>) command! -nargs=+ AssertLSPAddress :call ale#assert#LSPAddress(<args>) endfunction @@ -193,6 +202,10 @@ function! ale#assert#TearDownLinterTest() abort delcommand AssertLSPProject endif + if exists(':AssertLSPProjectFull') + delcommand AssertLSPProjectFull + endif + if exists(':AssertLSPAddress') delcommand AssertLSPAddress endif diff --git a/autoload/ale/debugging.vim b/autoload/ale/debugging.vim index 3aed38fe..e4bf5e7e 100644 --- a/autoload/ale/debugging.vim +++ b/autoload/ale/debugging.vim @@ -31,6 +31,7 @@ let s:global_variable_list = [ \ 'ale_list_vertical', \ 'ale_list_window_size', \ 'ale_loclist_msg_format', +\ 'ale_lsp_root', \ 'ale_max_buffer_history_size', \ 'ale_max_signs', \ 'ale_maximum_file_size', diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim index 306a2cf1..b029d833 100644 --- a/autoload/ale/lsp_linter.vim +++ b/autoload/ale/lsp_linter.vim @@ -152,12 +152,45 @@ function! ale#lsp_linter#GetConfig(buffer, linter) abort return l:config endfunction +function! ale#lsp_linter#FindProjectRoot(buffer, linter) abort + let l:buffer_ale_root = getbufvar(a:buffer, 'ale_lsp_root', {}) + + if type(l:buffer_ale_root) is v:t_string + return l:buffer_ale_root + endif + + " Try to get a buffer-local setting for the root + if has_key(l:buffer_ale_root, a:linter.name) + let l:Root = l:buffer_ale_root[a:linter.name] + + if type(l:Root) is v:t_func + return l:Root(a:buffer) + else + return l:Root + endif + endif + + " Try to get a global setting for the root + if has_key(g:ale_lsp_root, a:linter.name) + let l:Root = g:ale_lsp_root[a:linter.name] + + if type(l:Root) is v:t_func + return l:Root(a:buffer) + else + return l:Root + endif + endif + + " Fall back to the linter-specific configuration + return ale#util#GetFunction(a:linter.project_root_callback)(a:buffer) +endfunction + " Given a buffer, an LSP linter, start up an LSP linter and get ready to " receive messages for the document. function! ale#lsp_linter#StartLSP(buffer, linter) abort let l:command = '' let l:address = '' - let l:root = ale#util#GetFunction(a:linter.project_root_callback)(a:buffer) + let l:root = ale#lsp_linter#FindProjectRoot(a:buffer, a:linter) if empty(l:root) && a:linter.lsp isnot# 'tsserver' " If there's no project root, then we can't check files with LSP, |