Implement virtual text support for vim (#3915)

This requires the textprop and popupwin feature (vim 8.2).

Fixes #3906
This commit is contained in:
Magnus Groß 2021-10-02 02:02:49 +02:00 committed by GitHub
parent c9c89a1853
commit 708e810414
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 6 deletions

View File

@ -7,9 +7,15 @@ scriptencoding utf-8
let g:ale_virtualtext_delay = get(g:, 'ale_virtualtext_delay', 10)
let s:cursor_timer = -1
let s:last_pos = [0, 0, 0]
let s:has_virt_text = 0
if has('nvim-0.3.2')
let s:ns_id = nvim_create_namespace('ale')
let s:has_virt_text = 1
elseif has('textprop') && has('popupwin')
call prop_type_add('ale', {})
let s:last_popup = -1
let s:has_virt_text = 1
endif
if !hlexists('ALEVirtualTextError')
@ -33,17 +39,25 @@ if !hlexists('ALEVirtualTextInfo')
endif
function! ale#virtualtext#Clear() abort
if !has('nvim-0.3.2')
if !s:has_virt_text
return
endif
let l:buffer = bufnr('')
call nvim_buf_clear_highlight(l:buffer, s:ns_id, 0, -1)
if has('nvim')
call nvim_buf_clear_highlight(l:buffer, s:ns_id, 0, -1)
else
if s:last_popup != -1
call prop_remove({'type': 'ale'})
call popup_close(s:last_popup)
let s:last_popup = -1
endif
endif
endfunction
function! ale#virtualtext#ShowMessage(message, hl_group) abort
if !has('nvim-0.3.2')
if !s:has_virt_text
return
endif
@ -51,7 +65,24 @@ function! ale#virtualtext#ShowMessage(message, hl_group) abort
let l:buffer = bufnr('')
let l:prefix = get(g:, 'ale_virtualtext_prefix', '> ')
call nvim_buf_set_virtual_text(l:buffer, s:ns_id, l:line-1, [[l:prefix.a:message, a:hl_group]], {})
if has('nvim')
call nvim_buf_set_virtual_text(l:buffer, s:ns_id, l:line-1, [[l:prefix.a:message, a:hl_group]], {})
else
let l:left_pad = col('$')
call prop_add(l:line, l:left_pad, {
\ 'type': 'ale',
\})
let s:last_popup = popup_create(l:prefix.a:message, {
\ 'line': -1,
\ 'padding': [0, 0, 0, 1],
\ 'mask': [[1, 1, 1, 1]],
\ 'textprop': 'ale',
\ 'highlight': a:hl_group,
\ 'fixed': 1,
\ 'wrap': 0,
\ 'zindex': 2
\})
endif
endfunction
function! s:StopCursorTimer() abort

View File

@ -2226,8 +2226,6 @@ g:ale_virtualtext_cursor *g:ale_virtualtext_cursor*
Type: |Number|
Default: `0`
This option only has any effect in NeoVim.
When this option is set to `1`, a message will be shown when a cursor is
near a warning or error. ALE will attempt to find the warning or error at a
column nearest to the cursor when the cursor is resting on a line which