diff options
author | Magnus Groß <21310755+vimpostor@users.noreply.github.com> | 2021-10-02 02:02:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-02 09:02:49 +0900 |
commit | 708e810414d124b17b0c42e872b387a7a6c2ea85 (patch) | |
tree | d5d7f4ac47cdf223668e69932b5c498fa9a82699 | |
parent | c9c89a1853c01f3451edd7105814d123023ddbd8 (diff) | |
download | ale-708e810414d124b17b0c42e872b387a7a6c2ea85.zip |
Implement virtual text support for vim (#3915)
This requires the textprop and popupwin feature (vim 8.2).
Fixes #3906
-rw-r--r-- | autoload/ale/virtualtext.vim | 39 | ||||
-rw-r--r-- | doc/ale.txt | 2 |
2 files changed, 35 insertions, 6 deletions
diff --git a/autoload/ale/virtualtext.vim b/autoload/ale/virtualtext.vim index d7c5360e..2a9903bc 100644 --- a/autoload/ale/virtualtext.vim +++ b/autoload/ale/virtualtext.vim @@ -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 diff --git a/doc/ale.txt b/doc/ale.txt index c9921b8b..1da2d4a1 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -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 |