#254 Capture command exit codes in the history

This commit is contained in:
w0rp
2017-02-16 22:19:53 +00:00
parent ca17b5aebd
commit 843370b96f
5 changed files with 82 additions and 4 deletions

View File

@@ -68,7 +68,14 @@ function! s:EchoCommandHistory() abort
endif
for l:item in g:ale_buffer_info[l:buffer].history
echom '(' . l:item.status . ') ' . string(l:item.command)
let l:status_message = l:item.status
" Include the exit code in output if we have it.
if l:item.status ==# 'finished'
let l:status_message .= ' - exit code ' . l:item.exit_code
endif
echom '(' . l:status_message . ') ' . string(l:item.command)
endfor
endfunction

View File

@@ -270,7 +270,23 @@ function! ale#engine#SetResults(buffer, loclist) abort
endif
endfunction
function! s:HandleExitNeoVim(job, data, event) abort
function! s:SetExitCode(job, exit_code) abort
let l:job_id = s:GetJobID(a:job)
if !has_key(s:job_info_map, l:job_id)
return
endif
let l:buffer = s:job_info_map[l:job_id].buffer
call ale#history#SetExitCode(l:buffer, l:job_id, a:exit_code)
endfunction
function! s:HandleExitNeoVim(job, exit_code, event) abort
if g:ale_history_enabled
call s:SetExitCode(a:job, a:exit_code)
endif
call s:HandleExit(a:job)
endfunction
@@ -278,6 +294,12 @@ function! s:HandleExitVim(channel) abort
call s:HandleExit(ch_getjob(a:channel))
endfunction
" Vim returns the exit status with one callback,
" and the channel will close later in another callback.
function! s:HandleExitStatusVim(job, exit_code) abort
call s:SetExitCode(a:job, a:exit_code)
endfunction
function! s:FixLocList(buffer, loclist) abort
" Some errors have line numbers beyond the end of the file,
" so we need to adjust them so they set the error at the last line
@@ -415,6 +437,12 @@ function! s:RunJob(options) abort
\ 'close_cb': function('s:HandleExitVim'),
\}
if g:ale_history_enabled
" We only need to capture the exit status if we are going to
" save it in the history. Otherwise, we don't care.
let l:job_options.exit_cb = function('s:HandleExitStatusVim')
endif
if l:output_stream ==# 'stderr'
" Read from stderr instead of stdout.
let l:job_options.err_cb = function('s:GatherOutputVim')

View File

@@ -24,3 +24,18 @@ function! ale#history#Add(buffer, status, job_id, command) abort
let g:ale_buffer_info[a:buffer].history = l:history
endfunction
" Set an exit code for a command which finished.
function! ale#history#SetExitCode(buffer, job_id, exit_code) abort
" Search backwards to find a matching job ID. IDs might be recycled,
" so finding the last one should be good enough.
for l:obj in reverse(g:ale_buffer_info[a:buffer].history[:])
if l:obj.job_id == a:job_id
" If we find a match, then set the code and status, and stop here.
let l:obj.exit_code = a:exit_code
let l:obj.status = 'finished'
return
endif
endfor
endfunction