2016-10-03 18:41:02 +00:00
|
|
|
" Author: w0rp <devw0rp@gmail.com>
|
|
|
|
" Description: Echoes lint message for the current line, if any
|
|
|
|
|
2016-10-10 11:53:54 +00:00
|
|
|
" Return a formatted message according to g:ale_echo_msg_format variable
|
|
|
|
function! s:GetMessage(linter, type, text) abort
|
2016-10-10 23:00:09 +00:00
|
|
|
let l:msg = g:ale_echo_msg_format
|
|
|
|
let l:type = a:type ==# 'E'
|
2016-10-10 11:53:54 +00:00
|
|
|
\ ? g:ale_echo_msg_error_str
|
|
|
|
\ : g:ale_echo_msg_warning_str
|
|
|
|
|
|
|
|
" Replace handlers if they exist
|
2016-10-10 23:00:09 +00:00
|
|
|
for [l:k, l:v] in items({'linter': a:linter, 'severity': l:type})
|
|
|
|
let l:msg = substitute(l:msg, '\V%' . l:k . '%', l:v, '')
|
2016-10-10 11:53:54 +00:00
|
|
|
endfor
|
|
|
|
|
2017-05-21 18:51:34 +00:00
|
|
|
return printf(l:msg, a:text)
|
2016-10-10 11:53:54 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
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
|
2017-03-04 23:55:12 +00:00
|
|
|
" Turn shortmess on or off.
|
2017-03-03 20:14:03 +00:00
|
|
|
if a:setting ==# 'on'
|
|
|
|
setlocal shortmess+=T
|
2017-03-04 23:55:12 +00:00
|
|
|
" echomsg is neede for the message to get truncated and appear in
|
|
|
|
" the message history.
|
|
|
|
exec "norm! :echomsg a:message\n"
|
2017-03-03 20:14:03 +00:00
|
|
|
elseif a:setting ==# 'off'
|
|
|
|
setlocal shortmess-=T
|
2017-03-04 23:55:12 +00:00
|
|
|
" Regular echo is needed for printing newline characters.
|
|
|
|
echo a:message
|
2017-03-03 20:14:03 +00:00
|
|
|
else
|
|
|
|
throw 'Invalid setting: ' . string(a:setting)
|
|
|
|
endif
|
|
|
|
finally
|
|
|
|
call setbufvar('%', '&shortmess', l:shortmess_options)
|
|
|
|
endtry
|
|
|
|
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#TruncatedEcho(message) abort
|
2016-10-10 23:00:09 +00:00
|
|
|
let l:message = a: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-03-03 20:14:03 +00:00
|
|
|
call s:EchoWithShortMess('on', l:message)
|
2016-09-08 23:23:26 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-03-03 02:40:07 +00:00
|
|
|
function! s:FindItemAtCursor() abort
|
|
|
|
let l:info = get(g:ale_buffer_info, bufnr('%'), {'loclist': []})
|
|
|
|
let l:pos = getcurpos()
|
|
|
|
let l:index = ale#util#BinarySearch(l:info.loclist, l:pos[1], l:pos[2])
|
|
|
|
let l:loc = l:index >= 0 ? l:info.loclist[l:index] : {}
|
|
|
|
|
|
|
|
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-05-26 15:20:17 +00:00
|
|
|
if ale#ShouldDoNothing()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2016-10-09 11:50:45 +00:00
|
|
|
" Only echo the warnings in normal mode, otherwise we will get problems.
|
|
|
|
if mode() !=# 'n'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
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)
|
2016-10-10 23:00:09 +00:00
|
|
|
let l:msg = s:GetMessage(l:loc.linter_name, l:loc.type, l:loc.text)
|
|
|
|
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-03-03 02:40:07 +00:00
|
|
|
echo
|
2017-03-03 20:14:03 +00:00
|
|
|
let l:info.echoed = 0
|
2016-09-08 23:23:26 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2016-09-15 09:57:11 +00:00
|
|
|
let s:cursor_timer = -1
|
2016-10-25 15:07:20 +00:00
|
|
|
let s:last_pos = [0, 0, 0]
|
2016-09-15 09:57:11 +00:00
|
|
|
|
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-02-14 21:02:49 +00:00
|
|
|
if ale#ShouldDoNothing()
|
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
|
|
|
|
let s:last_pos = l:pos
|
|
|
|
let s:cursor_timer = timer_start(10, function('ale#cursor#EchoCursorWarning'))
|
|
|
|
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-05-26 20:21:15 +00:00
|
|
|
if ale#ShouldDoNothing()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-03-03 02:40:07 +00:00
|
|
|
" Only echo the warnings in normal mode, otherwise we will get problems.
|
2017-03-02 07:14:30 +00:00
|
|
|
if mode() !=# 'n'
|
|
|
|
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)
|
|
|
|
|
|
|
|
call s:EchoWithShortMess('off', l:message)
|
|
|
|
|
|
|
|
" Set the echo marker, so we can clear it by moving the cursor.
|
|
|
|
let l:info.echoed = 1
|
2017-03-02 07:14:30 +00:00
|
|
|
endif
|
|
|
|
endfunction
|