From 708e810414d124b17b0c42e872b387a7a6c2ea85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Gro=C3=9F?= <21310755+vimpostor@users.noreply.github.com> Date: Sat, 2 Oct 2021 02:02:49 +0200 Subject: [PATCH] Implement virtual text support for vim (#3915) This requires the textprop and popupwin feature (vim 8.2). Fixes #3906 --- autoload/ale/virtualtext.vim | 39 ++++++++++++++++++++++++++++++++---- 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