Merge pull request #33 from IngoHeimbach/develop

Use vim 8 timers for continuous checking of debugger output
This commit is contained in:
Idan Arye 2017-01-22 15:51:37 +02:00 committed by GitHub
commit 97ca687489
2 changed files with 70 additions and 16 deletions

View File

@ -17,7 +17,9 @@ function! s:f_debugger.kill() dict
if self.shell.is_valid if self.shell.is_valid
call self.addLineToTerminal('','== DEBUGGER TERMINATED ==') call self.addLineToTerminal('','== DEBUGGER TERMINATED ==')
endif endif
let &updatetime=self.prevUpdateTime if !has('timers')
let &updatetime=self.prevUpdateTime
endif
call self.shell.kill(15) call self.shell.kill(15)
if exists('s:debugger') if exists('s:debugger')
for l:closeHandler in s:debugger.closeHandlers for l:closeHandler in s:debugger.closeHandlers
@ -54,7 +56,9 @@ function! s:f_debugger.invokeReading() dict
\|| 'error'==l:checkpid[0] \|| 'error'==l:checkpid[0]
call self.kill() call self.kill()
endif endif
call feedkeys("f\e", '\n') " Make sure the CursorHold event is refired even if the user does nothing if !has('timers')
call feedkeys("f\e", '\n') " Make sure the CursorHold event is refired even if the user does nothing
endif
endfunction endfunction
"Handle a single line from the debugger's interactive shell "Handle a single line from the debugger's interactive shell
@ -262,12 +266,19 @@ function! vebugger#createDebugger(command)
let l:debugger.writeHandlers={} let l:debugger.writeHandlers={}
let l:debugger.closeHandlers=[] let l:debugger.closeHandlers=[]
let l:debugger.prevUpdateTime=&updatetime if !has('timers')
let l:debugger.prevUpdateTime=&updatetime
set updatetime=500
endif
set updatetime=500
return l:debugger return l:debugger
endfunction endfunction
if has('timers')
function! s:readingTimerCallback(timerId)
call s:debugger.invokeReading()
endfunction
endif
"Create a debugger and set it as the currently active debugger "Create a debugger and set it as the currently active debugger
function! vebugger#startDebugger(command) function! vebugger#startDebugger(command)
@ -275,19 +286,30 @@ function! vebugger#startDebugger(command)
let s:debugger=vebugger#createDebugger(a:command) let s:debugger=vebugger#createDebugger(a:command)
augroup vebugger_shell if has('timers')
autocmd! let s:timerId = timer_start(500, function('s:readingTimerCallback'), {'repeat': -1})
autocmd CursorHold * call s:debugger.invokeReading() else
augroup END augroup vebugger_shell
autocmd!
autocmd CursorHold * call s:debugger.invokeReading()
augroup END
endif
return s:debugger return s:debugger
endfunction endfunction
"Terminate the currently active debugger "Terminate the currently active debugger
function! vebugger#killDebugger() function! vebugger#killDebugger()
augroup vebugger_shell if has('timers')
autocmd! if exists('s:timerId')
augroup END call timer_stop(s:timerId)
unlet s:timerId
endif
else
augroup vebugger_shell
autocmd!
augroup END
endif
if exists('s:debugger') if exists('s:debugger')
call vebugger#std#closeShellBuffer(s:debugger) call vebugger#std#closeShellBuffer(s:debugger)
call s:debugger.closeTerminalBuffer() call s:debugger.closeTerminalBuffer()

View File

@ -226,20 +226,52 @@ function! s:standardThinkHandlers.updateCallStack(readResult,debugger) dict
endif endif
endfunction endfunction
"Helper print function; when using vim timers feedkeys ensures that messages
"can be confirmend by the user.
function! s:printWithFeedKeys(evaluatedExpression)
if empty(get(a:evaluatedExpression,'expression'))
let l:echo = a:evaluatedExpression.value
else
let l:echo = a:evaluatedExpression.expression.': '.a:evaluatedExpression.value
endif
let l:echoLines = split(l:echo, '\r\n\|\n\|\r')
if len(l:echoLines) == 1
call add(l:echoLines, '')
endif
if has('timers')
" Convert to an expression we can use with feedkeys.
" string(l:echo) won't do because it uses single-quotes which
" do not escape newlines
let l:echoJoinExpr = 'join('.string(l:echoLines).', "\n")'
let l:echoKeys = ':echo '.l:echoJoinExpr."\<Cr>"
if mode() == 'n'
" Call echo normaly
call feedkeys(l:echoKeys)
elseif mode() == 'i'
" Execute command in insert mode
call feedkeys("\<C-o>".l:echoKeys)
endif
" NOTE: Other modes are not supported
else
" Without timer support, feedkeys won't work and we have
" to echo directly
echo join(l:echoLines, "\n")
endif
endfunction
"Print an expression that it's evaluation was previously requested "Print an expression that it's evaluation was previously requested
function! s:standardThinkHandlers.printEvaluatedExpression(readResult,debugger) dict function! s:standardThinkHandlers.printEvaluatedExpression(readResult,debugger) dict
let l:evaluatedExpression=a:readResult.std.evaluatedExpression let l:evaluatedExpression=a:readResult.std.evaluatedExpression
if !empty(l:evaluatedExpression) if !empty(l:evaluatedExpression)
if empty(get(l:evaluatedExpression,'expression')) if !empty(get(l:evaluatedExpression,'expression'))
echo l:evaluatedExpression.value."\n"
else
let l:index=index(a:debugger.state.std.evaluateExpressions,l:evaluatedExpression.expression) let l:index=index(a:debugger.state.std.evaluateExpressions,l:evaluatedExpression.expression)
if 0<=l:index if 0<=l:index
call remove(a:debugger.state.std.evaluateExpressions,l:index) call remove(a:debugger.state.std.evaluateExpressions,l:index)
echo l:evaluatedExpression.expression.': '.l:evaluatedExpression.value."\n"
let g:echo=l:evaluatedExpression.expression.': '.l:evaluatedExpression.value."\n"
endif endif
endif endif
call s:printWithFeedKeys(l:evaluatedExpression)
call a:debugger.addWriteAction('std','removeAfterDisplayed',a:readResult) call a:debugger.addWriteAction('std','removeAfterDisplayed',a:readResult)
endif endif
endfunction endfunction