2018-09-14 11:42:26 +00:00
|
|
|
scriptencoding utf-8
|
2016-10-03 18:41:02 +00:00
|
|
|
" Author: w0rp <devw0rp@gmail.com>
|
2018-09-14 11:42:26 +00:00
|
|
|
" Author: João Paulo S. de Souza <joao.paulo.silvasouza@hotmail.com>
|
2016-10-03 18:41:02 +00:00
|
|
|
" Description: Echoes lint message for the current line, if any
|
|
|
|
|
2018-05-28 18:19:20 +00:00
|
|
|
" Controls the milliseconds delay before echoing a message.
|
|
|
|
let g:ale_echo_delay = get(g:, 'ale_echo_delay', 10)
|
|
|
|
" A string format for the echoed message.
|
|
|
|
let g:ale_echo_msg_format = get(g:, 'ale_echo_msg_format', '%code: %%s')
|
|
|
|
|
2017-08-12 09:47:06 +00:00
|
|
|
let s:cursor_timer = -1
|
|
|
|
|
2022-04-01 13:35:07 +00:00
|
|
|
" A wrapper for echon so we can test messages we echo in Vader tests.
|
2022-04-06 01:51:07 +00:00
|
|
|
function! ale#cursor#Echom(message) abort
|
2022-04-01 13:35:07 +00:00
|
|
|
" no-custom-checks
|
2022-04-06 01:51:07 +00:00
|
|
|
exec "norm! :echom a:message\n"
|
2022-04-01 13:35:07 +00:00
|
|
|
endfunction
|
|
|
|
|
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')
|
2022-04-01 12:54:23 +00:00
|
|
|
" Convert indentation groups into single spaces for better legibility when
|
|
|
|
" put on a single line
|
|
|
|
let l:message = substitute(l:message, ' \+', ' ', '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
|
2019-03-07 12:28:36 +00:00
|
|
|
let l:cursor_position = getpos('.')
|
2017-12-19 12:06:08 +00:00
|
|
|
|
2017-12-18 11:22:24 +00:00
|
|
|
" The message is truncated and saved to the history.
|
2019-04-08 10:41:23 +00:00
|
|
|
silent! setlocal shortmess+=T
|
2018-10-11 14:01:27 +00:00
|
|
|
|
|
|
|
try
|
2022-04-06 01:51:07 +00:00
|
|
|
call ale#cursor#Echom(l:message)
|
2018-10-11 14:01:27 +00:00
|
|
|
catch /^Vim\%((\a\+)\)\=:E523/
|
|
|
|
" Fallback into manual truncate (#1987)
|
|
|
|
let l:winwidth = winwidth(0)
|
|
|
|
|
|
|
|
if l:winwidth < strdisplaywidth(l:message)
|
|
|
|
" Truncate message longer than window width with trailing '...'
|
|
|
|
let l:message = l:message[:l:winwidth - 4] . '...'
|
|
|
|
endif
|
|
|
|
|
|
|
|
exec 'echomsg l:message'
|
2020-08-27 12:57:14 +00:00
|
|
|
catch /E481/
|
|
|
|
" Do nothing if running from a visual selection.
|
2018-10-11 14:01:27 +00:00
|
|
|
endtry
|
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.
|
2019-03-07 12:28:36 +00:00
|
|
|
if l:cursor_position != getpos('.')
|
2017-12-19 12:06:08 +00:00
|
|
|
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 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
|
2018-09-14 11:42:26 +00:00
|
|
|
let l:buffer = bufnr('')
|
|
|
|
|
2018-11-07 06:31:35 +00:00
|
|
|
if !g:ale_echo_cursor && !g:ale_cursor_detail
|
2017-12-19 14:43:18 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-10-11 22:51:36 +00:00
|
|
|
" Only echo the warnings in normal mode, otherwise we will get problems.
|
2018-09-03 10:41:54 +00:00
|
|
|
if mode(1) isnot# 'n'
|
2017-05-26 15:20:17 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2018-09-14 11:42:26 +00:00
|
|
|
if ale#ShouldDoNothing(l:buffer)
|
2016-10-09 11:50:45 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2018-11-07 06:31:35 +00:00
|
|
|
let [l:info, l:loc] = ale#util#FindItemAtCursor(l:buffer)
|
2018-09-14 11:42:26 +00:00
|
|
|
|
|
|
|
if g:ale_echo_cursor
|
|
|
|
if !empty(l:loc)
|
|
|
|
let l:format = ale#Var(l:buffer, 'echo_msg_format')
|
|
|
|
let l:msg = ale#GetLocItemMessage(l:loc, l:format)
|
|
|
|
call ale#cursor#TruncatedEcho(l:msg)
|
|
|
|
let l:info.echoed = 1
|
|
|
|
elseif get(l:info, 'echoed')
|
|
|
|
" We'll only clear the echoed message when moving off errors once,
|
|
|
|
" so we don't continually clear the echo line.
|
2022-04-01 13:35:07 +00:00
|
|
|
"
|
|
|
|
" no-custom-checks
|
|
|
|
echo
|
2018-09-14 11:42:26 +00:00
|
|
|
let l:info.echoed = 0
|
|
|
|
endif
|
|
|
|
endif
|
2016-09-14 10:47:52 +00:00
|
|
|
|
2018-09-14 11:42:26 +00:00
|
|
|
if g:ale_cursor_detail
|
|
|
|
if !empty(l:loc)
|
|
|
|
call s:ShowCursorDetailForItem(l:loc, {'stay_here': 1})
|
|
|
|
else
|
|
|
|
call ale#preview#CloseIfTypeMatches('ale-preview')
|
|
|
|
endif
|
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
|
2018-09-14 11:42:26 +00:00
|
|
|
let l:buffer = bufnr('')
|
|
|
|
|
2018-11-07 06:31:35 +00:00
|
|
|
if !g:ale_echo_cursor && !g:ale_cursor_detail
|
2017-12-19 14:43:18 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-10-11 22:51:36 +00:00
|
|
|
" Only echo the warnings in normal mode, otherwise we will get problems.
|
2018-09-03 10:41:54 +00:00
|
|
|
if mode(1) 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
|
|
|
|
2019-03-07 12:28:36 +00:00
|
|
|
let l:pos = getpos('.')[0:2]
|
2016-10-25 15:07:20 +00:00
|
|
|
|
2021-01-14 18:06:20 +00:00
|
|
|
if !exists('w:last_pos')
|
|
|
|
let w:last_pos = [0, 0, 0]
|
|
|
|
endif
|
|
|
|
|
2016-10-25 15:07:20 +00:00
|
|
|
" 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.
|
2021-01-14 18:06:20 +00:00
|
|
|
if l:pos != w:last_pos
|
2018-09-14 11:42:26 +00:00
|
|
|
let l:delay = ale#Var(l:buffer, 'echo_delay')
|
2017-10-12 22:25:41 +00:00
|
|
|
|
2021-01-14 18:06:20 +00:00
|
|
|
let w: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
|
|
|
|
2018-09-14 11:42:26 +00:00
|
|
|
function! s:ShowCursorDetailForItem(loc, options) abort
|
|
|
|
let l:stay_here = get(a:options, 'stay_here', 0)
|
|
|
|
|
|
|
|
let s:last_detailed_line = line('.')
|
|
|
|
let l:message = get(a:loc, 'detail', a:loc.text)
|
|
|
|
let l:lines = split(l:message, "\n")
|
|
|
|
|
2021-01-14 18:06:20 +00:00
|
|
|
if g:ale_floating_preview || g:ale_detail_to_floating_preview
|
|
|
|
call ale#floating_preview#Show(l:lines)
|
|
|
|
else
|
|
|
|
call ale#preview#Show(l:lines, {'stay_here': l:stay_here})
|
|
|
|
|
|
|
|
" Clear the echo message if we manually displayed details.
|
|
|
|
if !l:stay_here
|
2022-04-01 13:35:07 +00:00
|
|
|
" no-custom-checks
|
|
|
|
echo
|
2021-01-14 18:06:20 +00:00
|
|
|
endif
|
2018-09-14 11:42:26 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
function! ale#cursor#ShowCursorDetail() abort
|
2018-09-14 11:42:26 +00:00
|
|
|
let l:buffer = bufnr('')
|
|
|
|
|
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
|
|
|
|
|
2018-09-14 11:42:26 +00:00
|
|
|
if ale#ShouldDoNothing(l:buffer)
|
2017-03-02 07:14:30 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
call s:StopCursorTimer()
|
|
|
|
|
2018-11-07 06:31:35 +00:00
|
|
|
let [l:info, l:loc] = ale#util#FindItemAtCursor(l:buffer)
|
2017-03-02 07:14:30 +00:00
|
|
|
|
2017-03-03 02:40:07 +00:00
|
|
|
if !empty(l:loc)
|
2018-09-14 11:42:26 +00:00
|
|
|
call s:ShowCursorDetailForItem(l:loc, {'stay_here': 0})
|
2017-03-02 07:14:30 +00:00
|
|
|
endif
|
|
|
|
endfunction
|