diff --git a/autoload/ale/assert.vim b/autoload/ale/assert.vim index 7db0a22e..8c7a5461 100644 --- a/autoload/ale/assert.vim +++ b/autoload/ale/assert.vim @@ -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) diff --git a/autoload/ale/debugging.vim b/autoload/ale/debugging.vim index 5e6d5906..1f7ea467 100644 --- a/autoload/ale/debugging.vim +++ b/autoload/ale/debugging.vim @@ -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', diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim index 2a3902b6..0d039198 100644 --- a/autoload/ale/lsp_linter.vim +++ b/autoload/ale/lsp_linter.vim @@ -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) diff --git a/doc/ale.txt b/doc/ale.txt index 1ea65a33..5376a16c 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -963,8 +963,8 @@ g:ale_default_navigation *g:ale_default_navigation* buffer, such as for |ALEFindReferences|, or |ALEGoToDefinition|. -g:ale_detail_to_floating_preview *g:ale_detail_to_floating_preview* - *b:ale_detail_to_floating_preview* +g:ale_detail_to_floating_preview *g:ale_detail_to_floating_preview* + *b:ale_detail_to_floating_preview* Type: |Number| Default: `0` @@ -1195,7 +1195,7 @@ g:ale_fix_on_save_ignore *g:ale_fix_on_save_ignore* let g:ale_fix_on_save_ignore = [g:AddBar] < -g:ale_floating_preview *g:ale_floating_preview* +g:ale_floating_preview *g:ale_floating_preview* Type: |Number| Default: `0` @@ -1263,8 +1263,8 @@ g:ale_hover_to_preview *g:ale_hover_to_preview* instead of in balloons or the message line. -g:ale_hover_to_floating_preview *g:ale_hover_to_floating_preview* - *b:ale_hover_to_floating_preview* +g:ale_hover_to_floating_preview *g:ale_hover_to_floating_preview* + *b:ale_hover_to_floating_preview* Type: |Number| Default: `0` @@ -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* diff --git a/plugin/ale.vim b/plugin/ale.vim index 845586be..540ba11b 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -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) diff --git a/test/lsp/test_lsp_root_detection.vader b/test/lsp/test_lsp_root_detection.vader index 3de4d825..291300f0 100644 --- a/test/lsp/test_lsp_root_detection.vader +++ b/test/lsp/test_lsp_root_detection.vader @@ -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' diff --git a/test/test_ale_info.vader b/test/test_ale_info.vader index 895ed2a7..2e0965a9 100644 --- a/test/test_ale_info.vader +++ b/test/test_ale_info.vader @@ -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', diff --git a/test/test_linter_defintion_processing.vader b/test/test_linter_defintion_processing.vader index fa1b6786..4c096a5e 100644 --- a/test/test_linter_defintion_processing.vader +++ b/test/test_linter_defintion_processing.vader @@ -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 = {}