summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/balloon.vim21
-rw-r--r--doc/ale.txt10
-rw-r--r--plugin/ale.vim15
-rw-r--r--test/test_balloon_messages.vader38
4 files changed, 84 insertions, 0 deletions
diff --git a/autoload/ale/balloon.vim b/autoload/ale/balloon.vim
new file mode 100644
index 00000000..3d179a0d
--- /dev/null
+++ b/autoload/ale/balloon.vim
@@ -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
diff --git a/doc/ale.txt b/doc/ale.txt
index 1e3ac0fb..42868121 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -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|
diff --git a/plugin/ale.vim b/plugin/ale.vim
index 1f9df896..85930f3d 100644
--- a/plugin/ale.vim
+++ b/plugin/ale.vim
@@ -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)
diff --git a/test/test_balloon_messages.vader b/test/test_balloon_messages.vader
new file mode 100644
index 00000000..50dc6af4
--- /dev/null
+++ b/test/test_balloon_messages.vader
@@ -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)