mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-25 04:16:50 +08:00
Move virtualtext handling to own file
This allows cursor and virtualtext to be independently autoloaded.
This commit is contained in:
@@ -52,39 +52,6 @@ function! ale#cursor#TruncatedEcho(original_message) abort
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! ale#cursor#ClearVirtualText() abort
|
||||
if !has('nvim-0.3.2')
|
||||
return
|
||||
endif
|
||||
|
||||
let l:buffer = bufnr('')
|
||||
|
||||
call nvim_buf_clear_highlight(l:buffer, 1000, 0, -1)
|
||||
endfunction
|
||||
|
||||
function! ale#cursor#ShowVirtualText(message, hl_group) abort
|
||||
if !has('nvim-0.3.2')
|
||||
return
|
||||
endif
|
||||
|
||||
let l:cursor_position = getcurpos()
|
||||
let l:line = line('.')
|
||||
let l:buffer = bufnr('')
|
||||
let l:prefix = get(g:, 'ale_virtualtext_prefix', '> ')
|
||||
|
||||
call nvim_buf_set_virtual_text(l:buffer, 1000, l:line-1, [[l:prefix.a:message, a:hl_group]], {})
|
||||
endfunction
|
||||
|
||||
function! s:FindItemAtCursor(buffer) abort
|
||||
let l:info = get(g:ale_buffer_info, a:buffer, {})
|
||||
let l:loclist = get(l:info, 'loclist', [])
|
||||
let l:pos = getcurpos()
|
||||
let l:index = ale#util#BinarySearch(l:loclist, a:buffer, l:pos[1], l:pos[2])
|
||||
let l:loc = l:index >= 0 ? l:loclist[l:index] : {}
|
||||
|
||||
return [l:info, l:loc]
|
||||
endfunction
|
||||
|
||||
function! s:StopCursorTimer() abort
|
||||
if s:cursor_timer != -1
|
||||
call timer_stop(s:cursor_timer)
|
||||
@@ -95,7 +62,7 @@ endfunction
|
||||
function! ale#cursor#EchoCursorWarning(...) abort
|
||||
let l:buffer = bufnr('')
|
||||
|
||||
if !g:ale_echo_cursor && !g:ale_cursor_detail && !g:ale_virtualtext_cursor
|
||||
if !g:ale_echo_cursor && !g:ale_cursor_detail
|
||||
return
|
||||
endif
|
||||
|
||||
@@ -108,7 +75,7 @@ function! ale#cursor#EchoCursorWarning(...) abort
|
||||
return
|
||||
endif
|
||||
|
||||
let [l:info, l:loc] = s:FindItemAtCursor(l:buffer)
|
||||
let [l:info, l:loc] = ale#util#FindItemAtCursor(l:buffer)
|
||||
|
||||
if g:ale_echo_cursor
|
||||
if !empty(l:loc)
|
||||
@@ -131,30 +98,12 @@ function! ale#cursor#EchoCursorWarning(...) abort
|
||||
call ale#preview#CloseIfTypeMatches('ale-preview')
|
||||
endif
|
||||
endif
|
||||
|
||||
if g:ale_virtualtext_cursor
|
||||
call ale#cursor#ClearVirtualText()
|
||||
|
||||
if !empty(l:loc)
|
||||
let l:msg = get(l:loc, 'detail', l:loc.text)
|
||||
let l:hl_group = 'ALEInfo'
|
||||
let l:type = get(l:loc, 'type', 'E')
|
||||
|
||||
if l:type is# 'E'
|
||||
let l:hl_group = 'ALEError'
|
||||
elseif l:type is# 'W'
|
||||
let l:hl_group = 'ALEWarning'
|
||||
endif
|
||||
|
||||
call ale#cursor#ShowVirtualText(l:msg, l:hl_group)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#cursor#EchoCursorWarningWithDelay() abort
|
||||
let l:buffer = bufnr('')
|
||||
|
||||
if !g:ale_echo_cursor && !g:ale_cursor_detail && !g:ale_virtualtext_cursor
|
||||
if !g:ale_echo_cursor && !g:ale_cursor_detail
|
||||
return
|
||||
endif
|
||||
|
||||
@@ -210,7 +159,7 @@ function! ale#cursor#ShowCursorDetail() abort
|
||||
|
||||
call s:StopCursorTimer()
|
||||
|
||||
let [l:info, l:loc] = s:FindItemAtCursor(l:buffer)
|
||||
let [l:info, l:loc] = ale#util#FindItemAtCursor(l:buffer)
|
||||
|
||||
if !empty(l:loc)
|
||||
call s:ShowCursorDetailForItem(l:loc, {'stay_here': 0})
|
||||
|
||||
Reference in New Issue
Block a user