Added expression evaluation functionality
This commit is contained in:
parent
61d1c3f752
commit
69dab33ea3
@ -16,9 +16,11 @@ function! vebugger#jdb#start(entryClass,args)
|
||||
call l:debugger.writeLine('monitor where')
|
||||
|
||||
call l:debugger.addReadHandler(function('s:readWhere'))
|
||||
call l:debugger.addReadHandler(function('s:readEvaluatedExpressions'))
|
||||
|
||||
call l:debugger.setWriteHandler('std','flow',function('s:writeFlow'))
|
||||
call l:debugger.setWriteHandler('std','breakpoints',function('s:writeBreakpoints'))
|
||||
call l:debugger.setWriteHandler('std','evaluateExpressions',function('s:requestEvaluateExpression'))
|
||||
|
||||
call l:debugger.generateWriteActionsFromTemplate()
|
||||
|
||||
@ -100,3 +102,22 @@ function! s:writeBreakpoints(writeAction,debugger)
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:requestEvaluateExpression(writeAction,debugger)
|
||||
for l:evalAction in a:writeAction
|
||||
call a:debugger.writeLine('eval '.l:evalAction.expression)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:readEvaluatedExpressions(pipeName,line,readResult,debugger)
|
||||
if 'out'==a:pipeName
|
||||
let l:matches=matchlist(a:line,'\v^%(\s*%(%(%(\w|\.)+)\[\d+\] )+)? ([^=]+) \= (.*)$')
|
||||
if 3<len(l:matches)
|
||||
let l:expression=l:matches[1]
|
||||
let l:value=l:matches[2]
|
||||
let a:readResult.std.evaluatedExpression={
|
||||
\'expression':(l:matches[1]),
|
||||
\'value':(l:matches[2])}
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
@ -3,19 +3,22 @@ let g:vebugger_breakpoints=[]
|
||||
function! vebugger#std#setStandardState(debugger)
|
||||
let a:debugger.state.std={
|
||||
\'location':{},
|
||||
\'callstack':[]}
|
||||
\'callstack':[],
|
||||
\'evaluateExpressions':[]}
|
||||
endfunction
|
||||
|
||||
function! vebugger#std#setStandardReadResultTemplate(debugger)
|
||||
let a:debugger.readResultTemplate.std={
|
||||
\'location':{},
|
||||
\'callstack':{}}
|
||||
\'callstack':{},
|
||||
\'evaluatedExpression':{}}
|
||||
endfunction
|
||||
|
||||
function! vebugger#std#setStandardWriteactionsTemplate(debugger)
|
||||
let a:debugger.writeActionsTemplate.std={
|
||||
\'flow':'',
|
||||
\'breakpoints':[]}
|
||||
\'breakpoints':[],
|
||||
\'evaluateExpressions':[]}
|
||||
endfunction
|
||||
|
||||
function! vebugger#std#addStandardFunctions(debugger)
|
||||
@ -65,6 +68,15 @@ function! s:standardFunctions.addAllBreakpointActions(breakpoints) dict
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:standardFunctions.eval(expression) dict
|
||||
if -1==index(self.state.std.evaluateExpressions,a:expression)
|
||||
call add(self.state.std.evaluateExpressions,a:expression)
|
||||
endif
|
||||
call self.addWriteAction('std','evaluateExpressions',{
|
||||
\'expression':(a:expression)})
|
||||
call self.performWriteActions()
|
||||
endfunction
|
||||
|
||||
let s:standardThinkHandlers={}
|
||||
function! s:standardThinkHandlers.moveToCurrentLine(readResult,debugger) dict
|
||||
if !empty(a:readResult.std.location)
|
||||
@ -97,6 +109,21 @@ function! s:standardThinkHandlers.updateCallStack(readResult,debugger) dict
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:standardThinkHandlers.printEvaluatedExpression(readResult,debugger) dict
|
||||
let l:evaluatedExpression=a:readResult.std.evaluatedExpression
|
||||
if !empty(l:evaluatedExpression)
|
||||
if empty(l:evaluatedExpression.expression)
|
||||
echo l:evaluatedExpression.value
|
||||
else
|
||||
let l:index=index(a:debugger.state.std.evaluateExpressions,l:evaluatedExpression.expression)
|
||||
if 0<=l:index
|
||||
call remove(a:debugger.state.std.evaluateExpressions,l:index)
|
||||
echo l:evaluatedExpression.expression.': '.l:evaluatedExpression.value
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let s:standardCloseHandlers={}
|
||||
function! s:standardCloseHandlers.removeCurrentMarker(debugger) dict
|
||||
let a:debugger.state.std.location={}
|
||||
@ -168,3 +195,10 @@ function! vebugger#std#clearBreakpoints()
|
||||
call vebugger#std#updateMarksForFile(l:debuggerState,l:file)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! vebugger#std#eval(expression)
|
||||
let l:debugger=vebugger#getActiveDebugger()
|
||||
if !empty(l:debugger) && !empty(l:debugger.std_eval)
|
||||
call l:debugger.std_eval(a:expression)
|
||||
endif
|
||||
endfunction
|
||||
|
@ -12,6 +12,23 @@ command! -nargs=+ VBGtoggleBreakpoint call vebugger#std#toggleBreakpoint(<f-args
|
||||
command! -nargs=0 VBGtoggleBreakpointThisLine call vebugger#std#toggleBreakpoint(expand('%:~:.'),line('.'))
|
||||
command! -nargs=0 VBGclearBreakpints call vebugger#std#clearBreakpoints()
|
||||
|
||||
command! -nargs=1 VBGeval call vebugger#std#eval(<q-args>)
|
||||
command! -nargs=0 VBGevalWordUnderCursor call vebugger#std#eval(expand('<cword>'))
|
||||
|
||||
"Shamefully stolen from http://stackoverflow.com/a/6271254/794380
|
||||
function! s:get_visual_selection()
|
||||
" Why is this not a built-in Vim script function?!
|
||||
let [lnum1, col1] = getpos("'<")[1:2]
|
||||
let [lnum2, col2] = getpos("'>")[1:2]
|
||||
let lines = getline(lnum1, lnum2)
|
||||
let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
|
||||
let lines[0] = lines[0][col1 - 1:]
|
||||
return join(lines, "\n")
|
||||
endfunction
|
||||
|
||||
command! -range -nargs=0 VBGevalSelectedText call vebugger#std#eval(s:get_visual_selection())
|
||||
|
||||
|
||||
if exists('g:vebugger_leader')
|
||||
if !empty(g:vebugger_leader)
|
||||
for s:mapping in items({
|
||||
@ -20,8 +37,13 @@ if exists('g:vebugger_leader')
|
||||
\'O':'VBGstepOut',
|
||||
\'c':'VBGcontinue',
|
||||
\'l':'VBGtoggleLogBuffer',
|
||||
\'b':'VBGtoggleBreakpointThisLine'})
|
||||
\'b':'VBGtoggleBreakpointThisLine',
|
||||
\'e':'VBGevalWordUnderCursor'})
|
||||
exe 'nnoremap '.g:vebugger_leader.s:mapping[0].' :'.s:mapping[1].'<Cr>'
|
||||
endfor
|
||||
for s:mapping in items({
|
||||
\'e':'VBGevalSelectedText'})
|
||||
exe 'vnoremap '.g:vebugger_leader.s:mapping[0].' :'.s:mapping[1].'<Cr>'
|
||||
endfor
|
||||
endif
|
||||
endif
|
||||
|
Loading…
Reference in New Issue
Block a user