mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-25 11:07:27 +08:00
Merge pull request #2241 from bk2204/lsp-detect-hook
Add a hook to detect LSP project root
This commit is contained in:
@@ -17,6 +17,7 @@ Execute(Command formatting should be applied correctly for LSP linters):
|
||||
call ale#lsp_linter#StartLSP(
|
||||
\ bufnr(''),
|
||||
\ {
|
||||
\ 'name': 'linter',
|
||||
\ 'language_callback': {-> 'x'},
|
||||
\ 'project_root_callback': {-> '/foo/bar'},
|
||||
\ 'lsp': 'stdio',
|
||||
|
||||
63
test/lsp/test_lsp_root_detection.vader
Normal file
63
test/lsp/test_lsp_root_detection.vader
Normal file
@@ -0,0 +1,63 @@
|
||||
Before:
|
||||
call ale#assert#SetUpLinterTest('c', 'clangd')
|
||||
|
||||
function! Hook1(buffer)
|
||||
return 'abc123'
|
||||
endfunction
|
||||
|
||||
After:
|
||||
let g:ale_lsp_root = {}
|
||||
unlet! b:ale_lsp_root
|
||||
delfunction Hook1
|
||||
|
||||
call ale#assert#TearDownLinterTest()
|
||||
|
||||
Execute(The buffer-specific variable can be a string):
|
||||
let b:ale_lsp_root = '/some/path'
|
||||
call ale#test#SetFilename('other-file.c')
|
||||
|
||||
AssertLSPProjectFull '/some/path'
|
||||
|
||||
Execute(The buffer-specific variable can be a dictionary):
|
||||
let b:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
|
||||
call ale#test#SetFilename('other-file.c')
|
||||
|
||||
AssertLSPProjectFull '/some/path'
|
||||
|
||||
Execute(The buffer-specific variable can have funcrefs):
|
||||
let b:ale_lsp_root = {'clangd': function('Hook1'), 'golangserver': '/path'}
|
||||
call ale#test#SetFilename('other-file.c')
|
||||
|
||||
AssertLSPProjectFull 'abc123'
|
||||
|
||||
Execute(The global variable can be a dictionary):
|
||||
let g:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
|
||||
call ale#test#SetFilename('other-file.c')
|
||||
|
||||
AssertLSPProjectFull '/some/path'
|
||||
|
||||
Execute(The global variable can have funcrefs):
|
||||
let g:ale_lsp_root = {'clangd': function('Hook1'), 'golangserver': '/path'}
|
||||
call ale#test#SetFilename('other-file.c')
|
||||
|
||||
AssertLSPProjectFull 'abc123'
|
||||
|
||||
Execute(The buffer-specific variable overrides the global variable):
|
||||
let b:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
|
||||
let g:ale_lsp_root = {'clangd': '/not/this/path', 'golangserver': '/elsewhere'}
|
||||
call ale#test#SetFilename('other-file.c')
|
||||
|
||||
AssertLSPProjectFull '/some/path'
|
||||
|
||||
Execute(The global variable is queried if the buffer-specific has no value):
|
||||
let b:ale_lsp_root = {'golangserver': '/other/path'}
|
||||
let g:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/elsewhere'}
|
||||
call ale#test#SetFilename('other-file.c')
|
||||
|
||||
AssertLSPProjectFull '/some/path'
|
||||
|
||||
|
||||
Execute(The default hook value is acceptable):
|
||||
call ale#test#SetFilename('other-file.c')
|
||||
|
||||
AssertLSPProjectFull ''
|
||||
@@ -97,6 +97,7 @@ Before:
|
||||
\ 'let g:ale_list_vertical = 0',
|
||||
\ 'let g:ale_list_window_size = 10',
|
||||
\ 'let g:ale_loclist_msg_format = ''%code: %%s''',
|
||||
\ 'let g:ale_lsp_root = {}',
|
||||
\ 'let g:ale_max_buffer_history_size = 20',
|
||||
\ 'let g:ale_max_signs = -1',
|
||||
\ 'let g:ale_maximum_file_size = 0',
|
||||
|
||||
Reference in New Issue
Block a user