Fix #537 - Add support for balloons

This commit is contained in:
w0rp 2017-05-31 22:04:33 +01:00
parent 5e4c302b5b
commit 735a6a2a88
4 changed files with 84 additions and 0 deletions

21
autoload/ale/balloon.vim Normal file
View File

@ -0,0 +1,21 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: balloonexpr support for ALE.
function! ale#balloon#MessageForPos(bufnr, lnum, col) abort
let l:loclist = get(g:ale_buffer_info, a:bufnr, {'loclist': []}).loclist
let l:index = ale#util#BinarySearch(l:loclist, a:lnum, a:col)
return l:index >= 0 ? l:loclist[l:index].text : ''
endfunction
function! ale#balloon#Expr() abort
return ale#balloon#MessageForPos(v:beval_bufnr, v:beval_lnum, v:beval_col)
endfunction
function! ale#balloon#Disable() abort
set noballooneval
endfunction
function! ale#balloon#Enable() abort
set ballooneval balloonexpr=ale#balloon#Expr()
endfunction

View File

@ -586,6 +586,16 @@ g:ale_pattern_options_enabled *g:ale_pattern_options_enabled*
for |g:ale_pattern_options| will turn this option on.
g:ale_set_balloons *g:ale_set_balloons*
Type: |Number|
Default: `has('balloon_eval')`
When this option is set to `1`, balloon messages will be displayed for
problems. Problems nearest to the cursor on the line the cursor is over will
be displayed.
g:ale_set_highlights *g:ale_set_highlights*
Type: |Number|

View File

@ -144,6 +144,9 @@ let g:ale_echo_msg_warning_str = get(g:, 'ale_echo_msg_warning_str', 'Warning')
" 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 0 to disable balloon support.
call ale#Set('set_balloons', has('balloon_eval'))
" A deprecated setting for ale#statusline#Status()
" See :help ale#statusline#Count() for getting status reports.
let g:ale_statusline_format = get(g:, 'ale_statusline_format',
@ -267,6 +270,10 @@ function! s:ALEToggle() abort
" Lint immediately, including running linters against the file.
call ale#Queue(0, 'lint_file')
if g:ale_set_balloons
call ale#balloon#Enable()
endif
else
" Make sure the buffer number is a number, not a string,
" otherwise things can go wrong.
@ -281,6 +288,10 @@ function! s:ALEToggle() abort
if g:ale_set_highlights
call ale#highlight#UpdateHighlights()
endif
if g:ale_set_balloons
call ale#balloon#Disable()
endif
endif
call ALEInitAuGroups()
@ -288,6 +299,10 @@ endfunction
call ALEInitAuGroups()
if g:ale_set_balloons
call ale#balloon#Enable()
endif
" Define commands for moving through warnings and errors.
command! -bar ALEPrevious :call ale#loclist_jumping#Jump('before', 0)
command! -bar ALEPreviousWrap :call ale#loclist_jumping#Jump('before', 1)

View File

@ -0,0 +1,38 @@
Before:
Save g:ale_buffer_info
let g:ale_buffer_info[347] = {'loclist': [
\ {
\ 'lnum': 1,
\ 'col': 10,
\ 'text': 'Missing semicolon. (semi)',
\ },
\ {
\ 'lnum': 2,
\ 'col': 10,
\ 'text': 'Infix operators must be spaced. (space-infix-ops)'
\ },
\ {
\ 'lnum': 2,
\ 'col': 15,
\ 'text': 'Missing radix parameter (radix)'
\ },
\]}
After:
Restore
Execute(Balloon messages should be shown for the correct lines):
AssertEqual
\ 'Missing semicolon. (semi)',
\ ale#balloon#MessageForPos(347, 1, 1)
Execute(Balloon messages should be shown for earlier columns):
AssertEqual
\ 'Infix operators must be spaced. (space-infix-ops)',
\ ale#balloon#MessageForPos(347, 2, 1)
Execute(Balloon messages should be shown for later columns):
AssertEqual
\ 'Missing radix parameter (radix)',
\ ale#balloon#MessageForPos(347, 2, 16)