mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-30 14:45:29 +08:00
Merge pull request #2241 from bk2204/lsp-detect-hook
Add a hook to detect LSP project root
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user