summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-11-19 23:44:02 +0000
committerw0rp <devw0rp@gmail.com>2017-11-19 23:44:09 +0000
commit597507e5197ef51037d01d30ad819a048eea9c9b (patch)
tree07945599c638ab1bb50097e77f35187fa6938949
parent0cb8130d0e65d9a239c43ddb21d2f89b2815f10d (diff)
downloadale-597507e5197ef51037d01d30ad819a048eea9c9b.zip
Make the message formats configurable with buffer local variables
-rw-r--r--autoload/ale/cursor.vim4
-rw-r--r--autoload/ale/list.vim22
-rw-r--r--doc/ale.txt6
-rw-r--r--test/test_cursor_warnings.vader10
-rw-r--r--test/test_list_formatting.vader24
5 files changed, 53 insertions, 13 deletions
diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim
index 5a1d7789..abe3c5a0 100644
--- a/autoload/ale/cursor.vim
+++ b/autoload/ale/cursor.vim
@@ -69,10 +69,12 @@ function! s:EchoImpl() abort
return
endif
+ let l:buffer = bufnr('')
let [l:info, l:loc] = s:FindItemAtCursor()
if !empty(l:loc)
- let l:msg = ale#GetLocItemMessage(l:loc, g:ale_echo_msg_format)
+ let l:format = ale#Var(l:buffer, 'echo_msg_format')
+ let l:msg = ale#GetLocItemMessage(l:loc, l:format)
call ale#cursor#TruncatedEcho(l:msg)
let l:info.echoed = 1
elseif get(l:info, 'echoed')
diff --git a/autoload/ale/list.vim b/autoload/ale/list.vim
index fbc71efc..b1a8d4a7 100644
--- a/autoload/ale/list.vim
+++ b/autoload/ale/list.vim
@@ -37,16 +37,14 @@ function! ale#list#GetCombinedList() abort
return l:list
endfunction
-function! s:FixList(list) abort
+function! s:FixList(buffer, list) abort
+ let l:format = ale#Var(a:buffer, 'loclist_msg_format')
let l:new_list = []
for l:item in a:list
let l:fixed_item = copy(l:item)
- let l:fixed_item.text = ale#GetLocItemMessage(
- \ l:item,
- \ g:ale_loclist_msg_format,
- \)
+ let l:fixed_item.text = ale#GetLocItemMessage(l:item, l:format)
if l:item.bufnr == -1
" If the buffer number is invalid, remove it.
@@ -70,22 +68,22 @@ function! s:SetListsImpl(timer_id, buffer, loclist) abort
let l:quickfix_list = ale#list#GetCombinedList()
if has('nvim')
- call setqflist(s:FixList(l:quickfix_list), ' ', l:title)
+ call setqflist(s:FixList(a:buffer, l:quickfix_list), ' ', l:title)
else
- call setqflist(s:FixList(l:quickfix_list))
+ call setqflist(s:FixList(a:buffer, l:quickfix_list))
call setqflist([], 'r', {'title': l:title})
endif
elseif g:ale_set_loclist
" If windows support is off, bufwinid() may not exist.
" We'll set result in the current window, which might not be correct,
- " but is better than nothing.
- let l:win_id = s:BufWinId(a:buffer)
+ " but it's better than nothing.
+ let l:id = s:BufWinId(a:buffer)
if has('nvim')
- call setloclist(l:win_id, s:FixList(a:loclist), ' ', l:title)
+ call setloclist(l:id, s:FixList(a:buffer, a:loclist), ' ', l:title)
else
- call setloclist(l:win_id, s:FixList(a:loclist))
- call setloclist(l:win_id, [], 'r', {'title': l:title})
+ call setloclist(l:id, s:FixList(a:buffer, a:loclist))
+ call setloclist(l:id, [], 'r', {'title': l:title})
endif
endif
diff --git a/doc/ale.txt b/doc/ale.txt
index ec201b13..223f16c9 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -646,6 +646,7 @@ g:ale_echo_msg_error_str *g:ale_echo_msg_error_str*
g:ale_echo_msg_format *g:ale_echo_msg_format*
+b:ale_echo_msg_format *b:ale_echo_msg_format*
Type: |String|
Default: `'%code: %%s'`
@@ -672,6 +673,10 @@ g:ale_echo_msg_format *g:ale_echo_msg_format*
|g:ale_echo_cursor| needs to be set to 1 for messages to be displayed.
+ The echo message format can also be configured separately for each buffer,
+ so different formats can be used for differnt languages. (Say in ftplugin
+ files.)
+
g:ale_echo_msg_info_str *g:ale_echo_msg_info_str*
@@ -1017,6 +1022,7 @@ g:ale_linters_explicit *g:ale_linters_explicit*
g:ale_loclist_msg_format *g:ale_loclist_msg_format*
+b:ale_loclist_msg_format *b:ale_loclist_msg_format*
Type: |String|
Default: `g:ale_echo_msg_format`
diff --git a/test/test_cursor_warnings.vader b/test/test_cursor_warnings.vader
index c6dc5269..f112d8dc 100644
--- a/test/test_cursor_warnings.vader
+++ b/test/test_cursor_warnings.vader
@@ -89,6 +89,7 @@ After:
let g:ale_buffer_info = {}
unlet! g:output
+ unlet! b:ale_loclist_msg_format
delfunction GetLastMessage
@@ -212,3 +213,12 @@ Execute(The %code% and %ifcode% should be removed when there's no code):
call ale#cursor#EchoCursorWarning()
AssertEqual 'Some information', GetLastMessage()
+
+Execute(The buffer message format option should take precedence):
+ let g:ale_echo_msg_format = '%(code) %%s'
+ let b:ale_echo_msg_format = 'FOO %s'
+
+ call cursor(1, 14)
+ call ale#cursor#EchoCursorWarning()
+
+ AssertEqual 'FOO Some information', GetLastMessage()
diff --git a/test/test_list_formatting.vader b/test/test_list_formatting.vader
index 6b494fc2..0c52f10f 100644
--- a/test/test_list_formatting.vader
+++ b/test/test_list_formatting.vader
@@ -28,6 +28,7 @@ After:
Restore
unlet! g:loclist
+ unlet! b:ale_loclist_msg_format
delfunction AddItem
@@ -162,3 +163,26 @@ Execute(Formatting with the linter name should work for the quickfix list):
\ },
\ ],
\ getqflist()
+
+Execute(The buffer loclist format option should take precedence):
+ let g:ale_loclist_msg_format = '(%linter%) %s'
+ let b:ale_loclist_msg_format = 'FOO %s'
+
+ call AddItem({'text': 'whatever'})
+ call ale#list#SetLists(bufnr(''), g:loclist)
+
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 1,
+ \ 'bufnr': bufnr(''),
+ \ 'col': 1,
+ \ 'valid': 1,
+ \ 'vcol': 0,
+ \ 'nr': 0,
+ \ 'type': 'E',
+ \ 'pattern': '',
+ \ 'text': 'FOO whatever',
+ \ },
+ \ ],
+ \ getloclist(0)