Fix #876 - Save history in a separate buffer variable so history works when linting is disabled

This commit is contained in:
w0rp
2017-08-25 22:22:26 +01:00
parent 8f8d015dae
commit cdd1ddffdb
5 changed files with 67 additions and 80 deletions

View File

@@ -1,15 +1,20 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Tools for managing command history
"
" Return a shallow copy of the command history for a given buffer number.
function! ale#history#Get(buffer) abort
return copy(getbufvar(a:buffer, 'ale_history', []))
endfunction
function! ale#history#Add(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 = []
call setbufvar(a:buffer, 'ale_history', [])
return
endif
let l:history = g:ale_buffer_info[a:buffer].history
let l:history = getbufvar(a:buffer, 'ale_history', [])
" Remove the first item if we hit the max history size.
if len(l:history) >= g:ale_max_buffer_history_size
@@ -22,18 +27,13 @@ function! ale#history#Add(buffer, status, job_id, command) abort
\ 'command': a:command,
\})
let g:ale_buffer_info[a:buffer].history = l:history
call setbufvar(a:buffer, 'ale_history', l:history)
endfunction
function! s:FindHistoryItem(buffer, job_id) abort
" Stop immediately if there's nothing set up for the buffer.
if !has_key(g:ale_buffer_info, a:buffer)
return {}
endif
" 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[:])
for l:obj in reverse(ale#history#Get(a:buffer))
if l:obj.job_id == a:job_id
return l:obj
endif
@@ -46,18 +46,14 @@ endfunction
function! ale#history#SetExitCode(buffer, job_id, exit_code) abort
let l:obj = s:FindHistoryItem(a:buffer, a:job_id)
if !empty(l:obj)
" If we find a match, then set the code and status.
let l:obj.exit_code = a:exit_code
let l:obj.status = 'finished'
endif
" If we find a match, then set the code and status.
let l:obj.exit_code = a:exit_code
let l:obj.status = 'finished'
endfunction
" Set the output for a command which finished.
function! ale#history#RememberOutput(buffer, job_id, output) abort
let l:obj = s:FindHistoryItem(a:buffer, a:job_id)
if !empty(l:obj)
let l:obj.output = a:output
endif
let l:obj.output = a:output
endfunction