Fixes #2982 - Implement g:ale_exclude_highlights

Particular highlights can now be excluded by providing Lists of regular
expressions.
This commit is contained in:
w0rp 2020-03-11 12:52:41 -04:00
parent 8f7ccdc5e9
commit bbe5153fcb
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
4 changed files with 47 additions and 0 deletions

View File

@ -210,6 +210,12 @@ function! ale#highlight#SetHighlights(buffer, loclist) abort
" Set the list in the buffer variable.
call setbufvar(str2nr(a:buffer), 'ale_highlight_items', l:new_list)
let l:exclude_list = ale#Var(a:buffer, 'exclude_highlights')
if !empty(l:exclude_list)
call filter(l:new_list, 'empty(ale#util#GetMatches(v:val.text, l:exclude_list))')
endif
" Update highlights for the current buffer, which may or may not
" be the buffer we just set highlights for.
call ale#highlight#UpdateHighlights()

View File

@ -923,6 +923,21 @@ g:ale_enabled *g:ale_enabled*
See |g:ale_pattern_options| for more information on that option.
g:ale_exclude_highlights *g:ale_exclude_highlights*
b:ale_exclude_highlights *b:ale_exclude_highlights*
Type: |List|
Default: `[]`
A list of regular expressions for matching against highlight messages to
remove. For example: >
" Do not highlight messages matching strings like these.
let b:ale_exclude_highlights = ['line too long', 'foo.*bar']
<
See also: |g:ale_set_highlights|
g:ale_fixers *g:ale_fixers*
*b:ale_fixers*
@ -1609,6 +1624,8 @@ g:ale_set_highlights *g:ale_set_highlights*
match highlights, whereas the line highlights when signs are enabled will
run to the edge of the screen.
Highlights can be excluded with the |g:ale_exclude_highlights| option.
g:ale_set_loclist *g:ale_set_loclist*

View File

@ -109,6 +109,9 @@ let g:ale_set_signs = get(g:, 'ale_set_signs', has('signs'))
" This flag can be set to 0 to disable setting error highlights.
let g:ale_set_highlights = get(g:, 'ale_set_highlights', has('syntax'))
" This List can be configured to exclude particular highlights.
let g:ale_exclude_highlights = get(g:, 'ale_exclude_highlights', [])
" This flag can be set to 0 to disable echoing when the cursor moves.
let g:ale_echo_cursor = get(g:, 'ale_echo_cursor', 1)

View File

@ -7,6 +7,8 @@ Before:
Save g:ale_set_loclist
Save g:ale_set_quickfix
Save g:ale_set_signs
Save g:ale_exclude_highlights
Save b:ale_exclude_highlights
runtime autoload/ale/highlight.vim
@ -20,6 +22,8 @@ Before:
let g:ale_set_quickfix = 0
let g:ale_set_loclist = 0
let g:ale_echo_cursor = 0
let g:ale_exclude_highlights = []
let b:ale_exclude_highlights = []
function! GenerateResults(buffer, output)
return [
@ -363,6 +367,23 @@ Execute(Highlights should always be cleared when the buffer highlight list is em
\ GetMatchesWithoutIDs()
endif
Execute(Highlights should be hidden when excluded):
let b:ale_exclude_highlights = ['ig.*ore', 'nope']
call ale#highlight#SetHighlights(bufnr('%'), [
\ {'bufnr': bufnr('%'), 'type': 'E', 'lnum': 1, 'col': 1, 'text': 'hello'},
\ {'bufnr': bufnr('%'), 'type': 'E', 'lnum': 2, 'col': 1, 'text': 'ignore'},
\ {'bufnr': bufnr('%'), 'type': 'E', 'lnum': 3, 'col': 1, 'text': 'nope'},
\ {'bufnr': bufnr('%'), 'type': 'E', 'lnum': 4, 'col': 1, 'text': 'world'},
\])
AssertEqual
\ [
\ {'group': 'ALEError', 'priority': 10, 'pos1': [1, 1, 1]},
\ {'group': 'ALEError', 'priority': 10, 'pos1': [4, 1, 1]},
\ ],
\ GetMatchesWithoutIDs()
Execute(Highlights should be cleared when ALE is disabled):
let g:ale_enabled = 1
call ale#highlight#SetHighlights(bufnr(''), [