#1532 - Display hover information on CursorHold

This commit is contained in:
w0rp 2020-08-04 20:07:46 +01:00
parent 316c7c7372
commit acf892c4d1
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
6 changed files with 73 additions and 2 deletions

View File

@ -231,6 +231,9 @@ ALE supports "hover" information for printing brief information about symbols at
the cursor taken from Language Server Protocol linters and `tsserver` with the
`ALEHover` command.
Truncated information will be displayed when the cursor rests on a symbol by
default, as long as there are no problems on the same line.
The information can be displayed in a `balloon` tooltip in Vim or GVim by
hovering your mouse over symbols. Mouse hovering is enabled by default in GVim,
and needs to be configured for Vim 8.1+ in terminals.

View File

@ -147,6 +147,10 @@ function! ale#events#Init() abort
autocmd InsertLeave * if exists('*ale#engine#Cleanup') | call ale#virtualtext#ShowCursorWarning() | endif
endif
if g:ale_hover_cursor
autocmd CursorHold * if exists('*ale#lsp#Send') | call ale#hover#ShowTruncatedMessageAtCursor() | endif
endif
if g:ale_close_preview_on_insert
autocmd InsertEnter * if exists('*ale#preview#CloseIfTypeMatches') | call ale#preview#CloseIfTypeMatches('ale-preview') | endif
endif

View File

@ -42,6 +42,8 @@ function! ale#hover#HandleTSServerResponse(conn_id, response) abort
\&& exists('*balloon_show')
\&& ale#Var(l:options.buffer, 'set_balloons')
call balloon_show(a:response.body.displayString)
elseif get(l:options, 'truncated_echo', 0)
call ale#cursor#TruncatedEcho(split(a:response.body.displayString, "\n")[0])
elseif g:ale_hover_to_preview
call ale#preview#Show(split(a:response.body.displayString, "\n"), {
\ 'filetype': 'ale-preview.message',
@ -156,6 +158,7 @@ function! s:OnReady(line, column, opt, linter, lsp_details) abort
\ 'column': l:column,
\ 'hover_from_balloonexpr': get(a:opt, 'called_from_balloonexpr', 0),
\ 'show_documentation': get(a:opt, 'show_documentation', 0),
\ 'truncated_echo': get(a:opt, 'truncated_echo', 0),
\}
endfunction
@ -189,6 +192,16 @@ function! ale#hover#ShowAtCursor() abort
call ale#hover#Show(l:buffer, l:pos[1], l:pos[2], {})
endfunction
function! ale#hover#ShowTruncatedMessageAtCursor() abort
let l:buffer = bufnr('')
let [l:info, l:loc] = ale#util#FindItemAtCursor(l:buffer)
if empty(l:loc)
let l:pos = getpos('.')
call ale#hover#Show(l:buffer, l:pos[1], l:pos[2], {'truncated_echo': 1})
endif
endfunction
" This function implements the :ALEDocumentation command.
function! ale#hover#ShowDocumentationAtCursor() abort
let l:buffer = bufnr('')

View File

@ -516,6 +516,10 @@ at the cursor taken from LSP linters. The following commands are supported:
|ALEHover| - Print information about the symbol at the cursor.
Truncated information will be displayed when the cursor rests on a symbol by
default, as long as there are no problems on the same line. You can disable
this behavior by setting |g:ale_hover_cursor| to `0`.
If |g:ale_set_balloons| is set to `1` and your version of Vim supports the
|balloon_show()| function, then "hover" information also show up when you move
the mouse over a symbol in a buffer. Diagnostic information will take priority
@ -1048,9 +1052,27 @@ g:ale_history_log_output *g:ale_history_log_output*
if you want to save on some memory usage.
g:ale_hover_cursor *g:ale_hover_cursor*
Type: |Number|
Default: `1`
If set to `1`, ALE will show truncated information in the echo line about
the symbol at the cursor automatically when the |CursorHold| event is fired.
The delay before requesting hover information is based on 'updatetime', as
with all |CursorHold| events.
If there's a problem on the line where the cursor is resting, ALE will not
show any hover information.
See |ale-hover| for more information on hover information.
This setting must be set to `1` before ALE is loaded for this behavior
to be enabled. See |ale-lint-settings-on-startup|.
g:ale_hover_to_preview *g:ale_hover_to_preview*
*b:ale_hover_to_preview*
Type: |Number|
Default: `0`

View File

@ -121,6 +121,9 @@ let g:ale_cursor_detail = get(g:, 'ale_cursor_detail', 0)
" This flag can be set to 1 to enable virtual text when the cursor moves.
let g:ale_virtualtext_cursor = get(g:, 'ale_virtualtext_cursor', 0)
" This flag can be set to 1 to enable LSP hover messages at the cursor.
let g:ale_hover_cursor = get(g:, 'ale_hover_cursor', 1)
" This flag can be set to 1 to automatically close the preview window upon
" entering Insert Mode.
let g:ale_close_preview_on_insert = get(g:, 'ale_close_preview_on_insert', 0)

View File

@ -49,6 +49,7 @@ Before:
Save g:ale_lint_on_save
Save g:ale_lint_on_text_changed
Save g:ale_pattern_options_enabled
Save g:ale_hover_cursor
" Turn everything on by defaul for these tests.
let g:ale_completion_enabled = 1
@ -61,6 +62,7 @@ Before:
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 1
let g:ale_pattern_options_enabled = 1
let g:ale_hover_cursor = 1
After:
delfunction CheckAutocmd
@ -84,6 +86,7 @@ Execute (All events should be set up when everything is on):
\ 'BufWinEnter * call ale#events#LintOnEnter(str2nr(expand(''<abuf>'')))',
\ 'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
\ 'CursorHold * if exists(''*ale#engine#Cleanup'') | call ale#cursor#EchoCursorWarningWithDelay() | endif',
\ 'CursorHold if exists(''*ale#lsp#Send'') | call ale#hover#ShowTruncatedMessageAtCursor() | endif',
\ 'CursorMoved * if exists(''*ale#engine#Cleanup'') | call ale#cursor#EchoCursorWarningWithDelay() | endif',
\ 'FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand(''<abuf>'')))',
\ 'FileType * call ale#events#FileTypeEvent( str2nr(expand(''<abuf>'')), expand(''<amatch>''))',
@ -95,9 +98,9 @@ Execute (All events should be set up when everything is on):
\ CheckAutocmd('ALEEvents')
Execute (Only the required events should be bound even if various settings are off):
let g:ale_enabled = 1
let g:ale_completion_enabled = 0
let g:ale_echo_cursor = 0
let g:ale_enabled = 0
let g:ale_fix_on_save = 0
let g:ale_lint_on_enter = 0
let g:ale_lint_on_filetype_changed = 0
@ -105,6 +108,7 @@ Execute (Only the required events should be bound even if various settings are o
let g:ale_lint_on_save = 0
let g:ale_lint_on_text_changed = 0
let g:ale_pattern_options_enabled = 0
let g:ale_hover_cursor = 0
AssertEqual
\ [
@ -114,6 +118,28 @@ Execute (Only the required events should be bound even if various settings are o
\ ],
\ CheckAutocmd('ALEEvents')
Execute (The cursor hoever event should be enabled with g:ale_hover_cursor = 1):
let g:ale_enabled = 1
let g:ale_completion_enabled = 0
let g:ale_echo_cursor = 0
let g:ale_fix_on_save = 0
let g:ale_lint_on_enter = 0
let g:ale_lint_on_filetype_changed = 0
let g:ale_lint_on_insert_leave = 0
let g:ale_lint_on_save = 0
let g:ale_lint_on_text_changed = 0
let g:ale_pattern_options_enabled = 0
let g:ale_hover_cursor = 1
AssertEqual
\ [
\ 'BufEnter * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
\ 'BufReadPost * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
\ 'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
\ 'CursorHold * if exists(''*ale#lsp#Send'') | call ale#hover#ShowTruncatedMessageAtCursor() | endif',
\ ],
\ CheckAutocmd('ALEEvents')
Execute (g:ale_lint_on_text_changed = 1 bind both events):
let g:ale_lint_on_text_changed = 1