6fc016ad05
Currently, we detect the linter root based on a variety of techniques. However, these techniques are not foolproof. For example, clangd works fine for many things without a compile_commands.json file, and Go projects may be built outside of the GOPATH to take advantage of Go 1.11's automatic module support. Add global and buffer-specific variables to allow the user to specify the root, either as a string or a funcref. Make the funcrefs accept the buffer number as an argument to make sure that they can function easily in an asynchronous environment. We define the global variable in the main plugin, since the LSP linter code is not loaded unless required, and we want the variable to be able to be read correctly by :ALEInfo regardless.
63 lines
1.9 KiB
Text
63 lines
1.9 KiB
Text
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 ''
|