summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-04-27 22:52:11 +0100
committerw0rp <devw0rp@gmail.com>2018-04-27 22:52:11 +0100
commit6ab3fdc4d0566c09e9456c3bf1b7aa92747fd0aa (patch)
tree84362ca60df1e82d69e709e11688062d59c1ba79 /autoload
parentd1d705cc8484d935c0c18857f152027491df355e (diff)
downloadale-6ab3fdc4d0566c09e9456c3bf1b7aa92747fd0aa.zip
Close #1521 - Allow the language to be set with simple strings for LSP linters
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/linter.vim26
1 files changed, 23 insertions, 3 deletions
diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim
index 8aec2598..1e0ec304 100644
--- a/autoload/ale/linter.vim
+++ b/autoload/ale/linter.vim
@@ -51,6 +51,10 @@ function! s:IsBoolean(value) abort
return type(a:value) == type(0) && (a:value == 0 || a:value == 1)
endfunction
+function! s:LanguageGetter(buffer) dict abort
+ return l:self.language
+endfunction
+
function! ale#linter#PreProcess(linter) abort
if type(a:linter) != type({})
throw 'The linter object must be a Dictionary'
@@ -185,10 +189,26 @@ function! ale#linter#PreProcess(linter) abort
endif
if l:needs_lsp_details
- let l:obj.language_callback = get(a:linter, 'language_callback')
+ if has_key(a:linter, 'language')
+ if has_key(a:linter, 'language_callback')
+ throw 'Only one of `language` or `language_callback` '
+ \ . 'should be set'
+ endif
+
+ let l:obj.language = get(a:linter, 'language')
- if !s:IsCallback(l:obj.language_callback)
- throw '`language_callback` must be a callback for LSP linters'
+ if type(l:obj.language) != type('')
+ throw '`language` must be a string'
+ endif
+
+ " Make 'language_callback' return the 'language' value.
+ let l:obj.language_callback = function('s:LanguageGetter')
+ else
+ let l:obj.language_callback = get(a:linter, 'language_callback')
+
+ if !s:IsCallback(l:obj.language_callback)
+ throw '`language_callback` must be a callback for LSP linters'
+ endif
endif
let l:obj.project_root_callback = get(a:linter, 'project_root_callback')