Add support for showing Info severities in echoed messages

This commit is contained in:
w0rp 2017-11-12 23:19:26 +00:00
parent 7d056b0839
commit 70623ca8a7
4 changed files with 62 additions and 5 deletions

View File

@ -7,12 +7,16 @@ let s:last_pos = [0, 0, 0]
" Return a formatted message according to g:ale_echo_msg_format variable " Return a formatted message according to g:ale_echo_msg_format variable
function! s:GetMessage(linter, type, text) abort function! s:GetMessage(linter, type, text) abort
let l:msg = g:ale_echo_msg_format let l:msg = g:ale_echo_msg_format
let l:type = a:type is# 'E' let l:severity = g:ale_echo_msg_warning_str
\ ? g:ale_echo_msg_error_str
\ : g:ale_echo_msg_warning_str if a:type is# 'E'
let l:severity = g:ale_echo_msg_error_str
elseif a:type is# 'I'
let l:severity = g:ale_echo_msg_info_str
endif
" Replace handlers if they exist " Replace handlers if they exist
for [l:k, l:v] in items({'linter': a:linter, 'severity': l:type}) for [l:k, l:v] in items({'linter': a:linter, 'severity': l:severity})
let l:msg = substitute(l:msg, '\V%' . l:k . '%', l:v, '') let l:msg = substitute(l:msg, '\V%' . l:k . '%', l:v, '')
endfor endfor

View File

@ -660,6 +660,14 @@ 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. |g:ale_echo_cursor| needs to be set to 1 for messages to be displayed.
g:ale_echo_msg_info_str *g:ale_echo_msg_info_str*
Type: |String|
Default: `'Info'`
The string used for `%severity%` for info. See |g:ale_echo_msg_format|
g:ale_echo_msg_warning_str *g:ale_echo_msg_warning_str* g:ale_echo_msg_warning_str *g:ale_echo_msg_warning_str*
Type: |String| Type: |String|

View File

@ -155,6 +155,7 @@ let g:ale_echo_msg_format = get(g:, 'ale_echo_msg_format', '%s')
" Strings used for severity in the echoed message " 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_error_str = get(g:, 'ale_echo_msg_error_str', 'Error')
let g:ale_echo_msg_info_str = get(g:, 'ale_echo_msg_info_str', 'Info')
let g:ale_echo_msg_warning_str = get(g:, 'ale_echo_msg_warning_str', 'Warning') 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. " This flag can be set to 0 to disable echoing when the cursor moves.

View File

@ -1,4 +1,6 @@
Before: Before:
Save g:ale_echo_msg_format
let g:ale_buffer_info = { let g:ale_buffer_info = {
\ bufnr('%'): { \ bufnr('%'): {
\ 'loclist': [ \ 'loclist': [
@ -14,6 +16,16 @@ Before:
\ 'detail': "Every statement should end with a semicolon\nsecond line" \ 'detail': "Every statement should end with a semicolon\nsecond line"
\ }, \ },
\ { \ {
\ 'lnum': 1,
\ 'col': 14,
\ 'bufnr': bufnr('%'),
\ 'vcol': 0,
\ 'linter_name': 'eslint',
\ 'nr': -1,
\ 'type': 'I',
\ 'text': 'Some information',
\ },
\ {
\ 'lnum': 2, \ 'lnum': 2,
\ 'col': 10, \ 'col': 10,
\ 'bufnr': bufnr('%'), \ 'bufnr': bufnr('%'),
@ -63,6 +75,8 @@ Before:
endfunction endfunction
After: After:
Restore
call cursor(1, 1) call cursor(1, 1)
let g:ale_set_loclist = 1 let g:ale_set_loclist = 1
@ -81,7 +95,7 @@ After:
echomsg '' echomsg ''
Given javascript(A Javscript file with warnings/errors): Given javascript(A Javscript file with warnings/errors):
var x = 3 var x = 3 + 12345678
var x = 5*2 + parseInt("10"); var x = 5*2 + parseInt("10");
// comment // comment
@ -141,3 +155,33 @@ Execute(ALEDetail should not capitlise cursor messages):
call ale#cursor#EchoCursorWarning() call ale#cursor#EchoCursorWarning()
AssertEqual 'lowercase error', GetLastMessage() AssertEqual 'lowercase error', GetLastMessage()
Execute(The linter name should be formatted into the message correctly):
let g:ale_echo_msg_format = '%linter%: %s'
call cursor(2, 9)
call ale#cursor#EchoCursorWarning()
AssertEqual
\ 'eslint: Infix operators must be spaced. (space-infix-ops)',
\ GetLastMessage()
Execute(The severity should be formatted into the message correctly):
let g:ale_echo_msg_format = '%severity%: %s'
call cursor(2, 9)
call ale#cursor#EchoCursorWarning()
AssertEqual
\ 'Warning: Infix operators must be spaced. (space-infix-ops)',
\ GetLastMessage()
call cursor(1, 10)
call ale#cursor#EchoCursorWarning()
AssertEqual 'Error: Missing semicolon. (semi)', GetLastMessage()
call cursor(1, 14)
call ale#cursor#EchoCursorWarning()
AssertEqual 'Info: Some information', GetLastMessage()