Add support for nvim's virtualtext on cursor
- Add g:ale_virtualtext_cursor boolean to enable/disable it - Add g:ale_virtualtext_prefix to configure what prefix to use (default: '> ') - Requires neovim 0.3.2's unreleased API `nvim_buf_set_virtual_text`
This commit is contained in:
parent
945dd2fa26
commit
c41dbe2ba9
@ -52,6 +52,29 @@ function! ale#cursor#TruncatedEcho(original_message) abort
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! ale#cursor#ClearVirtualText() abort
|
||||
if !has('nvim-0.3.2')
|
||||
return
|
||||
endif
|
||||
|
||||
let l:buffer = bufnr('')
|
||||
|
||||
call nvim_buf_clear_highlight(l:buffer, 1000, 0, -1)
|
||||
endfunction
|
||||
|
||||
function! ale#cursor#ShowVirtualText(message, hl_group) abort
|
||||
if !has('nvim-0.3.2')
|
||||
return
|
||||
endif
|
||||
|
||||
let l:cursor_position = getcurpos()
|
||||
let l:line = line('.')
|
||||
let l:buffer = bufnr('')
|
||||
let l:prefix = get(g:, 'ale_virtualtext_prefix', '> ')
|
||||
|
||||
call nvim_buf_set_virtual_text(l:buffer, 1000, l:line-1, [[l:prefix.a:message, a:hl_group]], {})
|
||||
endfunction
|
||||
|
||||
function! s:FindItemAtCursor(buffer) abort
|
||||
let l:info = get(g:ale_buffer_info, a:buffer, {})
|
||||
let l:loclist = get(l:info, 'loclist', [])
|
||||
@ -72,7 +95,7 @@ endfunction
|
||||
function! ale#cursor#EchoCursorWarning(...) abort
|
||||
let l:buffer = bufnr('')
|
||||
|
||||
if !g:ale_echo_cursor && !g:ale_cursor_detail
|
||||
if !g:ale_echo_cursor && !g:ale_cursor_detail && !g:ale_virtualtext_cursor
|
||||
return
|
||||
endif
|
||||
|
||||
@ -108,12 +131,30 @@ function! ale#cursor#EchoCursorWarning(...) abort
|
||||
call ale#preview#CloseIfTypeMatches('ale-preview')
|
||||
endif
|
||||
endif
|
||||
|
||||
if g:ale_virtualtext_cursor
|
||||
call ale#cursor#ClearVirtualText()
|
||||
|
||||
if !empty(l:loc)
|
||||
let l:msg = get(l:loc, 'detail', l:loc.text)
|
||||
let l:hl_group = 'ALEInfo'
|
||||
let l:type = get(l:loc, 'type', 'E')
|
||||
|
||||
if l:type is# 'E'
|
||||
let l:hl_group = 'ALEError'
|
||||
elseif l:type is# 'I'
|
||||
let l:hl_group = 'ALEWarning'
|
||||
endif
|
||||
|
||||
call ale#cursor#ShowVirtualText(l:msg, l:hl_group)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#cursor#EchoCursorWarningWithDelay() abort
|
||||
let l:buffer = bufnr('')
|
||||
|
||||
if !g:ale_echo_cursor && !g:ale_cursor_detail
|
||||
if !g:ale_echo_cursor && !g:ale_cursor_detail && !g:ale_virtualtext_cursor
|
||||
return
|
||||
endif
|
||||
|
||||
|
@ -22,14 +22,14 @@ let s:global_variable_list = [
|
||||
\ 'ale_lint_delay',
|
||||
\ 'ale_lint_on_enter',
|
||||
\ 'ale_lint_on_filetype_changed',
|
||||
\ 'ale_lint_on_insert_leave',
|
||||
\ 'ale_lint_on_save',
|
||||
\ 'ale_lint_on_text_changed',
|
||||
\ 'ale_lint_on_insert_leave',
|
||||
\ 'ale_linter_aliases',
|
||||
\ 'ale_linters',
|
||||
\ 'ale_linters_explicit',
|
||||
\ 'ale_list_window_size',
|
||||
\ 'ale_list_vertical',
|
||||
\ 'ale_list_window_size',
|
||||
\ 'ale_loclist_msg_format',
|
||||
\ 'ale_max_buffer_history_size',
|
||||
\ 'ale_max_signs',
|
||||
@ -52,6 +52,8 @@ let s:global_variable_list = [
|
||||
\ 'ale_statusline_format',
|
||||
\ 'ale_type_map',
|
||||
\ 'ale_use_global_executables',
|
||||
\ 'ale_virtualtext_cursor',
|
||||
\ 'ale_virtualtext_prefix',
|
||||
\ 'ale_warn_about_trailing_blank_lines',
|
||||
\ 'ale_warn_about_trailing_whitespace',
|
||||
\]
|
||||
|
@ -298,7 +298,7 @@ function! ale#engine#SetResults(buffer, loclist) abort
|
||||
endif
|
||||
|
||||
if l:linting_is_done
|
||||
if g:ale_echo_cursor
|
||||
if g:ale_echo_cursor || g:ale_virtualtext_cursor
|
||||
" Try and echo the warning now.
|
||||
" This will only do something meaningful if we're in normal mode.
|
||||
call ale#cursor#EchoCursorWarning()
|
||||
|
@ -131,7 +131,7 @@ function! ale#events#Init() abort
|
||||
autocmd InsertLeave * call ale#Queue(0)
|
||||
endif
|
||||
|
||||
if g:ale_echo_cursor || g:ale_cursor_detail
|
||||
if g:ale_echo_cursor || g:ale_cursor_detail || g:ale_virtualtext_cursor
|
||||
autocmd CursorMoved,CursorHold * if exists('*ale#engine#Cleanup') | call ale#cursor#EchoCursorWarningWithDelay() | endif
|
||||
" Look for a warning to echo as soon as we leave Insert mode.
|
||||
" The script's position variable used when moving the cursor will
|
||||
|
24
doc/ale.txt
24
doc/ale.txt
@ -557,6 +557,7 @@ their relevant options.
|
||||
* By setting error highlights. - |g:ale_set_highlights|
|
||||
* By creating signs in the sign column. - |g:ale_set_signs|
|
||||
* By echoing messages based on your cursor. - |g:ale_echo_cursor|
|
||||
* By inline text based on your cursor. - |g:ale_virtualtext_cursor|
|
||||
* By displaying the preview based on your cursor. - |g:ale_cursor_detail|
|
||||
* By showing balloons for your mouse cursor - |g:ale_set_balloons|
|
||||
|
||||
@ -1868,6 +1869,29 @@ g:ale_use_global_executables *g:ale_use_global_executables*
|
||||
options.
|
||||
|
||||
|
||||
g:ale_virtualtext_cursor *g:ale_virtualtext_cursor*
|
||||
|
||||
Type: |Number|
|
||||
Default: `0`
|
||||
|
||||
When this option is set to `1`, a message will be shown when a cursor is
|
||||
near a warning or error. ALE will attempt to find the warning or error at a
|
||||
column nearest to the cursor when the cursor is resting on a line which
|
||||
contains a warning or error. This option can be set to `0` to disable this
|
||||
behavior.
|
||||
|
||||
Messages are only displayed after a short delay. See |g:ale_echo_delay|.
|
||||
|
||||
Messages can be prefixed prefixed with a string. See |g:ale_virtualtext_prefix|.
|
||||
|
||||
|
||||
g:ale_virtualtext_prefix *g:ale_virtualtext_prefix*
|
||||
|
||||
Type: |String|
|
||||
Default: `'> '`
|
||||
|
||||
Prefix to be used with |g:ale_virtualtext_cursor|.
|
||||
|
||||
g:ale_virtualenv_dir_names *g:ale_virtualenv_dir_names*
|
||||
b:ale_virtualenv_dir_names *b:ale_virtualenv_dir_names*
|
||||
|
||||
|
@ -109,6 +109,9 @@ let g:ale_set_highlights = get(g:, 'ale_set_highlights', has('syntax'))
|
||||
" This flag can be set to 0 to disable echoing when the cursor moves.
|
||||
let g:ale_echo_cursor = get(g:, 'ale_echo_cursor', 1)
|
||||
|
||||
" 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 automatically show errors in the preview window.
|
||||
let g:ale_cursor_detail = get(g:, 'ale_cursor_detail', 0)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user