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

@@ -112,11 +112,7 @@ 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
for l:item in ale#history#Get(l:buffer)
if l:item.job_id is# 'executable'
call s:EchoExecutable(l:item)
else

View File

@@ -53,14 +53,12 @@ function! ale#engine#InitBufferInfo(buffer) abort
" loclist holds the loclist items after all jobs have completed.
" 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': [],
\ 'active_linter_list': [],
\ 'loclist': [],
\ 'temporary_file_list': [],
\ 'temporary_directory_list': [],
\ 'history': [],
\}
return 1
@@ -557,8 +555,6 @@ function! s:RunJob(options) abort
if g:ale_history_enabled
call ale#history#Add(l:buffer, l:status, l:job_id, l:command)
else
let l:info.history = []
endif
if get(g:, 'ale_run_synchronously') == 1

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