#254 Add command history to ALEInfo

This commit is contained in:
w0rp
2017-02-14 23:44:37 +00:00
parent c460602cbb
commit ed370667c8
5 changed files with 163 additions and 8 deletions

View File

@@ -60,6 +60,18 @@ function! s:EchoGlobalVariables() abort
endfor
endfunction
function! s:EchoCommandHistory() abort
let l:buffer = bufnr('%')
if !has_key(g:ale_buffer_info, l:buffer)
return
endif
for l:item in g:ale_buffer_info[l:buffer].history
echom '(' . l:item.status . ') ' . string(l:item.command)
endfor
endfunction
function! ale#debugging#Info() abort
let l:filetype = &filetype
@@ -91,4 +103,7 @@ function! ale#debugging#Info() abort
echom ' Global Variables:'
echom ''
call s:EchoGlobalVariables()
echom ' Command History:'
echom ''
call s:EchoCommandHistory()
endfunction

View File

@@ -9,6 +9,30 @@
" output: The array of lines for the output of the job.
let s:job_info_map = {}
function! ale#engine#AddToHistory(buffer, status, job_id, command) abort
if g:ale_max_buffer_history_size <= 0
" Don't save anything if the history isn't a positive number.
let g:ale_buffer_info[a:buffer].history = []
return
endif
let l:history = g:ale_buffer_info[a:buffer].history
" Remove the first item if we hit the max history size.
if len(l:history) >= g:ale_max_buffer_history_size
let l:history = l:history[1:]
endif
call add(l:history, {
\ 'status': a:status,
\ 'job_id': a:job_id,
\ 'command': a:command,
\})
let g:ale_buffer_info[a:buffer].history = l:history
endfunction
function! s:GetJobID(job) abort
if has('nvim')
"In NeoVim, job values are just IDs.
@@ -33,12 +57,14 @@ function! ale#engine#InitBufferInfo(buffer) abort
" new_loclist holds loclist items while jobs are being run.
" temporary_file_list holds temporary files to be cleaned up
" temporary_directory_list holds temporary directories to be cleaned up
" history holds a list of previously run commands for this buffer
let g:ale_buffer_info[a:buffer] = {
\ 'job_list': [],
\ 'loclist': [],
\ 'new_loclist': [],
\ 'temporary_file_list': [],
\ 'temporary_directory_list': [],
\ 'history': [],
\}
endif
endfunction
@@ -437,19 +463,26 @@ function! s:RunJob(options) abort
let l:job = job_start(l:command, l:job_options)
endif
let l:status = 'failed'
let l:job_id = 0
" Only proceed if the job is being run.
if has('nvim') || (l:job !=# 'no process' && job_status(l:job) ==# 'run')
" Add the job to the list of jobs, so we can track them.
call add(g:ale_buffer_info[l:buffer].job_list, l:job)
let l:status = 'ran'
let l:job_id = s:GetJobID(l:job)
" Store the ID for the job in the map to read back again.
let s:job_info_map[s:GetJobID(l:job)] = {
let s:job_info_map[l:job_id] = {
\ 'linter': l:linter,
\ 'buffer': l:buffer,
\ 'output': [],
\ 'next_chain_index': l:next_chain_index,
\}
endif
call ale#engine#AddToHistory(l:buffer, l:status, l:job_id, l:command)
endfunction
" Determine which commands to run for a link in a command chain, or