Fix #1404 - Do not show balloons when g:ale_set_balloons is 0. Add b:ale_set_balloons
This commit is contained in:
parent
107516c757
commit
164c711b3d
@ -2,6 +2,13 @@
|
||||
" Description: balloonexpr support for ALE.
|
||||
|
||||
function! ale#balloon#MessageForPos(bufnr, lnum, col) abort
|
||||
" Don't show balloons if they are disabled, or linting is disabled.
|
||||
if !ale#Var(a:bufnr, 'set_balloons')
|
||||
\|| !g:ale_enabled
|
||||
\|| !getbufvar(a:bufnr, 'ale_enabled', 1)
|
||||
return ''
|
||||
endif
|
||||
|
||||
let l:loclist = get(g:ale_buffer_info, a:bufnr, {'loclist': []}).loclist
|
||||
let l:index = ale#util#BinarySearch(l:loclist, a:bufnr, a:lnum, a:col)
|
||||
|
||||
@ -13,7 +20,7 @@ function! ale#balloon#Expr() abort
|
||||
endfunction
|
||||
|
||||
function! ale#balloon#Disable() abort
|
||||
set noballooneval
|
||||
set noballooneval balloonexpr=
|
||||
endfunction
|
||||
|
||||
function! ale#balloon#Enable() abort
|
||||
|
@ -84,10 +84,6 @@ function! s:EnablePreamble() 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
|
||||
endfunction
|
||||
|
||||
function! s:DisablePostamble() abort
|
||||
@ -95,10 +91,6 @@ function! s:DisablePostamble() abort
|
||||
if g:ale_set_highlights
|
||||
call ale#highlight#UpdateHighlights()
|
||||
endif
|
||||
|
||||
if g:ale_set_balloons
|
||||
call ale#balloon#Disable()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:CleanupEveryBuffer() abort
|
||||
@ -121,9 +113,17 @@ function! ale#toggle#Toggle() abort
|
||||
|
||||
if g:ale_enabled
|
||||
call s:EnablePreamble()
|
||||
|
||||
if g:ale_set_balloons
|
||||
call ale#balloon#Enable()
|
||||
endif
|
||||
else
|
||||
call s:CleanupEveryBuffer()
|
||||
call s:DisablePostamble()
|
||||
|
||||
if has('balloon_eval')
|
||||
call ale#balloon#Disable()
|
||||
endif
|
||||
endif
|
||||
|
||||
call ale#toggle#InitAuGroups()
|
||||
|
@ -1291,13 +1291,19 @@ g:ale_pattern_options_enabled *g:ale_pattern_options_enabled*
|
||||
|
||||
|
||||
g:ale_set_balloons *g:ale_set_balloons*
|
||||
*b: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.
|
||||
be displayed. Balloons will not be shown when either |g:ale_enabled| is `0`
|
||||
or |b:ale_enabled| is `0`.
|
||||
|
||||
`b:ale_set_balloons` can be set to `0` to disable balloons for a buffer.
|
||||
Balloons cannot be enabled for a specific buffer when not initially enabled
|
||||
globally.
|
||||
|
||||
|
||||
g:ale_set_highlights *g:ale_set_highlights*
|
||||
|
@ -5,12 +5,14 @@ Before:
|
||||
Save g:ale_run_synchronously
|
||||
Save g:ale_pattern_options
|
||||
Save g:ale_pattern_options_enabled
|
||||
Save g:ale_set_balloons
|
||||
|
||||
let g:ale_set_signs = 1
|
||||
let g:ale_set_lists_synchronously = 1
|
||||
let g:ale_run_synchronously = 1
|
||||
let g:ale_pattern_options = {}
|
||||
let g:ale_pattern_options_enabled = 1
|
||||
let g:ale_set_balloons = has('balloon_eval')
|
||||
|
||||
unlet! b:ale_enabled
|
||||
|
||||
@ -344,3 +346,41 @@ Execute(ALEResetBuffer should reset everything for a buffer):
|
||||
|
||||
AssertEqual 1, g:ale_enabled
|
||||
AssertEqual 1, get(b:, 'ale_enabled', 1)
|
||||
|
||||
Execute(Disabling ALE should disable balloons):
|
||||
" These tests won't run in the console, but we can run them manually in GVim.
|
||||
if has('balloon_eval')
|
||||
call ale#linter#Reset()
|
||||
|
||||
" Enable balloons, so we can check the expr value.
|
||||
call ale#balloon#Enable()
|
||||
|
||||
AssertEqual 1, &ballooneval
|
||||
AssertEqual 'ale#balloon#Expr()', &balloonexpr
|
||||
|
||||
" Toggle ALE off.
|
||||
ALEToggle
|
||||
|
||||
" The balloon settings should be reset.
|
||||
AssertEqual 0, &ballooneval
|
||||
AssertEqual '', &balloonexpr
|
||||
endif
|
||||
|
||||
Execute(Enabling ALE should enable balloons if the setting is on):
|
||||
if has('balloon_eval')
|
||||
call ale#linter#Reset()
|
||||
call ale#balloon#Disable()
|
||||
ALEDisable
|
||||
let g:ale_set_balloons = 0
|
||||
ALEEnable
|
||||
|
||||
AssertEqual 0, &ballooneval
|
||||
AssertEqual '', &balloonexpr
|
||||
|
||||
ALEDisable
|
||||
let g:ale_set_balloons = 1
|
||||
ALEEnable
|
||||
|
||||
AssertEqual 1, &ballooneval
|
||||
AssertEqual 'ale#balloon#Expr()', &balloonexpr
|
||||
endif
|
||||
|
@ -1,21 +1,25 @@
|
||||
Before:
|
||||
Save g:ale_buffer_info
|
||||
Save g:ale_enabled
|
||||
Save g:ale_set_balloons
|
||||
|
||||
let g:ale_buffer_info[347] = {'loclist': [
|
||||
let g:ale_set_balloons = 1
|
||||
|
||||
let g:ale_buffer_info[bufnr('')] = {'loclist': [
|
||||
\ {
|
||||
\ 'bufnr': 347,
|
||||
\ 'bufnr': bufnr(''),
|
||||
\ 'lnum': 1,
|
||||
\ 'col': 10,
|
||||
\ 'text': 'Missing semicolon. (semi)',
|
||||
\ },
|
||||
\ {
|
||||
\ 'bufnr': 347,
|
||||
\ 'bufnr': bufnr(''),
|
||||
\ 'lnum': 2,
|
||||
\ 'col': 10,
|
||||
\ 'text': 'Infix operators must be spaced. (space-infix-ops)'
|
||||
\ },
|
||||
\ {
|
||||
\ 'bufnr': 347,
|
||||
\ 'bufnr': bufnr(''),
|
||||
\ 'lnum': 2,
|
||||
\ 'col': 15,
|
||||
\ 'text': 'Missing radix parameter (radix)'
|
||||
@ -25,17 +29,50 @@ Before:
|
||||
After:
|
||||
Restore
|
||||
|
||||
unlet! b:ale_enabled
|
||||
unlet! b:ale_set_balloons
|
||||
|
||||
Execute(Balloon messages should be shown for the correct lines):
|
||||
AssertEqual
|
||||
\ 'Missing semicolon. (semi)',
|
||||
\ ale#balloon#MessageForPos(347, 1, 1)
|
||||
\ ale#balloon#MessageForPos(bufnr(''), 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)
|
||||
\ ale#balloon#MessageForPos(bufnr(''), 2, 1)
|
||||
|
||||
Execute(Balloon messages should be shown for later columns):
|
||||
AssertEqual
|
||||
\ 'Missing radix parameter (radix)',
|
||||
\ ale#balloon#MessageForPos(347, 2, 16)
|
||||
\ ale#balloon#MessageForPos(bufnr(''), 2, 16)
|
||||
|
||||
Execute(Balloon messages should be disabled if ALE is disabled globally):
|
||||
let g:ale_enabled = 0
|
||||
" Enabling the buffer should not make a difference.
|
||||
let b:ale_enabled = 1
|
||||
|
||||
AssertEqual '', ale#balloon#MessageForPos(bufnr(''), 1, 1)
|
||||
|
||||
Execute(Balloon messages should be disabled if ALE is disabled for a buffer):
|
||||
let b:ale_enabled = 0
|
||||
|
||||
AssertEqual '', ale#balloon#MessageForPos(bufnr(''), 1, 1)
|
||||
|
||||
Execute(Balloon messages should be disabled if the global setting is off):
|
||||
let g:ale_set_balloons = 0
|
||||
|
||||
AssertEqual '', ale#balloon#MessageForPos(bufnr(''), 1, 1)
|
||||
|
||||
Execute(Balloon messages should be disabled if the buffer setting is off):
|
||||
let b:ale_set_balloons = 0
|
||||
|
||||
AssertEqual '', ale#balloon#MessageForPos(bufnr(''), 1, 1)
|
||||
|
||||
Execute(The balloon buffer setting should override the global one):
|
||||
let g:ale_set_balloons = 0
|
||||
let b:ale_set_balloons = 1
|
||||
|
||||
AssertEqual
|
||||
\ 'Missing semicolon. (semi)',
|
||||
\ ale#balloon#MessageForPos(bufnr(''), 1, 1)
|
||||
|
Loading…
Reference in New Issue
Block a user