2016-10-03 18:41:02 +00:00
|
|
|
" Author: w0rp <devw0rp@gmail.com>
|
|
|
|
" Description: Echoes lint message for the current line, if any
|
|
|
|
|
2017-08-12 09:47:06 +00:00
|
|
|
let s:cursor_timer = -1
|
|
|
|
let s:last_pos = [0, 0, 0]
|
|
|
|
|
2017-12-18 11:22:24 +00:00
|
|
|
function! ale#cursor#TruncatedEcho(original_message) abort
|
|
|
|
let l:message = a:original_message
|
2016-09-08 23:23:26 +00:00
|
|
|
" Change tabs to spaces.
|
2016-10-10 23:00:09 +00:00
|
|
|
let l:message = substitute(l:message, "\t", ' ', 'g')
|
2016-09-08 23:23:26 +00:00
|
|
|
" Remove any newlines in the message.
|
2016-10-10 23:00:09 +00:00
|
|
|
let l:message = substitute(l:message, "\n", '', 'g')
|
2016-09-08 23:23:26 +00:00
|
|
|
|
2017-12-18 11:22:24 +00:00
|
|
|
" We need to remember the setting for shortmess and reset it again.
|
|
|
|
let l:shortmess_options = &l:shortmess
|
|
|
|
|
|
|
|
try
|
2017-12-19 12:06:08 +00:00
|
|
|
let l:cursor_position = getcurpos()
|
|
|
|
|
2017-12-18 11:22:24 +00:00
|
|
|
" The message is truncated and saved to the history.
|
|
|
|
setlocal shortmess+=T
|
|
|
|
exec "norm! :echomsg l:message\n"
|
2017-12-19 12:06:08 +00:00
|
|
|
|
|
|
|
" Reset the cursor position if we moved off the end of the line.
|
|
|
|
" Using :norm and :echomsg can move the cursor off the end of the
|
|
|
|
" line.
|
|
|
|
if l:cursor_position != getcurpos()
|
|
|
|
call setpos('.', l:cursor_position)
|
|
|
|
endif
|
2017-12-18 11:22:24 +00:00
|
|
|
finally
|
|
|
|
let &l:shortmess = l:shortmess_options
|
|
|
|
endtry
|
2016-09-08 23:23:26 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-03-03 02:40:07 +00:00
|
|
|
function! s:FindItemAtCursor() abort
|
2017-08-12 13:27:47 +00:00
|
|
|
let l:buf = bufnr('')
|
|
|
|
let l:info = get(g:ale_buffer_info, l:buf, {})
|
2017-08-07 23:46:42 +00:00
|
|
|
let l:loclist = get(l:info, 'loclist', [])
|
2017-03-03 02:40:07 +00:00
|
|
|
let l:pos = getcurpos()
|
2017-08-12 13:27:47 +00:00
|
|
|
let l:index = ale#util#BinarySearch(l:loclist, l:buf, l:pos[1], l:pos[2])
|
2017-08-07 23:46:42 +00:00
|
|
|
let l:loc = l:index >= 0 ? l:loclist[l:index] : {}
|
2017-03-03 02:40:07 +00:00
|
|
|
|
|
|
|
return [l:info, l:loc]
|
|
|
|
endfunction
|
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
function! s:StopCursorTimer() abort
|
|
|
|
if s:cursor_timer != -1
|
|
|
|
call timer_stop(s:cursor_timer)
|
|
|
|
let s:cursor_timer = -1
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
First pass at optimizing ale to autoload (#80)
* First pass at optimizing ale to autoload
First off, the structure/function names should be revised a bit,
but I will wait for @w0rp's input before unifying the naming style.
Second off, the docs probably need some more work, I just did some
simple find-and-replace work.
With that said, this pull brings major performance gains for ale. On my
slowest system, fully loading ale and all its code takes around 150ms.
I have moved all of ale's autoload-able code to autoload/, and in
addition, implemented lazy-loading of linters. This brings load time on
that same system down to 5ms.
The only downside of lazy loading is that `g:ale_linters` cannot be
changed at runtime; however, it also speeds up performance at runtime by
simplfying the logic greatly.
Please let me know what you think!
Closes #59
* Address Travis/Vint errors
For some reason, ale isn't running vint for me...
* Incorporate feedback, make fixes
Lazy-loading logic is much improved.
* Add header comments; remove incorrect workaround
* Remove unneeded plugin guards
* Fix lazy-loading linter logic
Set the wrong variable....
* Fix capitialization
2016-10-10 18:51:29 +00:00
|
|
|
function! ale#cursor#EchoCursorWarning(...) abort
|
2017-08-12 09:47:06 +00:00
|
|
|
return ale#CallWithCooldown('dont_echo_until', function('s:EchoImpl'), [])
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:EchoImpl() abort
|
2017-12-19 14:43:18 +00:00
|
|
|
if !g:ale_echo_cursor
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-10-11 22:51:36 +00:00
|
|
|
" Only echo the warnings in normal mode, otherwise we will get problems.
|
|
|
|
if mode() isnot# 'n'
|
2017-05-26 15:20:17 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-10-11 22:51:36 +00:00
|
|
|
if ale#ShouldDoNothing(bufnr(''))
|
2016-10-09 11:50:45 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-11-19 23:44:02 +00:00
|
|
|
let l:buffer = bufnr('')
|
2017-03-03 02:40:07 +00:00
|
|
|
let [l:info, l:loc] = s:FindItemAtCursor()
|
2016-09-14 10:47:52 +00:00
|
|
|
|
2017-03-03 02:40:07 +00:00
|
|
|
if !empty(l:loc)
|
2017-11-19 23:44:02 +00:00
|
|
|
let l:format = ale#Var(l:buffer, 'echo_msg_format')
|
|
|
|
let l:msg = ale#GetLocItemMessage(l:loc, l:format)
|
2016-10-10 23:00:09 +00:00
|
|
|
call ale#cursor#TruncatedEcho(l:msg)
|
2017-03-03 02:40:07 +00:00
|
|
|
let l:info.echoed = 1
|
|
|
|
elseif get(l:info, 'echoed')
|
2016-10-24 19:55:20 +00:00
|
|
|
" We'll only clear the echoed message when moving off errors once,
|
|
|
|
" so we don't continually clear the echo line.
|
2017-11-15 12:00:08 +00:00
|
|
|
execute 'echo'
|
2017-03-03 20:14:03 +00:00
|
|
|
let l:info.echoed = 0
|
2016-09-08 23:23:26 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
First pass at optimizing ale to autoload (#80)
* First pass at optimizing ale to autoload
First off, the structure/function names should be revised a bit,
but I will wait for @w0rp's input before unifying the naming style.
Second off, the docs probably need some more work, I just did some
simple find-and-replace work.
With that said, this pull brings major performance gains for ale. On my
slowest system, fully loading ale and all its code takes around 150ms.
I have moved all of ale's autoload-able code to autoload/, and in
addition, implemented lazy-loading of linters. This brings load time on
that same system down to 5ms.
The only downside of lazy loading is that `g:ale_linters` cannot be
changed at runtime; however, it also speeds up performance at runtime by
simplfying the logic greatly.
Please let me know what you think!
Closes #59
* Address Travis/Vint errors
For some reason, ale isn't running vint for me...
* Incorporate feedback, make fixes
Lazy-loading logic is much improved.
* Add header comments; remove incorrect workaround
* Remove unneeded plugin guards
* Fix lazy-loading linter logic
Set the wrong variable....
* Fix capitialization
2016-10-10 18:51:29 +00:00
|
|
|
function! ale#cursor#EchoCursorWarningWithDelay() abort
|
2017-12-19 14:43:18 +00:00
|
|
|
if !g:ale_echo_cursor
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-10-11 22:51:36 +00:00
|
|
|
" Only echo the warnings in normal mode, otherwise we will get problems.
|
|
|
|
if mode() isnot# 'n'
|
2016-10-31 14:47:08 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
call s:StopCursorTimer()
|
2016-09-15 09:57:11 +00:00
|
|
|
|
2016-10-25 15:07:20 +00:00
|
|
|
let l:pos = getcurpos()[0:2]
|
|
|
|
|
|
|
|
" Check the current buffer, line, and column number against the last
|
|
|
|
" recorded position. If the position has actually changed, *then*
|
|
|
|
" we should echo something. Otherwise we can end up doing processing
|
|
|
|
" the echo message far too frequently.
|
|
|
|
if l:pos != s:last_pos
|
2017-10-12 22:25:41 +00:00
|
|
|
let l:delay = ale#Var(bufnr(''), 'echo_delay')
|
|
|
|
|
2016-10-25 15:07:20 +00:00
|
|
|
let s:last_pos = l:pos
|
2017-10-12 22:25:41 +00:00
|
|
|
let s:cursor_timer = timer_start(
|
|
|
|
\ l:delay,
|
|
|
|
\ function('ale#cursor#EchoCursorWarning')
|
|
|
|
\)
|
2016-10-25 15:07:20 +00:00
|
|
|
endif
|
2016-09-15 09:57:11 +00:00
|
|
|
endfunction
|
2017-03-02 07:14:30 +00:00
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
function! ale#cursor#ShowCursorDetail() abort
|
2017-10-11 22:51:36 +00:00
|
|
|
" Only echo the warnings in normal mode, otherwise we will get problems.
|
|
|
|
if mode() isnot# 'n'
|
2017-05-26 20:21:15 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-10-11 22:51:36 +00:00
|
|
|
if ale#ShouldDoNothing(bufnr(''))
|
2017-03-02 07:14:30 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
call s:StopCursorTimer()
|
|
|
|
|
2017-03-03 02:40:07 +00:00
|
|
|
let [l:info, l:loc] = s:FindItemAtCursor()
|
2017-03-02 07:14:30 +00:00
|
|
|
|
2017-03-03 02:40:07 +00:00
|
|
|
if !empty(l:loc)
|
2017-03-03 20:14:03 +00:00
|
|
|
let l:message = get(l:loc, 'detail', l:loc.text)
|
|
|
|
|
2017-11-14 23:25:01 +00:00
|
|
|
call ale#preview#Show(split(l:message, "\n"))
|
2017-11-15 12:00:08 +00:00
|
|
|
execute 'echo'
|
2017-03-02 07:14:30 +00:00
|
|
|
endif
|
|
|
|
endfunction
|