Merge pull request #374 from jwoudenberg/master
WIP: Add support for error details
This commit is contained in:
commit
1f211dbe3e
@ -25,6 +25,7 @@ function! ale_linters#elm#make#Handle(buffer, lines) abort
|
||||
\ 'col': l:error.region.start.column,
|
||||
\ 'type': (l:error.type ==? 'error') ? 'E' : 'W',
|
||||
\ 'text': l:error.overview,
|
||||
\ 'detail': l:error.overview . "\n\n" . l:error.details
|
||||
\})
|
||||
endif
|
||||
endfor
|
||||
|
@ -38,34 +38,32 @@ function! ale#cursor#TruncatedEcho(message) abort
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! s:FindItemAtCursor() abort
|
||||
let l:info = get(g:ale_buffer_info, bufnr('%'), {'loclist': []})
|
||||
let l:pos = getcurpos()
|
||||
let l:index = ale#util#BinarySearch(l:info.loclist, l:pos[1], l:pos[2])
|
||||
let l:loc = l:index >= 0 ? l:info.loclist[l:index] : {}
|
||||
|
||||
return [l:info, l:loc]
|
||||
endfunction
|
||||
|
||||
function! ale#cursor#EchoCursorWarning(...) abort
|
||||
" Only echo the warnings in normal mode, otherwise we will get problems.
|
||||
if mode() !=# 'n'
|
||||
return
|
||||
endif
|
||||
|
||||
let l:buffer = bufnr('%')
|
||||
let [l:info, l:loc] = s:FindItemAtCursor()
|
||||
|
||||
if !has_key(g:ale_buffer_info, l:buffer)
|
||||
return
|
||||
endif
|
||||
|
||||
let l:pos = getcurpos()
|
||||
let l:loclist = g:ale_buffer_info[l:buffer].loclist
|
||||
let l:index = ale#util#BinarySearch(l:loclist, l:pos[1], l:pos[2])
|
||||
|
||||
if l:index >= 0
|
||||
let l:loc = l:loclist[l:index]
|
||||
if !empty(l:loc)
|
||||
let l:msg = s:GetMessage(l:loc.linter_name, l:loc.type, l:loc.text)
|
||||
call ale#cursor#TruncatedEcho(l:msg)
|
||||
let g:ale_buffer_info[l:buffer].echoed = 1
|
||||
else
|
||||
let l:info.echoed = 1
|
||||
elseif get(l:info, 'echoed')
|
||||
" We'll only clear the echoed message when moving off errors once,
|
||||
" so we don't continually clear the echo line.
|
||||
if get(g:ale_buffer_info[l:buffer], 'echoed')
|
||||
echo
|
||||
let g:ale_buffer_info[l:buffer].echoed = 0
|
||||
endif
|
||||
let l:info.echoed = 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@ -93,3 +91,20 @@ function! ale#cursor#EchoCursorWarningWithDelay() abort
|
||||
let s:cursor_timer = timer_start(10, function('ale#cursor#EchoCursorWarning'))
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#cursor#ShowCursorDetail(...) abort
|
||||
" Only echo the warnings in normal mode, otherwise we will get problems.
|
||||
if mode() !=# 'n'
|
||||
return
|
||||
endif
|
||||
|
||||
let [l:info, l:loc] = s:FindItemAtCursor()
|
||||
|
||||
if !empty(l:loc)
|
||||
if has_key(l:loc, 'detail')
|
||||
echo l:loc.detail
|
||||
else
|
||||
echo l:loc.text
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
@ -338,6 +338,10 @@ function! ale#engine#FixLocList(buffer, linter, loclist) abort
|
||||
\ 'linter_name': a:linter.name,
|
||||
\}
|
||||
|
||||
if has_key(l:old_item, 'detail')
|
||||
let l:item.detail = l:old_item.detail
|
||||
endif
|
||||
|
||||
if l:item.lnum == 0
|
||||
" When errors appear at line 0, put them at line 1 instead.
|
||||
let l:item.lnum = 1
|
||||
|
@ -1173,6 +1173,14 @@ ALEToggle *ALEToggle*
|
||||
quickfix items, signs, current jobs, etc. Calling this option will change
|
||||
the |g:ale_enabled| variable.
|
||||
|
||||
|
||||
ALEDetail *ALEDetail*
|
||||
|
||||
Show the full linter message for the current line. This will only have an
|
||||
effect on lines that contain a linter message.
|
||||
|
||||
A plug mapping `<Plug>(ale_detail)` is defined for this command.
|
||||
|
||||
===============================================================================
|
||||
7. API *ale-api*
|
||||
|
||||
|
@ -212,6 +212,9 @@ command! ALEPreviousWrap :call ale#loclist_jumping#Jump('before', 1)
|
||||
command! ALENext :call ale#loclist_jumping#Jump('after', 0)
|
||||
command! ALENextWrap :call ale#loclist_jumping#Jump('after', 1)
|
||||
|
||||
" A command for showing error details.
|
||||
command! ALEDetail :call ale#cursor#ShowCursorDetail()
|
||||
|
||||
" A command for turning ALE on or off.
|
||||
command! ALEToggle :call s:ALEToggle()
|
||||
" A command for linting manually.
|
||||
@ -229,6 +232,7 @@ nnoremap <silent> <Plug>(ale_next) :ALENext<Return>
|
||||
nnoremap <silent> <Plug>(ale_next_wrap) :ALENextWrap<Return>
|
||||
nnoremap <silent> <Plug>(ale_toggle) :ALEToggle<Return>
|
||||
nnoremap <silent> <Plug>(ale_lint) :ALELint<Return>
|
||||
nnoremap <silent> <Plug>(ale_detail) :ALEDetail<Return>
|
||||
|
||||
" Housekeeping
|
||||
|
||||
|
@ -10,7 +10,8 @@ Before:
|
||||
\ 'nr': -1,
|
||||
\ 'type': 'E',
|
||||
\ 'col': 10,
|
||||
\ 'text': 'Missing semicolon. (semi)'
|
||||
\ 'text': 'Missing semicolon. (semi)',
|
||||
\ 'detail': 'Every statement should end with a semicolon'
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 2,
|
||||
@ -123,3 +124,25 @@ Then(Check the cursor output):
|
||||
let g:lines = split(g:output, "\n")
|
||||
|
||||
AssertEqual 'Infix operators must be spaced. (space-infix-ops)', g:lines[-1]
|
||||
|
||||
Execute(Evaluate the cursor detail function at line 1):
|
||||
:1
|
||||
call ale#cursor#ShowCursorDetail()
|
||||
|
||||
Then(Check the cursor output):
|
||||
redir => g:output
|
||||
:mess
|
||||
redir END
|
||||
|
||||
AssertEqual "Every statement should end with a semicolon", g:lines[-1]
|
||||
|
||||
Execute(Evaluate the cursor detail function at line 2):
|
||||
:2
|
||||
call ale#cursor#ShowCursorDetail()
|
||||
|
||||
Then(Check the cursor output):
|
||||
redir => g:output
|
||||
:mess
|
||||
redir END
|
||||
|
||||
AssertEqual "Infix operators must be spaced. (space-infix-ops)", g:lines[-1]
|
||||
|
Loading…
Reference in New Issue
Block a user