Compare commits

...

7 Commits

4 changed files with 70 additions and 59 deletions

View File

@@ -52,9 +52,9 @@ function! s:NvimShow(lines, options) abort
autocmd! autocmd!
if g:ale_close_preview_on_insert if g:ale_close_preview_on_insert
autocmd CursorMoved,TabLeave,WinLeave,InsertEnter <buffer> ++once call s:NvimClose() autocmd CursorMoved,TabLeave,WinLeave,BufWinLeave,WinScrolled,InsertEnter <buffer> ++once call s:NvimClose()
else else
autocmd CursorMoved,TabLeave,WinLeave <buffer> ++once call s:NvimClose() autocmd CursorMoved,TabLeave,WinLeave,BufWinLeave,WinScrolled <buffer> ++once call s:NvimClose()
endif endif
augroup END augroup END

View File

@@ -22,26 +22,6 @@ if !hlexists('ALEInfo')
highlight link ALEInfo ALEWarning highlight link ALEInfo ALEWarning
endif endif
if !hlexists('ALEVirtualTextError')
highlight link ALEVirtualTextError ALEError
endif
if !hlexists('ALEVirtualTextStyleError')
highlight link ALEVirtualTextStyleError ALEVirtualTextError
endif
if !hlexists('ALEVirtualTextWarning')
highlight link ALEVirtualTextWarning ALEWarning
endif
if !hlexists('ALEVirtualTextStyleWarning')
highlight link ALEVirtualTextStyleWarning ALEVirtualTextWarning
endif
if !hlexists('ALEVirtualTextInfo')
highlight link ALEVirtualTextInfo ALEVirtualTextWarning
endif
" The maximum number of items for the second argument of matchaddpos() " The maximum number of items for the second argument of matchaddpos()
let s:MAX_POS_VALUES = 8 let s:MAX_POS_VALUES = 8
let s:MAX_COL_SIZE = 1073741824 " pow(2, 30) let s:MAX_COL_SIZE = 1073741824 " pow(2, 30)

View File

@@ -3,12 +3,36 @@ scriptencoding utf-8
" Author: Luan Santos <cfcluan@gmail.com> " Author: Luan Santos <cfcluan@gmail.com>
" Description: Shows lint message for the current line as virtualtext, if any " Description: Shows lint message for the current line as virtualtext, if any
if !hlexists('ALEVirtualTextError')
highlight link ALEVirtualTextError SpellBad
endif
if !hlexists('ALEVirtualTextStyleError')
highlight link ALEVirtualTextStyleError ALEVirtualTextError
endif
if !hlexists('ALEVirtualTextWarning')
highlight link ALEVirtualTextWarning SpellCap
endif
if !hlexists('ALEVirtualTextStyleWarning')
highlight link ALEVirtualTextStyleWarning ALEVirtualTextWarning
endif
if !hlexists('ALEVirtualTextInfo')
highlight link ALEVirtualTextInfo ALEVirtualTextWarning
endif
" Controls the milliseconds delay before showing a message. " Controls the milliseconds delay before showing a message.
let g:ale_virtualtext_delay = get(g:, 'ale_virtualtext_delay', 10) let g:ale_virtualtext_delay = get(g:, 'ale_virtualtext_delay', 10)
let s:cursor_timer = -1 let s:cursor_timer = get(s:, 'cursor_timer', -1)
let s:last_pos = [0, 0, 0] let s:last_pos = get(s:, 'last_pos', [0, 0, 0])
let s:hl_list = get(s:, 'hl_list', [])
if !has_key(s:, 'has_virt_text')
let s:has_virt_text = 0 let s:has_virt_text = 0
let s:emulate_virt = 0 let s:emulate_virt = 0
let s:last_virt = -1
if has('nvim-0.3.2') if has('nvim-0.3.2')
let s:ns_id = nvim_create_namespace('ale') let s:ns_id = nvim_create_namespace('ale')
@@ -16,16 +40,15 @@ if has('nvim-0.3.2')
elseif has('textprop') && has('popupwin') elseif has('textprop') && has('popupwin')
let s:has_virt_text = 1 let s:has_virt_text = 1
let s:emulate_virt = !has('patch-9.0.0297') let s:emulate_virt = !has('patch-9.0.0297')
let s:hl_list = []
if s:emulate_virt if s:emulate_virt
call prop_type_add('ale', {}) call prop_type_add('ale', {})
let s:last_virt = -1 endif
endif endif
endif endif
function! ale#virtualtext#Clear(buf) abort function! ale#virtualtext#Clear(buf) abort
if !s:has_virt_text if !s:has_virt_text || !bufexists(str2nr(a:buf))
return return
endif endif
@@ -50,14 +73,15 @@ function! ale#virtualtext#ShowMessage(message, hl_group, buf, line) abort
return return
endif endif
let l:line = max([1, a:line])
let l:prefix = get(g:, 'ale_virtualtext_prefix', '> ') let l:prefix = get(g:, 'ale_virtualtext_prefix', '> ')
let l:msg = l:prefix.trim(substitute(a:message, '\n', ' ', 'g')) let l:msg = l:prefix.trim(substitute(a:message, '\n', ' ', 'g'))
if has('nvim') if has('nvim')
call nvim_buf_set_virtual_text(a:buf, s:ns_id, a:line-1, [[l:msg, a:hl_group]], {}) call nvim_buf_set_virtual_text(a:buf, s:ns_id, l:line-1, [[l:msg, a:hl_group]], {})
elseif s:emulate_virt elseif s:emulate_virt
let l:left_pad = col('$') let l:left_pad = col('$')
call prop_add(a:line, l:left_pad, { call prop_add(l:line, l:left_pad, {
\ 'type': 'ale', \ 'type': 'ale',
\}) \})
let s:last_virt = popup_create(l:msg, { let s:last_virt = popup_create(l:msg, {
@@ -71,14 +95,19 @@ function! ale#virtualtext#ShowMessage(message, hl_group, buf, line) abort
\ 'zindex': 2 \ 'zindex': 2
\}) \})
else else
let type = prop_type_get(a:hl_group) let l:type = prop_type_get(a:hl_group)
if type == {} if l:type == {}
call add(s:hl_list, a:hl_group)
call prop_type_add(a:hl_group, {'highlight': a:hl_group}) call prop_type_add(a:hl_group, {'highlight': a:hl_group})
endif endif
call prop_add(a:line, 0, { " Add highlight groups to the list so we can clear them later.
if index(s:hl_list, a:hl_group) == -1
call add(s:hl_list, a:hl_group)
endif
" We ignore all errors from prop_add.
silent! call prop_add(l:line, 0, {
\ 'type': a:hl_group, \ 'type': a:hl_group,
\ 'text': ' ' . l:msg, \ 'text': ' ' . l:msg,
\ 'bufnr': a:buf \ 'bufnr': a:buf
@@ -93,22 +122,24 @@ function! s:StopCursorTimer() abort
endif endif
endfunction endfunction
function! ale#virtualtext#GetHlGroup(type, style) abort function! ale#virtualtext#GetHlGroup(type, sub_type) abort
if a:type is# 'E' if a:type is# 'E'
if a:style is# 'style' if a:sub_type is# 'style'
return 'ALEVirtualTextStyleError' return 'ALEVirtualTextStyleError'
else endif
return 'ALEVirtualTextError' return 'ALEVirtualTextError'
endif endif
elseif a:type is# 'W'
if a:style is# 'style' if a:type is# 'W'
if a:sub_type is# 'style'
return 'ALEVirtualTextStyleWarning' return 'ALEVirtualTextStyleWarning'
else endif
return 'ALEVirtualTextWarning' return 'ALEVirtualTextWarning'
endif endif
else
return 'ALEVirtualTextInfo' return 'ALEVirtualTextInfo'
endif
endfunction endfunction
function! ale#virtualtext#ShowCursorWarning(...) abort function! ale#virtualtext#ShowCursorWarning(...) abort
@@ -181,7 +212,7 @@ function! ale#virtualtext#SetTexts(buf, loclist) abort
continue continue
endif endif
let hl = ale#virtualtext#GetHlGroup(l['type'], get(l, 'sub_type', '')) let l:hl = ale#virtualtext#GetHlGroup(l['type'], get(l, 'sub_type', ''))
call ale#virtualtext#ShowMessage(l['text'], hl, a:buf, l['lnum']) call ale#virtualtext#ShowMessage(l['text'], l:hl, a:buf, l['lnum'])
endfor endfor
endfunction endfunction

View File

@@ -2508,7 +2508,7 @@ ALEStyleWarningSignLineNr *ALEStyleWarningSignLineNr*
ALEVirtualTextError *ALEVirtualTextError* ALEVirtualTextError *ALEVirtualTextError*
Default: `highlight link ALEVirtualTextError ALEError` Default: `highlight link ALEVirtualTextError SpellBad`
The highlight for virtualtext errors. See |g:ale_virtualtext_cursor|. The highlight for virtualtext errors. See |g:ale_virtualtext_cursor|.
@@ -2536,7 +2536,7 @@ ALEVirtualTextStyleWarning *ALEVirtualTextStyleWarning*
ALEVirtualTextWarning *ALEVirtualTextWarning* ALEVirtualTextWarning *ALEVirtualTextWarning*
Default: `highlight link ALEVirtualTextWarning ALEWarning` Default: `highlight link ALEVirtualTextWarning SpellCap`
The highlight for virtualtext errors. See |g:ale_virtualtext_cursor|. The highlight for virtualtext errors. See |g:ale_virtualtext_cursor|.