mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-25 19:17:23 +08:00
Fix cursor issues, and clean up the cursor tests
This commit is contained in:
@@ -18,6 +18,26 @@ function! s:GetMessage(linter, type, text) abort
|
||||
return printf(l:msg, l:text)
|
||||
endfunction
|
||||
|
||||
function! s:EchoWithShortMess(setting, message) abort
|
||||
" We need to remember the setting for shormess and reset it again.
|
||||
let l:shortmess_options = getbufvar('%', '&shortmess')
|
||||
|
||||
try
|
||||
" Turn shormess on or off.
|
||||
if a:setting ==# 'on'
|
||||
setlocal shortmess+=T
|
||||
elseif a:setting ==# 'off'
|
||||
setlocal shortmess-=T
|
||||
else
|
||||
throw 'Invalid setting: ' . string(a:setting)
|
||||
endif
|
||||
|
||||
exec "norm! :echomsg a:message\n"
|
||||
finally
|
||||
call setbufvar('%', '&shortmess', l:shortmess_options)
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! ale#cursor#TruncatedEcho(message) abort
|
||||
let l:message = a:message
|
||||
" Change tabs to spaces.
|
||||
@@ -25,17 +45,7 @@ function! ale#cursor#TruncatedEcho(message) abort
|
||||
" Remove any newlines in the message.
|
||||
let l:message = substitute(l:message, "\n", '', 'g')
|
||||
|
||||
" We need to turn T for truncated messages on for shortmess,
|
||||
" and then then we need to reset the option back to what it was.
|
||||
let l:shortmess_options = getbufvar('%', '&shortmess')
|
||||
|
||||
try
|
||||
" Echo the message truncated to fit without creating a prompt.
|
||||
setlocal shortmess+=T
|
||||
exec "norm! :echomsg message\n"
|
||||
finally
|
||||
call setbufvar('%', '&shortmess', l:shortmess_options)
|
||||
endtry
|
||||
call s:EchoWithShortMess('on', l:message)
|
||||
endfunction
|
||||
|
||||
function! s:FindItemAtCursor() abort
|
||||
@@ -47,6 +57,13 @@ function! s:FindItemAtCursor() abort
|
||||
return [l:info, l:loc]
|
||||
endfunction
|
||||
|
||||
function! s:StopCursorTimer() abort
|
||||
if s:cursor_timer != -1
|
||||
call timer_stop(s:cursor_timer)
|
||||
let s:cursor_timer = -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#cursor#EchoCursorWarning(...) abort
|
||||
" Only echo the warnings in normal mode, otherwise we will get problems.
|
||||
if mode() !=# 'n'
|
||||
@@ -63,7 +80,7 @@ function! ale#cursor#EchoCursorWarning(...) abort
|
||||
" We'll only clear the echoed message when moving off errors once,
|
||||
" so we don't continually clear the echo line.
|
||||
echo
|
||||
let l:info.echoed = 1
|
||||
let l:info.echoed = 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -75,10 +92,7 @@ function! ale#cursor#EchoCursorWarningWithDelay() abort
|
||||
return
|
||||
endif
|
||||
|
||||
if s:cursor_timer != -1
|
||||
call timer_stop(s:cursor_timer)
|
||||
let s:cursor_timer = -1
|
||||
endif
|
||||
call s:StopCursorTimer()
|
||||
|
||||
let l:pos = getcurpos()[0:2]
|
||||
|
||||
@@ -92,19 +106,22 @@ function! ale#cursor#EchoCursorWarningWithDelay() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#cursor#ShowCursorDetail(...) abort
|
||||
function! ale#cursor#ShowCursorDetail() abort
|
||||
" Only echo the warnings in normal mode, otherwise we will get problems.
|
||||
if mode() !=# 'n'
|
||||
return
|
||||
endif
|
||||
|
||||
call s:StopCursorTimer()
|
||||
|
||||
let [l:info, l:loc] = s:FindItemAtCursor()
|
||||
|
||||
if !empty(l:loc)
|
||||
if has_key(l:loc, 'detail')
|
||||
echo l:loc.detail
|
||||
else
|
||||
echo l:loc.text
|
||||
endif
|
||||
let l:message = get(l:loc, 'detail', l:loc.text)
|
||||
|
||||
call s:EchoWithShortMess('off', l:message)
|
||||
|
||||
" Set the echo marker, so we can clear it by moving the cursor.
|
||||
let l:info.echoed = 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user