diff options
author | w0rp <devw0rp@gmail.com> | 2017-11-14 10:28:36 +0000 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-11-14 10:28:36 +0000 |
commit | 16e7dc2371f908204e5191c0e9d55626352097af (patch) | |
tree | 04e40db20efea0cf135728c40f658306c9d87cf6 /autoload | |
parent | d8f9aef84a1271633cb4fc7ba7a063e4b922d56b (diff) | |
download | ale-16e7dc2371f908204e5191c0e9d55626352097af.zip |
Fix #1069 Support formatting the loclist messages with g:ale_loclist_msg_format
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale.vim | 28 | ||||
-rw-r--r-- | autoload/ale/cursor.vim | 26 | ||||
-rw-r--r-- | autoload/ale/list.vim | 11 |
3 files changed, 36 insertions, 29 deletions
diff --git a/autoload/ale.vim b/autoload/ale.vim index 15fb53d9..f6c06cf1 100644 --- a/autoload/ale.vim +++ b/autoload/ale.vim @@ -257,3 +257,31 @@ function! ale#Escape(str) abort return shellescape (a:str) endfunction + +" Get the loclist item message according to a given format string. +" +" See `:help g:ale_loclist_msg_format` and `:help g:ale_echo_msg_format` +function! ale#GetLocItemMessage(item, format_string) abort + let l:msg = a:format_string + let l:severity = g:ale_echo_msg_warning_str + let l:code = get(a:item, 'code', '') + let l:type = get(a:item, 'type', 'E') + let l:linter_name = get(a:item, 'linter_name', '') + let l:code_repl = !empty(l:code) ? '\=submatch(1) . l:code . submatch(2)' : '' + + if l:type is# 'E' + let l:severity = g:ale_echo_msg_error_str + elseif l:type is# 'I' + let l:severity = g:ale_echo_msg_info_str + endif + + " 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%', '\=l: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 l:msg +endfunction diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim index 7b848623..1980c194 100644 --- a/autoload/ale/cursor.vim +++ b/autoload/ale/cursor.vim @@ -4,30 +4,6 @@ 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(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:item.type is# 'E' - let l:severity = g:ale_echo_msg_error_str - elseif a:item.type is# 'I' - let l:severity = g:ale_echo_msg_info_str - endif - - " 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 l:msg -endfunction - function! s:EchoWithShortMess(setting, message) abort " We need to remember the setting for shormess and reset it again. let l:shortmess_options = getbufvar('%', '&shortmess') @@ -96,7 +72,7 @@ function! s:EchoImpl() abort let [l:info, l:loc] = s:FindItemAtCursor() if !empty(l:loc) - let l:msg = s:GetMessage(l:loc) + let l:msg = ale#GetLocItemMessage(l:loc, g:ale_echo_msg_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 ecf088ae..fbc71efc 100644 --- a/autoload/ale/list.vim +++ b/autoload/ale/list.vim @@ -41,13 +41,16 @@ function! s:FixList(list) abort 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, + \) + if l:item.bufnr == -1 " If the buffer number is invalid, remove it. - let l:fixed_item = copy(l:item) call remove(l:fixed_item, 'bufnr') - else - " Don't copy the Dictionary if we do not need to. - let l:fixed_item = l:item endif call add(l:new_list, l:fixed_item) |