Merge remote-tracking branch 'origin/echo-string-format'

This commit is contained in:
w0rp
2016-10-10 12:57:27 +01:00
8 changed files with 104 additions and 11 deletions

View File

@@ -48,3 +48,12 @@ let g:ale_sign_column_always = get(g:, 'ale_sign_column_always', 0)
let g:ale_statusline_format = get(g:, 'ale_statusline_format',
\ ['%d error(s)', '%d warning(s)', 'OK']
\)
" String format for the echoed message
" A %s is mandatory
" It can contain 2 handlers: %linter%, %severity%
let g:ale_echo_msg_format = get(g:, 'ale_echo_msg_format', '%s')
" Strings used for severity in the echoed message
let g:ale_echo_msg_error_str = get(g:, 'ale_echo_msg_error_str', 'Error')
let g:ale_echo_msg_warning_str = get(g:, 'ale_echo_msg_warning_str', 'Warning')

View File

@@ -7,6 +7,23 @@ endif
let g:loaded_ale_cursor = 1
" Return a formatted message according to g:ale_echo_msg_format variable
function! s:GetMessage(linter, type, text) abort
let msg = g:ale_echo_msg_format
let type = a:type ==# 'E'
\ ? g:ale_echo_msg_error_str
\ : g:ale_echo_msg_warning_str
" Capitalize the 1st character
let text = toupper(a:text[0]) . a:text[1:-1]
" Replace handlers if they exist
for [k, v] in items({'linter': a:linter, 'severity': type})
let msg = substitute(msg, '\V%' . k . '%', v, '')
endfor
return printf(msg, text)
endfunction
" This function will perform a binary search to find a message from the
" loclist to echo when the cursor moves.
function! s:BinarySearch(loclist, line, column)
@@ -81,7 +98,9 @@ function! ale#cursor#EchoCursorWarning(...)
let index = s:BinarySearch(loclist, pos[1], pos[2])
if index >= 0
call ale#cursor#TruncatedEcho(loclist[index]['text'])
let l = loclist[index]
let msg = s:GetMessage(l.linter_name, l.type, l.text)
call ale#cursor#TruncatedEcho(msg)
else
echo
endif

View File

@@ -137,6 +137,11 @@ function! s:HandleExit(job)
" Make some adjustments to the loclists to fix common problems.
call s:FixLoclist(buffer, linter_loclist)
" Remember which linter returned these items for later use.
for obj in linter_loclist
let obj.linter_name = linter.name
endfor
if g:ale_buffer_should_reset_map[buffer]
let g:ale_buffer_should_reset_map[buffer] = 0
let g:ale_buffer_loclist_map[buffer] = []