diff options
author | David le Blanc <systemmonkey42@users.noreply.github.com> | 2023-03-31 12:50:48 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-31 10:50:48 +0900 |
commit | 41e12fd64048c6f9c1f9b9567b22bdc3dad459d3 (patch) | |
tree | e7ca87c242f91b1a2c04e428110b529fdf64270c /autoload | |
parent | 7dbd3c96ac1eb3a1981e740423a31500108f6e25 (diff) | |
download | ale-41e12fd64048c6f9c1f9b9567b22bdc3dad459d3.zip |
Added column alignment for errors (#4473)
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/virtualtext.vim | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/autoload/ale/virtualtext.vim b/autoload/ale/virtualtext.vim index 4897154b..72bc8e6f 100644 --- a/autoload/ale/virtualtext.vim +++ b/autoload/ale/virtualtext.vim @@ -28,6 +28,11 @@ let g:ale_virtualtext_prefix = " Controls the milliseconds delay before showing a message. let g:ale_virtualtext_delay = get(g:, 'ale_virtualtext_delay', 10) +" Controls the positioning of virtualtext +let g:ale_virtualtext_column = get(g:, 'ale_virtualtext_column', 0) +let g:ale_virtualtext_maxcolumn = get(g:, 'ale_virtualtext_maxcolumn', 0) +let g:ale_virtualtext_single = get(g:,'ale_virtualtext_single',0) + let s:cursor_timer = get(s:, 'cursor_timer', -1) let s:last_pos = get(s:, 'last_pos', [0, 0, 0]) let s:hl_list = get(s:, 'hl_list', []) @@ -119,6 +124,35 @@ function! ale#virtualtext#GetGroup(item) abort return 'ALEVirtualTextInfo' endfunction +function! ale#virtualtext#GetColumnPadding(buffer, line) abort + let l:mincol = ale#Var(a:buffer, 'virtualtext_column') + let l:maxcol = ale#Var(a:buffer, 'virtualtext_maxcolumn') + let l:win = bufwinnr(a:buffer) + + if l:mincol[len(l:mincol)-1] is# '%' + let l:mincol = (winwidth(l:win) * l:mincol) / 100 + endif + + if l:maxcol[len(l:maxcol)-1] is# '%' + let l:maxcol = (winwidth(l:win) * l:maxcol) / 100 + endif + + " Calculate padding for virtualtext alignment + if l:mincol > 0 || l:maxcol > 0 + let l:line_width = strdisplaywidth(getline(a:line)) + + if l:line_width < l:mincol + return l:mincol - l:line_width + elseif l:maxcol > 0 && l:line_width >= l:maxcol + " Stop processing if virtualtext would start beyond maxcol + return -1 + endif + endif + + " no padding. + return 0 +endfunction + function! ale#virtualtext#ShowMessage(buffer, item) abort if !s:has_virt_text || !bufexists(str2nr(a:buffer)) return @@ -133,10 +167,16 @@ function! ale#virtualtext#ShowMessage(buffer, item) abort let l:prefix = ale#GetLocItemMessage(a:item, l:prefix) let l:prefix = substitute(l:prefix, '\V%comment%', '\=l:comment', 'g') let l:msg = l:prefix . substitute(a:item.text, '\n', ' ', 'g') + let l:col_pad = ale#virtualtext#GetColumnPadding(a:buffer, l:line) " Store the last message we're going to set so we can read it in tests. let s:last_message = l:msg + " Discard virtualtext if padding is negative. + if l:col_pad < 0 + return + endif + if has('nvim') call nvim_buf_set_virtual_text( \ a:buffer, @@ -174,6 +214,7 @@ function! ale#virtualtext#ShowMessage(buffer, item) abort \ 'type': l:hl_group, \ 'text': ' ' . l:msg, \ 'bufnr': a:buffer, + \ 'text_padding_left': l:col_pad, \}) endif endfunction @@ -239,9 +280,17 @@ function! ale#virtualtext#SetTexts(buffer, loclist) abort call ale#virtualtext#Clear(a:buffer) + let l:filter = ale#Var(a:buffer,'virtualtext_single') + let l:seen = {} + for l:item in a:loclist if l:item.bufnr == a:buffer - call ale#virtualtext#ShowMessage(a:buffer, l:item) + let l:line = max([1, l:item.lnum]) + + if !has_key(l:seen,l:line) || l:filter == 0 + call ale#virtualtext#ShowMessage(a:buffer, l:item) + let l:seen[l:line] = 1 + endif endif endfor endfunction |