#254 Add an option for logging the output of commands
This commit is contained in:
parent
843370b96f
commit
eac0a41ae1
@ -76,6 +76,24 @@ function! s:EchoCommandHistory() abort
|
||||
endif
|
||||
|
||||
echom '(' . l:status_message . ') ' . string(l:item.command)
|
||||
|
||||
if g:ale_history_log_output && has_key(l:item, 'output')
|
||||
if empty(l:item.output)
|
||||
echom ''
|
||||
echom '<<<NO OUTPUT RETURNED>>>'
|
||||
echom ''
|
||||
else
|
||||
echom ''
|
||||
echom '<<<OUTPUT STARTS>>>'
|
||||
|
||||
for l:line in l:item.output
|
||||
echom l:line
|
||||
endfor
|
||||
|
||||
echom '<<<OUTPUT ENDS>>>'
|
||||
echom ''
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
|
@ -214,6 +214,11 @@ function! s:HandleExit(job) abort
|
||||
return
|
||||
endif
|
||||
|
||||
" Log the output of the command for ALEInfo if we should.
|
||||
if g:ale_history_enabled && g:ale_history_log_output
|
||||
call ale#history#RememberOutput(l:buffer, l:job_id, l:output[:])
|
||||
endif
|
||||
|
||||
let l:linter_loclist = ale#util#GetFunction(l:linter.callback)(l:buffer, l:output)
|
||||
|
||||
" Make some adjustments to the loclists to fix common problems.
|
||||
|
@ -25,17 +25,34 @@ 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
|
||||
function! s:FindHistoryItem(buffer, job_id) 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
|
||||
return l:obj
|
||||
endif
|
||||
endfor
|
||||
|
||||
return {}
|
||||
endfunction
|
||||
|
||||
" Set an exit code for a command which finished.
|
||||
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
|
||||
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
|
||||
endfunction
|
||||
|
16
doc/ale.txt
16
doc/ale.txt
@ -199,6 +199,22 @@ g:ale_history_enabled *g:ale_history_enabled*
|
||||
This option can be disabled if storing a command history is not desired.
|
||||
|
||||
|
||||
g:ale_history_log_output *g:ale_history_log_output*
|
||||
|
||||
Type: |Number|
|
||||
Default: `0`
|
||||
|
||||
When set to `1`, ALE will store the output of commands which have completed
|
||||
successfully in the command history, and the output will be displayed when
|
||||
using |ALEInfo|.
|
||||
|
||||
|g:ale_history_enabled| must be set to `1` for this output to be stored or
|
||||
printed.
|
||||
|
||||
ALE will likely consume a lot of memory if this option is on, so it should
|
||||
only be used for debugging problems with linters.
|
||||
|
||||
|
||||
g:ale_keep_list_window_open *g:ale_keep_list_window_open*
|
||||
|
||||
Type: |Number|
|
||||
|
@ -137,6 +137,9 @@ let g:ale_max_buffer_history_size = get(g:, 'ale_max_buffer_history_size', 20)
|
||||
" A flag for enabling or disabling the command history.
|
||||
let g:ale_history_enabled = get(g:, 'ale_history_enabled', 1)
|
||||
|
||||
" A flag for storing the full output of commands in the history.
|
||||
let g:ale_history_log_output = get(g:, 'ale_history_log_output', 0)
|
||||
|
||||
function! s:ALEInitAuGroups() abort
|
||||
augroup ALERunOnTextChangedGroup
|
||||
autocmd!
|
||||
|
@ -41,6 +41,7 @@ After:
|
||||
unlet! g:globals_string
|
||||
unlet! g:command_header
|
||||
let g:ale_buffer_info = {}
|
||||
let g:ale_history_log_output = 0
|
||||
unlet! g:ale_testft_testlinter1_foo
|
||||
unlet! g:ale_testft_testlinter1_bar
|
||||
unlet! g:ale_testft2_testlinter2_foo
|
||||
@ -218,3 +219,66 @@ Execute (ALEInfo command history should print exit codes correctly):
|
||||
\ '(finished - exit code 1) [''/bin/bash'', ''\c'', ''last command'']',
|
||||
\ ], "\n"),
|
||||
\ g:output
|
||||
|
||||
Given testft.testft2 (Empty buffer with two filetypes):
|
||||
Execute (ALEInfo command history should print command output if logging is on):
|
||||
let g:ale_history_log_output = 1
|
||||
|
||||
let g:ale_buffer_info[bufnr('%')] = {
|
||||
\ 'history': [
|
||||
\ {
|
||||
\ 'status': 'finished',
|
||||
\ 'exit_code': 0,
|
||||
\ 'job_id': 347,
|
||||
\ 'command': 'first command',
|
||||
\ 'output': ['some', 'first command output'],
|
||||
\ },
|
||||
\ {
|
||||
\ 'status': 'finished',
|
||||
\ 'exit_code': 1,
|
||||
\ 'job_id': 347,
|
||||
\ 'command': ['/bin/bash', '\c', 'last command'],
|
||||
\ 'output': ['different second command output'],
|
||||
\ },
|
||||
\ {
|
||||
\ 'status': 'finished',
|
||||
\ 'exit_code': 0,
|
||||
\ 'job_id': 347,
|
||||
\ 'command': 'command with no output',
|
||||
\ 'output': [],
|
||||
\ },
|
||||
\ ],
|
||||
\}
|
||||
|
||||
call ale#linter#Define('testft', g:testlinter1)
|
||||
call ale#linter#Define('testft2', g:testlinter2)
|
||||
redir => g:output
|
||||
silent ALEInfo
|
||||
redir END
|
||||
AssertEqual
|
||||
\ join([
|
||||
\ '',
|
||||
\ ' Current Filetype: testft.testft2',
|
||||
\ 'Available Linters: [''testlinter1'', ''testlinter2'']',
|
||||
\ ' Enabled Linters: [''testlinter1'', ''testlinter2'']',
|
||||
\ ' Linter Variables:',
|
||||
\ g:globals_string . g:command_header,
|
||||
\ '(finished - exit code 0) ''first command''',
|
||||
\ '',
|
||||
\ '<<<OUTPUT STARTS>>>',
|
||||
\ 'some',
|
||||
\ 'first command output',
|
||||
\ '<<<OUTPUT ENDS>>>',
|
||||
\ '',
|
||||
\ '(finished - exit code 1) [''/bin/bash'', ''\c'', ''last command'']',
|
||||
\ '',
|
||||
\ '<<<OUTPUT STARTS>>>',
|
||||
\ 'different second command output',
|
||||
\ '<<<OUTPUT ENDS>>>',
|
||||
\ '',
|
||||
\ '(finished - exit code 0) ''command with no output''',
|
||||
\ '',
|
||||
\ '<<<NO OUTPUT RETURNED>>>',
|
||||
\ '',
|
||||
\ ], "\n"),
|
||||
\ g:output
|
||||
|
@ -17,6 +17,7 @@ Before:
|
||||
|
||||
After:
|
||||
let g:ale_history_enabled = 1
|
||||
let g:ale_history_log_output = 0
|
||||
unlet g:history
|
||||
let g:ale_buffer_info = {}
|
||||
let g:ale_max_buffer_history_size = 20
|
||||
@ -52,6 +53,19 @@ Execute(History should be not set when disabled):
|
||||
|
||||
AssertEqual 0, len(g:ale_buffer_info[bufnr('%')].history)
|
||||
|
||||
Execute(History should include command output if logging is enabled):
|
||||
AssertEqual 'foobar', &filetype
|
||||
|
||||
let g:ale_history_log_output = 1
|
||||
|
||||
call ale#Lint()
|
||||
call ale#engine#WaitForJobs(2000)
|
||||
|
||||
let g:history = g:ale_buffer_info[bufnr('%')].history
|
||||
|
||||
AssertEqual 1, len(g:history)
|
||||
AssertEqual ['command history test'], g:history[0].output
|
||||
|
||||
Execute(History items should be popped after going over the max):
|
||||
let g:ale_buffer_info[1] = {
|
||||
\ 'history': map(range(20), '{''status'': ''started'', ''job_id'': v:val, ''command'': ''foobar''}'),
|
||||
|
Loading…
Reference in New Issue
Block a user