diff options
author | w0rp <devw0rp@gmail.com> | 2020-08-04 20:07:46 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2020-08-04 20:11:49 +0100 |
commit | acf892c4d14ee73c570527d86cecfc14c84360a9 (patch) | |
tree | 1d6669e80c836419e3eadf5c06f4082ff3b37af0 | |
parent | 316c7c7372ad6f34e439944713655ccff2123f40 (diff) | |
download | ale-acf892c4d14ee73c570527d86cecfc14c84360a9.zip |
#1532 - Display hover information on CursorHold
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | autoload/ale/events.vim | 4 | ||||
-rw-r--r-- | autoload/ale/hover.vim | 13 | ||||
-rw-r--r-- | doc/ale.txt | 24 | ||||
-rw-r--r-- | plugin/ale.vim | 3 | ||||
-rw-r--r-- | test/test_autocmd_commands.vader | 28 |
6 files changed, 73 insertions, 2 deletions
@@ -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. diff --git a/autoload/ale/events.vim b/autoload/ale/events.vim index da554ef9..731e36f2 100644 --- a/autoload/ale/events.vim +++ b/autoload/ale/events.vim @@ -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 diff --git a/autoload/ale/hover.vim b/autoload/ale/hover.vim index 8fdd288c..79c94266 100644 --- a/autoload/ale/hover.vim +++ b/autoload/ale/hover.vim @@ -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('') diff --git a/doc/ale.txt b/doc/ale.txt index 8c6f5e61..94e6978d 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -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` diff --git a/plugin/ale.vim b/plugin/ale.vim index e1ddf7b7..65c5a77c 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -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) diff --git a/test/test_autocmd_commands.vader b/test/test_autocmd_commands.vader index 355b4c77..a69333d4 100644 --- a/test/test_autocmd_commands.vader +++ b/test/test_autocmd_commands.vader @@ -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,30 @@ 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_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 = 0 + + 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>'')))', + \ ], + \ 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_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,12 +129,14 @@ 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 = 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') |