summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-11-13 00:47:34 +0000
committerw0rp <devw0rp@gmail.com>2017-11-13 00:47:34 +0000
commit584e0bc7f25563bf4ab3ae738b78d9d13a898f94 (patch)
treec128ae1a0336d407b53d8314dbd1c967cd5a0537 /autoload
parent70623ca8a7ffadac0d282b4737dbb7322659c592 (diff)
downloadale-584e0bc7f25563bf4ab3ae738b78d9d13a898f94.zip
#852 Support formatting echo messages with error codes. No linters set the `code` key yet
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/cursor.vim23
1 files changed, 14 insertions, 9 deletions
diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim
index c7c74c9b..7b848623 100644
--- a/autoload/ale/cursor.vim
+++ b/autoload/ale/cursor.vim
@@ -5,22 +5,27 @@ let s:cursor_timer = -1
let s:last_pos = [0, 0, 0]
" Return a formatted message according to g:ale_echo_msg_format variable
-function! s:GetMessage(linter, type, text) abort
+function! s:GetMessage(item) abort
let l:msg = g:ale_echo_msg_format
let l:severity = g:ale_echo_msg_warning_str
+ let l:code = get(a:item, 'code', '')
+ let l:code_repl = !empty(l:code) ? '\=submatch(1) . l:code . submatch(2)' : ''
- if a:type is# 'E'
+ if a:item.type is# 'E'
let l:severity = g:ale_echo_msg_error_str
- elseif a:type is# 'I'
+ elseif a:item.type is# 'I'
let l:severity = g:ale_echo_msg_info_str
endif
- " Replace handlers if they exist
- for [l:k, l:v] in items({'linter': a:linter, 'severity': l:severity})
- let l:msg = substitute(l:msg, '\V%' . l:k . '%', l:v, '')
- endfor
+ " Replace special markers with certain information.
+ " \=l:variable is used to avoid escaping issues.
+ let l:msg = substitute(l:msg, '\V%severity%', '\=l:severity', 'g')
+ let l:msg = substitute(l:msg, '\V%linter%', '\=a:item.linter_name', 'g')
+ let l:msg = substitute(l:msg, '\v\%([^\%]*)code([^\%]*)\%', l:code_repl, 'g')
+ " Replace %s with the text.
+ let l:msg = substitute(l:msg, '\V%s', '\=a:item.text', 'g')
- return printf(l:msg, a:text)
+ return l:msg
endfunction
function! s:EchoWithShortMess(setting, message) abort
@@ -91,7 +96,7 @@ function! s:EchoImpl() abort
let [l:info, l:loc] = s:FindItemAtCursor()
if !empty(l:loc)
- let l:msg = s:GetMessage(l:loc.linter_name, l:loc.type, l:loc.text)
+ let l:msg = s:GetMessage(l:loc)
call ale#cursor#TruncatedEcho(l:msg)
let l:info.echoed = 1
elseif get(l:info, 'echoed')