diff options
author | w0rp <devw0rp@gmail.com> | 2018-06-24 21:16:45 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2018-06-24 21:16:45 +0100 |
commit | 620951b6d3420ca69754f3e1068167729d8c651b (patch) | |
tree | 2880dce657ca750d3a6179420d655f00136b46fd /autoload | |
parent | 755f1a4ccfff28463b0fe30f74a97390ae59d1fa (diff) | |
download | ale-620951b6d3420ca69754f3e1068167729d8c651b.zip |
Close #1453 #1172 - Add ale_linters_ignore for ignoring linter results
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale.vim | 11 | ||||
-rw-r--r-- | autoload/ale/engine/ignore.vim | 46 | ||||
-rw-r--r-- | autoload/ale/lsp_linter.vim | 26 |
3 files changed, 81 insertions, 2 deletions
diff --git a/autoload/ale.vim b/autoload/ale.vim index 205a5abb..dcc12150 100644 --- a/autoload/ale.vim +++ b/autoload/ale.vim @@ -6,6 +6,8 @@ let g:ale_echo_msg_error_str = get(g:, 'ale_echo_msg_error_str', 'Error') let g:ale_echo_msg_info_str = get(g:, 'ale_echo_msg_info_str', 'Info') let g:ale_echo_msg_warning_str = get(g:, 'ale_echo_msg_warning_str', 'Warning') +" Ignoring linters, for disabling some, or ignoring LSP diagnostics. +let g:ale_linters_ignore = get(g:, 'ale_linters_ignore', {}) let s:lint_timer = -1 let s:queued_buffer_number = -1 @@ -150,7 +152,8 @@ function! ale#Lint(...) abort endif " Use the filetype from the buffer - let l:linters = ale#linter#Get(getbufvar(l:buffer, '&filetype')) + let l:filetype = getbufvar(l:buffer, '&filetype') + let l:linters = ale#linter#Get(l:filetype) let l:should_lint_file = 0 " Check if we previously requested checking the file. @@ -160,6 +163,12 @@ function! ale#Lint(...) abort let l:should_lint_file = filereadable(expand('#' . l:buffer . ':p')) endif + " Apply ignore lists for linters only if needed. + let l:ignore_config = ale#Var(l:buffer, 'linters_ignore') + let l:linters = !empty(l:ignore_config) + \ ? ale#engine#ignore#Exclude(l:filetype, l:linters, l:ignore_config) + \ : l:linters + call ale#engine#RunLinters(l:buffer, l:linters, l:should_lint_file) endfunction diff --git a/autoload/ale/engine/ignore.vim b/autoload/ale/engine/ignore.vim new file mode 100644 index 00000000..65347e21 --- /dev/null +++ b/autoload/ale/engine/ignore.vim @@ -0,0 +1,46 @@ +" Author: w0rp <devw0rp@gmail.com> +" Description: Code for ignoring linters. Only loaded and if configured. + +" Given a filetype and a configuration for ignoring linters, return a List of +" Strings for linter names to ignore. +function! ale#engine#ignore#GetList(filetype, config) abort + if type(a:config) is type([]) + return a:config + endif + + if type(a:config) is type({}) + let l:names_to_remove = [] + + for l:part in split(a:filetype , '\.') + call extend(l:names_to_remove, get(a:config, l:part, [])) + endfor + + return l:names_to_remove + endif + + return [] +endfunction + +" Given a List of linter descriptions, exclude the linters to be ignored. +function! ale#engine#ignore#Exclude(filetype, all_linters, config) abort + let l:names_to_remove = ale#engine#ignore#GetList(a:filetype, a:config) + let l:filtered_linters = [] + + for l:linter in a:all_linters + let l:name_list = [l:linter.name] + l:linter.aliases + let l:should_include = 1 + + for l:name in l:name_list + if index(l:names_to_remove, l:name) >= 0 + let l:should_include = 0 + break + endif + endfor + + if l:should_include + call add(l:filtered_linters, l:linter) + endif + endfor + + return l:filtered_linters +endfunction diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim index 4aef8ff5..781d04c4 100644 --- a/autoload/ale/lsp_linter.vim +++ b/autoload/ale/lsp_linter.vim @@ -8,11 +8,30 @@ if !has_key(s:, 'lsp_linter_map') let s:lsp_linter_map = {} endif +" Check if diagnostics for a particular linter should be ignored. +function! s:ShouldIgnore(buffer, linter_name) abort + let l:config = ale#Var(a:buffer, 'linters_ignore') + + " Don't load code for ignoring diagnostics if there's nothing to ignore. + if empty(l:config) + return 0 + endif + + let l:filetype = getbufvar(a:buffer, '&filetype') + let l:ignore_list = ale#engine#ignore#GetList(l:filetype, l:config) + + return index(l:ignore_list, a:linter_name) >= 0 +endfunction + function! s:HandleLSPDiagnostics(conn_id, response) abort let l:linter_name = s:lsp_linter_map[a:conn_id] let l:filename = ale#path#FromURI(a:response.params.uri) let l:buffer = bufnr(l:filename) + if s:ShouldIgnore(l:buffer, l:linter_name) + return + endif + if l:buffer <= 0 return endif @@ -23,6 +42,7 @@ function! s:HandleLSPDiagnostics(conn_id, response) abort endfunction function! s:HandleTSServerDiagnostics(response, error_type) abort + let l:linter_name = 'tsserver' let l:buffer = bufnr(a:response.body.file) let l:info = get(g:ale_buffer_info, l:buffer, {}) @@ -30,6 +50,10 @@ function! s:HandleTSServerDiagnostics(response, error_type) abort return endif + if s:ShouldIgnore(l:buffer, l:linter_name) + return + endif + let l:thislist = ale#lsp#response#ReadTSServerDiagnostics(a:response) " tsserver sends syntax and semantic errors in separate messages, so we @@ -44,7 +68,7 @@ function! s:HandleTSServerDiagnostics(response, error_type) abort let l:loclist = get(l:info, 'semantic_loclist', []) \ + get(l:info, 'syntax_loclist', []) - call ale#engine#HandleLoclist('tsserver', l:buffer, l:loclist) + call ale#engine#HandleLoclist(l:linter_name, l:buffer, l:loclist) endfunction function! s:HandleLSPErrorMessage(linter_name, response) abort |