aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorw0rp2026-05-15 21:06:48 +0100
committerw0rp2026-05-15 21:06:54 +0100
commit7b5b854fc487043038b86f66db93c4a4879e6629 (patch)
tree64aec6846d4ef48130262a86b449cbbc46ba4e4a
parent916c8764ce9d395f788eae9adf207a4bfe8a038e (diff)
downloadale-7b5b854fc487043038b86f66db93c4a4879e6629.tar.gz

Close #5002 - Support getting g:ale_root as a String

-rw-r--r--autoload/ale/lsp_linter.vim5
-rw-r--r--doc/ale.txt6
-rw-r--r--test/linter/test_perl_languageserver.vader11
-rw-r--r--test/linter/test_perl_perlnavigator.vader8
-rw-r--r--test/lsp/test_lsp_root_detection.vader6
5 files changed, 25 insertions, 11 deletions
diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim
index fdd492ddc..6e33f0af1 100644
--- a/autoload/ale/lsp_linter.vim
+++ b/autoload/ale/lsp_linter.vim
@@ -320,6 +320,11 @@ function! ale#lsp_linter#FindProjectRoot(buffer, linter) abort
endif
endif
+ " If the global setting is a string, return that right away.
+ if type(g:ale_root) is v:t_string
+ return g:ale_root
+ endif
+
" Try to get a global setting for the root
if has_key(g:ale_root, a:linter.name)
let l:Root = g:ale_root[a:linter.name]
diff --git a/doc/ale.txt b/doc/ale.txt
index 0c20eaf19..d3f2b6978 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2334,10 +2334,8 @@ g:ale_root
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.
+ provided the buffer number as its argument. If the the value is a string, it
+ will be interpreted as 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
diff --git a/test/linter/test_perl_languageserver.vader b/test/linter/test_perl_languageserver.vader
index bfcc6c1e4..f2e30a84f 100644
--- a/test/linter/test_perl_languageserver.vader
+++ b/test/linter/test_perl_languageserver.vader
@@ -33,11 +33,12 @@ Execute(The project root should be globally configurable):
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/perl')
unlet g:ale_root.languageserver
- " As tracked by <https://github.com/dense-analysis/ale/issues/5002>, there
- " is a bug with g:ale_root.
- " While attempting to configure g:ale_root using a String might be a quite
- " limiting setup, it would be handy for debugging. However the test case is
- " missing here. It would unfortunately just fail.
+
+ " Configuring g:ale_root using a String works.
+ let g:ale_root = ale#path#Simplify(g:dir . '/../test-files/perl')
+
+ AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/perl')
+ let g:ale_root = {}
endfor
Execute(The project root should be per buffer configurable):
diff --git a/test/linter/test_perl_perlnavigator.vader b/test/linter/test_perl_perlnavigator.vader
index f321babb2..f070a0aeb 100644
--- a/test/linter/test_perl_perlnavigator.vader
+++ b/test/linter/test_perl_perlnavigator.vader
@@ -32,8 +32,12 @@ Execute(The project root should be globally configurable):
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/perl')
unlet g:ale_root.perlnavigator
- " As tracked by <https://github.com/dense-analysis/ale/issues/5002>, there
- " is a bug with g:ale_root which is thus missing here.
+
+ " Configuring g:ale_root using a String works.
+ let g:ale_root = ale#path#Simplify(g:dir . '/../test-files/perl')
+
+ AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/perl')
+ let g:ale_root = {}
endfor
Execute(The project root should be per buffer configurable):
diff --git a/test/lsp/test_lsp_root_detection.vader b/test/lsp/test_lsp_root_detection.vader
index 2aead6ba4..cbd6b5eef 100644
--- a/test/lsp/test_lsp_root_detection.vader
+++ b/test/lsp/test_lsp_root_detection.vader
@@ -41,6 +41,12 @@ Execute(The global variable can be a dictionary):
AssertLSPProject '/some/path'
+Execute(The global variable can be a string):
+ let g:ale_root = '/some/path'
+ call ale#test#SetFilename('other-file.c')
+
+ AssertLSPProject '/some/path'
+
Execute(The global variable can have funcrefs):
let g:ale_root = {'clangd': function('Hook1'), 'golangserver': '/path'}
call ale#test#SetFilename('other-file.c')