#309 Add an option for changing the sign column color when problems are detected

This commit is contained in:
w0rp 2017-05-21 22:42:27 +01:00
parent 3a289dab6b
commit b67c103d06
4 changed files with 73 additions and 0 deletions

View File

@ -24,6 +24,24 @@ if !hlexists('ALEInfoSign')
highlight link ALEInfoSign ALEWarningSign
endif
if !hlexists('ALESignColumnWithErrors')
highlight link ALESignColumnWithErrors error
endif
if !hlexists('ALESignColumnWithoutErrors')
function! s:SetSignColumnWithoutErrorsHighlight() abort
redir => l:output
silent highlight SignColumn
redir end
execute 'highlight ALESignColumnWithoutErrors '
\ . join(split(l:output)[2:])
endfunction
call s:SetSignColumnWithoutErrorsHighlight()
delfunction s:SetSignColumnWithoutErrorsHighlight
endif
" Signs show up on the left for error markers.
execute 'sign define ALEErrorSign text=' . g:ale_sign_error
\ . ' texthl=ALEErrorSign linehl=ALEErrorLine'
@ -154,7 +172,21 @@ function! ale#sign#GetSignType(sublist) abort
return 'ALEErrorSign'
endfunction
function! ale#sign#SetSignColumnHighlight(has_problems) abort
highlight clear SignColumn
if a:has_problems
highlight link SignColumn ALESignColumnWithErrors
else
highlight link SignColumn ALESignColumnWithoutErrors
endif
endfunction
function! s:PlaceNewSigns(buffer, grouped_items) abort
if g:ale_change_sign_column_color
call ale#sign#SetSignColumnHighlight(!empty(a:grouped_items))
endif
" Add the new signs,
for l:index in range(0, len(a:grouped_items) - 1)
let l:sign_id = l:index + g:ale_sign_offset + 1

View File

@ -207,6 +207,21 @@ g:airline#extensions#ale#enabled *g:airline#extensions#ale#enabled*
|airline#extensions#ale#warning_symbol|.
g:ale_change_sign_column_color *g:ale_change_sign_column_color*
Type: |Number|
Default: `0`
When set to `1`, this option will set different highlights for the sign
column itself when ALE reports problems with a file. This option can be
combined with |g:ale_sign_column_always|.
ALE uses the following highlight groups for highlighting the sign column:
`ALESignColumnWithErrors` - Links to `error` by default.
`ALESignColumnWithoutErrors` - Use the value for `SignColumn` by default.
g:ale_echo_cursor *g:ale_echo_cursor*
Type: |Number|

View File

@ -108,6 +108,10 @@ let g:ale_keep_list_window_open = get(g:, 'ale_keep_list_window_open', 0)
" This is enabled by default only if the 'signs' feature exists.
let g:ale_set_signs = get(g:, 'ale_set_signs', has('signs'))
" This flag can be set to 1 to enable changing the sign column colors when
" there are errors.
call ale#Set('change_sign_column_color', 0)
" This flag can be set to 0 to disable setting error highlights.
let g:ale_set_highlights = get(g:, 'ale_set_highlights', has('syntax'))

View File

@ -0,0 +1,22 @@
Before:
function! ParseSignColumnHighlight() abort
redir => l:output
silent highlight SignColumn
redir end
return join(split(l:output)[2:])
endfunction
let g:sign_highlight = ParseSignColumnHighlight()
After:
delfunction ParseSignColumnHighlight
execute 'highlight SignColumn ' . g:sign_highlight
unlet! g:sign_highlight
Execute(The SignColumn highlight should be set and reset):
call ale#sign#SetSignColumnHighlight(1)
AssertEqual 'links to ALESignColumnWithErrors', ParseSignColumnHighlight()
call ale#sign#SetSignColumnHighlight(0)
AssertEqual 'links to ALESignColumnWithoutErrors', ParseSignColumnHighlight()