#3599 - Use ale_root instead of ale_lsp_root

The `ale_lsp_root` setting is now deprecated, and `ale_root` should be
used instead. The setting will be used for both setting the root easily
for LSP linters, and for running other linters over whole projects.
This commit is contained in:
w0rp 2021-03-01 20:51:29 +00:00
parent 9fe7b1fe6a
commit 680ba68d81
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
8 changed files with 91 additions and 52 deletions

View File

@ -265,11 +265,11 @@ function! ale#assert#SetUpLinterTest(filetype, name) abort
call ale#linter#Reset()
call ale#linter#PreventLoading(a:filetype)
Save g:ale_lsp_root
let g:ale_lsp_root = {}
Save g:ale_root
let g:ale_root = {}
Save b:ale_lsp_root
unlet! b:ale_lsp_root
Save b:ale_root
unlet! b:ale_root
call ale#assert#ResetVariables(a:filetype, a:name)

View File

@ -33,13 +33,13 @@ 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',
\ 'ale_open_list',
\ 'ale_pattern_options',
\ 'ale_pattern_options_enabled',
\ 'ale_root',
\ 'ale_set_balloons',
\ 'ale_set_highlights',
\ 'ale_set_loclist',

View File

@ -201,7 +201,11 @@ function! ale#lsp_linter#GetConfig(buffer, linter) abort
endfunction
function! ale#lsp_linter#FindProjectRoot(buffer, linter) abort
let l:buffer_ale_root = getbufvar(a:buffer, 'ale_lsp_root', {})
let l:buffer_ale_root = getbufvar(
\ a:buffer,
\ 'ale_root',
\ getbufvar(a:buffer, 'ale_lsp_root', {})
\)
if type(l:buffer_ale_root) is v:t_string
return l:buffer_ale_root
@ -218,9 +222,15 @@ function! ale#lsp_linter#FindProjectRoot(buffer, linter) abort
endif
endif
let l:global_root = g:ale_root
if empty(g:ale_root) && exists('g:ale_lsp_root')
let l:global_root = g:ale_lsp_root
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 has_key(l:global_root, a:linter.name)
let l:Root = l:global_root[a:linter.name]
if type(l:Root) is v:t_func
return l:Root(a:buffer)

View File

@ -1724,24 +1724,6 @@ g:ale_lsp_suggestions *g:ale_lsp_suggestions*
addition to warnings and errors.
g:ale_lsp_root *g:ale_lsp_root*
*b:ale_lsp_root*
Type: |Dictionary| or |String|
Default: {}
This option is used to determine the project root for the LSP linter. If the
value is a |Dictionary|, it maps a linter to either a string containing the
project root or a |Funcref| to call to look up the root. The funcref is
provided the buffer number as its argument.
The buffer-specific variable may additionally be a string containing the
project root itself.
If neither variable yields a result, a linter-specific function is invoked to
detect a project root. If this, too, yields no result, the linter is disabled.
g:ale_max_buffer_history_size *g:ale_max_buffer_history_size*
Type: |Number|
@ -1886,6 +1868,25 @@ g:ale_rename_tsserver_find_in_strings *g:ale_rename_tsserver_find_in_strings*
`1`.
g:ale_root *g:ale_root*
*b:ale_root*
Type: |Dictionary| or |String|
Default: {}
This option is used to determine the project root for a linter. If the value
is a |Dictionary|, it maps a linter to either a |String| containing the
project root or a |Funcref| to call to look up the root. The |Funcref| is
provided the buffer number as its argument.
The buffer-specific variable may additionally be a string containing the
project root itself.
If neither variable yields a result, a linter-specific function is invoked to
detect a project root. If this, too, yields no result, and the linter is an
LSP linter, it will not run.
g:ale_set_balloons *g:ale_set_balloons*
*b:ale_set_balloons*

View File

@ -87,9 +87,6 @@ let g:ale_lint_on_save = get(g:, 'ale_lint_on_save', 1)
" This flag can be set to 1 to enable linting when the filetype is changed.
let g:ale_lint_on_filetype_changed = get(g:, 'ale_lint_on_filetype_changed', 1)
" This Dictionary configures the default LSP roots for various linters.
let g:ale_lsp_root = get(g:, 'ale_lsp_root', {})
" If set to 1, hints and suggestion from LSP servers and tsserver will be shown.
let g:ale_lsp_suggestions = get(g:, 'ale_lsp_suggestions', 0)
@ -104,6 +101,9 @@ let g:ale_enabled = get(g:, 'ale_enabled', 1)
" mapping filename paths from one system to another.
let g:ale_filename_mappings = get(g:, 'ale_filename_mappings', {})
" This Dictionary configures the default project roots for various linters.
let g:ale_root = get(g:, 'ale_root', {})
" These flags dictates if ale uses the quickfix or the loclist (loclist is the
" default, quickfix overrides loclist).
let g:ale_set_loclist = get(g:, 'ale_set_loclist', 1)

View File

@ -1,4 +1,12 @@
Before:
Save g:ale_lsp_root
Save g:ale_root
Save b:ale_lsp_root
Save b:ale_root
unlet! g:ale_lsp_root
let g:ale_root = {}
call ale#assert#SetUpLinterTest('c', 'clangd')
function! Hook1(buffer)
@ -6,52 +14,72 @@ Before:
endfunction
After:
let g:ale_lsp_root = {}
unlet! b:ale_lsp_root
Restore
delfunction Hook1
call ale#assert#TearDownLinterTest()
Execute(The buffer-specific variable can be a string):
let b:ale_lsp_root = '/some/path'
let b:ale_root = '/some/path'
call ale#test#SetFilename('other-file.c')
AssertLSPProject '/some/path'
Execute(The buffer-specific variable can be a dictionary):
let b:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
let b:ale_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
call ale#test#SetFilename('other-file.c')
AssertLSPProject '/some/path'
Execute(The buffer-specific variable can have funcrefs):
let b:ale_lsp_root = {'clangd': function('Hook1'), 'golangserver': '/path'}
let b:ale_root = {'clangd': function('Hook1'), 'golangserver': '/path'}
call ale#test#SetFilename('other-file.c')
AssertLSPProject 'abc123'
Execute(The buffer-specific variable can be the old ale_lsp_root setting):
let b:ale_lsp_root = '/some/path'
call ale#test#SetFilename('other-file.c')
AssertLSPProject '/some/path'
Execute(The global variable can be a dictionary):
let g:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
let g:ale_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
call ale#test#SetFilename('other-file.c')
AssertLSPProject '/some/path'
Execute(The global variable can have funcrefs):
let g:ale_lsp_root = {'clangd': function('Hook1'), 'golangserver': '/path'}
let g:ale_root = {'clangd': function('Hook1'), 'golangserver': '/path'}
call ale#test#SetFilename('other-file.c')
AssertLSPProject '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'}
let b:ale_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
let g:ale_root = {'clangd': '/not/this/path', 'golangserver': '/elsewhere'}
call ale#test#SetFilename('other-file.c')
AssertLSPProject '/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'}
let b:ale_root = {'golangserver': '/other/path'}
let g:ale_root = {'clangd': '/some/path', 'golangserver': '/elsewhere'}
call ale#test#SetFilename('other-file.c')
AssertLSPProject '/some/path'
Execute(The global variable can be the old ale_lsp_root setting):
let g:ale_root = {}
let g:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
call ale#test#SetFilename('other-file.c')
AssertLSPProject '/some/path'
Execute(A non-empty ale_root setting should replace the old ale_lsp_root):
let g:ale_root = {'clangd': '/some/path', 'golangserver': '/other/path'}
let g:ale_lsp_root = {'clangd': '/xxx', 'golangserver': '/xxx'}
call ale#test#SetFilename('other-file.c')
AssertLSPProject '/some/path'

View File

@ -30,13 +30,13 @@ Before:
Save g:ale_list_window_size
Save g:ale_loclist_msg_format
Save g:ale_lsp_error_messages
Save g:ale_lsp_root
Save g:ale_max_buffer_history_size
Save g:ale_max_signs
Save g:ale_maximum_file_size
Save g:ale_open_list
Save g:ale_pattern_options
Save g:ale_pattern_options_enabled
Save g:ale_root
Save g:ale_set_balloons
Save g:ale_set_highlights
Save g:ale_set_loclist
@ -88,13 +88,13 @@ Before:
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_lsp_error_messages = {}
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
let g:ale_open_list = 0
let g:ale_pattern_options = {}
let g:ale_pattern_options_enabled = 0
let g:ale_root = {}
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
@ -167,13 +167,13 @@ 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',
\ 'let g:ale_open_list = 0',
\ 'let g:ale_pattern_options = {}',
\ 'let g:ale_pattern_options_enabled = 0',
\ 'let g:ale_root = {}',
\ 'let g:ale_set_balloons = 0',
\ 'let g:ale_set_highlights = 1',
\ 'let g:ale_set_loclist = 1',

View File

@ -1,9 +1,9 @@
Before:
Save g:ale_lsp_root
Save b:ale_lsp_root
Save g:ale_root
Save b:ale_root
let g:ale_lsp_root = {}
unlet! b:ale_lsp_root
let g:ale_root = {}
unlet! b:ale_root
let g:linter = {}