#2132 - Implement project_root as a replacement for project_root_callback

This commit is contained in:
w0rp
2019-02-22 15:24:34 +00:00
parent f8aeb5c5a4
commit f53b25d256
4 changed files with 98 additions and 8 deletions

View File

@@ -242,10 +242,21 @@ function! ale#linter#PreProcess(filetype, linter) abort
endif
endif
let l:obj.project_root_callback = get(a:linter, 'project_root_callback')
if has_key(a:linter, 'project_root')
let l:obj.project_root = a:linter.project_root
if !s:IsCallback(l:obj.project_root_callback)
throw '`project_root_callback` must be a callback for LSP linters'
if type(l:obj.project_root) isnot v:t_string
\&& type(l:obj.project_root) isnot v:t_func
throw '`project_root` must be a String or Function if defined'
endif
elseif has_key(a:linter, 'project_root_callback')
let l:obj.project_root_callback = a:linter.project_root_callback
if !s:IsCallback(l:obj.project_root_callback)
throw '`project_root_callback` must be a callback if defined'
endif
else
throw '`project_root` or `project_root_callback` must be defined for LSP linters'
endif
if has_key(a:linter, 'completion_filter')

View File

@@ -194,6 +194,12 @@ function! ale#lsp_linter#FindProjectRoot(buffer, linter) abort
endif
" Fall back to the linter-specific configuration
if has_key(a:linter, 'project_root')
let l:Root = a:linter.project_root
return type(l:Root) is v:t_func ? l:Root(a:buffer) : l:Root
endif
return ale#util#GetFunction(a:linter.project_root_callback)(a:buffer)
endfunction