summaryrefslogtreecommitdiff
path: root/autoload/ale/path.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/ale/path.vim')
-rw-r--r--autoload/ale/path.vim36
1 files changed, 36 insertions, 0 deletions
diff --git a/autoload/ale/path.vim b/autoload/ale/path.vim
index 00e31310..c7bfd47e 100644
--- a/autoload/ale/path.vim
+++ b/autoload/ale/path.vim
@@ -77,6 +77,42 @@ function! ale#path#ResolveLocalPath(buffer, search_string, global_fallback) abor
return l:path
endfunction
+" Given a buffer number, a base variable name, and a list of paths to search
+" for in ancestor directories, detect the executable path for a program.
+function! ale#path#FindNearestExecutable(buffer, path_list) abort
+ for l:path in a:path_list
+ if ale#path#IsAbsolute(l:path)
+ let l:executable = filereadable(l:path) ? l:path : ''
+ else
+ let l:executable = ale#path#FindNearestFile(a:buffer, l:path)
+ endif
+
+ if !empty(l:executable)
+ return l:executable
+ endif
+ endfor
+
+ return ''
+endfunction
+
+" Given a buffer number, a base variable name, and a list of paths to search
+" for in ancestor directories, detect the executable path for a program.
+"
+" The use_global and executable options for the relevant program will be used.
+function! ale#path#FindExecutable(buffer, base_var_name, path_list) abort
+ if ale#Var(a:buffer, a:base_var_name . '_use_global')
+ return ale#Var(a:buffer, a:base_var_name . '_executable')
+ endif
+
+ let l:nearest = ale#path#FindNearestExecutable(a:buffer, a:path_list)
+
+ if !empty(l:nearest)
+ return l:nearest
+ endif
+
+ return ale#Var(a:buffer, a:base_var_name . '_executable')
+endfunction
+
" Return 1 if a path is an absolute path.
function! ale#path#IsAbsolute(filename) abort
if has('win32') && a:filename[:0] is# '\'