summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--autoload/ale/balloon.vim21
-rw-r--r--autoload/ale/list.vim28
-rw-r--r--doc/ale.txt45
-rw-r--r--plugin/ale.vim18
-rw-r--r--test/test_balloon_messages.vader38
-rw-r--r--test/test_list_opening.vader69
-rw-r--r--test/test_list_titles.vader63
8 files changed, 261 insertions, 23 deletions
diff --git a/README.md b/README.md
index 0456784f..d5c3e076 100644
--- a/README.md
+++ b/README.md
@@ -486,4 +486,4 @@ still be an advantage.
If you are still concerned, you can turn the automatic linting off altogether,
including the option `g:ale_lint_on_enter`, and you can run ALE manually with
-`:call ale#Lint()`.
+`:ALELint`.
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/autoload/ale/list.vim b/autoload/ale/list.vim
index 63d51ab5..bbe71e3c 100644
--- a/autoload/ale/list.vim
+++ b/autoload/ale/list.vim
@@ -12,18 +12,26 @@ function! ale#list#IsQuickfixOpen() abort
endfunction
function! ale#list#SetLists(buffer, loclist) abort
+ let l:title = expand('#' . a:buffer . ':p')
+
if g:ale_set_quickfix
- call setqflist(a:loclist)
+ if has('nvim')
+ call setqflist(a:loclist, ' ', l:title)
+ else
+ call setqflist(a:loclist)
+ call setqflist([], 'r', {'title': l:title})
+ endif
elseif g:ale_set_loclist
" If windows support is off, bufwinid() may not exist.
- if exists('*bufwinid')
- " Set the results on the window for the buffer.
- call setloclist(bufwinid(str2nr(a:buffer)), a:loclist)
+ " We'll set result in the current window, which might not be correct,
+ " but is better than nothing.
+ let l:win_id = exists('*bufwinid') ? bufwinid(str2nr(a:buffer)) : 0
+
+ if has('nvim')
+ call setloclist(l:win_id, a:loclist, ' ', l:title)
else
- " Set the results in the current window.
- " This may not be the same window we ran the linters for, but
- " it's better than nothing.
- call setloclist(0, a:loclist)
+ call setloclist(l:win_id, a:loclist)
+ call setloclist(l:win_id, [], 'r', {'title': l:title})
endif
endif
@@ -38,9 +46,9 @@ function! ale#list#SetLists(buffer, loclist) abort
if !ale#list#IsQuickfixOpen()
if g:ale_set_quickfix
- copen
+ execute 'copen ' . str2nr(ale#Var(a:buffer, 'list_window_size'))
elseif g:ale_set_loclist
- lopen
+ execute 'lopen ' . str2nr(ale#Var(a:buffer, 'list_window_size'))
endif
endif
diff --git a/doc/ale.txt b/doc/ale.txt
index 1e3ac0fb..707e2a78 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -365,6 +365,19 @@ g:ale_keep_list_window_open *g:ale_keep_list_window_open*
See: |g:ale_open_list|
+g:ale_list_window_size *g:ale_list_window_size*
+ *b:ale_list_window_size*
+ Type: |Number|
+ Default: `10`
+
+ This number configures the number of lines to set for the height of windows
+ opened automatically for ALE problems. The default of `10` matches the Vim
+ default height.
+
+ See |g:ale_open_list| for information on automatically opening windows
+ for quickfix or the loclist.
+
+
g:ale_lint_delay *g:ale_lint_delay*
Type: |Number|
@@ -550,6 +563,8 @@ g:ale_open_list *g:ale_open_list*
including those not set by ALE, unless |g:ale_keep_list_window_open| is set
to `1`, in which case the window will be kept open until closed manually.
+ The window size can be configured with |g:ale_list_window_size|.
+
g:ale_pattern_options *g:ale_pattern_options*
@@ -586,6 +601,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|
@@ -769,11 +794,13 @@ are supported for running the commands.
Synchronous functions and asynchronous jobs will be run in a sequence for
fixing files, and can be combined. For example:
>
- let g:ale_fixers.javascript = [
- \ 'DoSomething',
- \ 'eslint',
- \ {buffer, lines -> filter(lines, 'v:val !=~ ''^\s*//''')},
- \]
+ let g:ale_fixers = {
+ \ 'javascript': [
+ \ 'DoSomething',
+ \ 'eslint',
+ \ {buffer, lines -> filter(lines, 'v:val !=~ ''^\s*//''')},
+ \ ],
+ \}
ALEFix
<
@@ -782,6 +809,12 @@ upon some lines immediately, then run `eslint` from the ALE registry, and
then call a lambda function which will remove every single line comment
from the file.
+For convenience, a plug mapping is defined for |ALEFix|, so you can set up a
+keybind easily for fixing files. >
+
+ " Bind F8 to fixing problems with ALE
+ nmap <F8> <Plug>(ale_fix)
+<
Files can be fixed automatically with the following options, which are all off
by default.
@@ -806,6 +839,8 @@ ALEFix *ALEFix*
Fix problems with the current buffer. See |ale-fix| for more information.
+ A plug mapping `<Plug>(ale_fix)` is defined for this command.
+
ALELint *ALELint*
diff --git a/plugin/ale.vim b/plugin/ale.vim
index 1f9df896..25622318 100644
--- a/plugin/ale.vim
+++ b/plugin/ale.vim
@@ -106,6 +106,9 @@ let g:ale_open_list = get(g:, 'ale_open_list', 0)
" This flag dictates if ale keeps open loclist even if there is no error in loclist
let g:ale_keep_list_window_open = get(g:, 'ale_keep_list_window_open', 0)
+" The window size to set for the quickfix and loclist windows
+call ale#Set('list_window_size', 10)
+
" This flag can be set to 0 to disable setting signs.
" This is enabled by default only if the 'signs' feature exists.
let g:ale_set_signs = get(g:, 'ale_set_signs', has('signs'))
@@ -144,6 +147,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 +273,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 +291,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 +302,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)
diff --git a/test/test_list_opening.vader b/test/test_list_opening.vader
index 6d0164fd..89b14161 100644
--- a/test/test_list_opening.vader
+++ b/test/test_list_opening.vader
@@ -1,6 +1,17 @@
" Author: Yann Fery <yann@fery.me>
-
Before:
+ Save g:ale_set_loclist
+ Save g:ale_set_quickfix
+ Save g:ale_open_list
+ Save g:ale_keep_list_window_open
+ Save g:ale_list_window_size
+
+ let g:ale_set_loclist = 1
+ let g:ale_set_quickfix = 0
+ let g:ale_open_list = 0
+ let g:ale_keep_list_window_open = 0
+ let g:ale_list_window_size = 10
+
let g:loclist = [
\ {'lnum': 5, 'col': 5},
\ {'lnum': 5, 'col': 4},
@@ -8,18 +19,28 @@ Before:
\ {'lnum': 3, 'col': 2},
\]
+ function GetQuickfixHeight() abort
+ for l:win in range(1, winnr('$'))
+ if getwinvar(l:win, '&buftype') ==# 'quickfix'
+ return winheight(l:win)
+ endif
+ endfor
+
+ return 0
+ endfunction
+
After:
+ Restore
+
+ unlet! g:loclist
+ unlet! b:ale_list_window_size
+ delfunction GetQuickfixHeight
+
" Close quickfix window after every execute block
lcl
ccl
- unlet g:loclist
call setloclist(0, [])
call setqflist([])
- " Reset options to their default values.
- let g:ale_set_loclist = 1
- let g:ale_set_quickfix = 0
- let g:ale_open_list = 0
- let g:ale_keep_list_window_open = 0
Execute(IsQuickfixOpen should return the right output):
AssertEqual 0, ale#list#IsQuickfixOpen()
@@ -53,6 +74,22 @@ Execute(The quickfix window should open for just the loclist):
call ale#list#SetLists(bufnr('%'), [])
Assert !ale#list#IsQuickfixOpen()
+Execute(The quickfix window height should be correct for the loclist):
+ let g:ale_open_list = 1
+ let g:ale_list_window_size = 7
+
+ call ale#list#SetLists(bufnr('%'), g:loclist)
+
+ AssertEqual 7, GetQuickfixHeight()
+
+Execute(The quickfix window height should be correct for the loclist with buffer variables):
+ let g:ale_open_list = 1
+ let b:ale_list_window_size = 8
+
+ call ale#list#SetLists(bufnr('%'), g:loclist)
+
+ AssertEqual 8, GetQuickfixHeight()
+
Execute(The quickfix window should stay open for just the loclist):
let g:ale_open_list = 1
let g:ale_keep_list_window_open = 1
@@ -93,3 +130,21 @@ Execute(The quickfix window should stay open for the quickfix list):
call ale#list#SetLists(bufnr('%'), g:loclist)
call ale#list#SetLists(bufnr('%'), [])
Assert ale#list#IsQuickfixOpen()
+
+Execute(The quickfix window height should be correct for the quickfix list):
+ let g:ale_set_quickfix = 1
+ let g:ale_open_list = 1
+ let g:ale_list_window_size = 7
+
+ call ale#list#SetLists(bufnr('%'), g:loclist)
+
+ AssertEqual 7, GetQuickfixHeight()
+
+Execute(The quickfix window height should be correct for the quickfix list with buffer variables):
+ let g:ale_set_quickfix = 1
+ let g:ale_open_list = 1
+ let b:ale_list_window_size = 8
+
+ call ale#list#SetLists(bufnr('%'), g:loclist)
+
+ AssertEqual 8, GetQuickfixHeight()
diff --git a/test/test_list_titles.vader b/test/test_list_titles.vader
new file mode 100644
index 00000000..fe28629d
--- /dev/null
+++ b/test/test_list_titles.vader
@@ -0,0 +1,63 @@
+Before:
+ Save g:ale_set_loclist
+ Save g:ale_set_quickfix
+
+ let g:ale_set_loclist = 0
+ let g:ale_set_quickfix = 0
+
+ silent! cd /testplugin/test
+
+After:
+ Restore
+
+ call setloclist(0, [])
+ call setqflist([])
+
+Execute(The loclist titles should be set appropriately):
+ silent noautocmd file foo
+
+ let g:ale_set_loclist = 1
+
+ call ale#list#SetLists(bufnr(''), [
+ \ {'bufnr': bufnr(''), 'lnum': 5, 'col': 5, 'text': 'x', 'type': 'E'},
+ \])
+
+ AssertEqual [{
+ \ 'lnum': 5,
+ \ 'bufnr': bufnr(''),
+ \ 'col': 5,
+ \ 'text': 'x',
+ \ 'valid': 1,
+ \ 'vcol': 0,
+ \ 'nr': 0,
+ \ 'type': 'E',
+ \ 'pattern': '',
+ \}], getloclist(0)
+
+ if !has('nvim')
+ AssertEqual {'title': getcwd() . '/foo'}, getloclist(0, {'title': ''})
+ endif
+
+Execute(The quickfix titles should be set appropriately):
+ silent noautocmd file foo
+
+ let g:ale_set_quickfix = 1
+
+ call ale#list#SetLists(bufnr(''), [
+ \ {'bufnr': bufnr(''), 'lnum': 5, 'col': 5, 'text': 'x', 'type': 'E'},
+ \])
+ AssertEqual [{
+ \ 'lnum': 5,
+ \ 'bufnr': bufnr(''),
+ \ 'col': 5,
+ \ 'text': 'x',
+ \ 'valid': 1,
+ \ 'vcol': 0,
+ \ 'nr': 0,
+ \ 'type': 'E',
+ \ 'pattern': '',
+ \}], getqflist()
+
+ if !has('nvim')
+ AssertEqual {'title': getcwd() . '/foo'}, getqflist({'title': ''})
+ endif