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.writeLine('monitor where')
|
||||||
|
|
||||||
call l:debugger.addReadHandler(function('s:readWhere'))
|
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','flow',function('s:writeFlow'))
|
||||||
call l:debugger.setWriteHandler('std','breakpoints',function('s:writeBreakpoints'))
|
call l:debugger.setWriteHandler('std','breakpoints',function('s:writeBreakpoints'))
|
||||||
|
call l:debugger.setWriteHandler('std','evaluateExpressions',function('s:requestEvaluateExpression'))
|
||||||
|
|
||||||
call l:debugger.generateWriteActionsFromTemplate()
|
call l:debugger.generateWriteActionsFromTemplate()
|
||||||
|
|
||||||
@ -100,3 +102,22 @@ function! s:writeBreakpoints(writeAction,debugger)
|
|||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
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)
|
function! vebugger#std#setStandardState(debugger)
|
||||||
let a:debugger.state.std={
|
let a:debugger.state.std={
|
||||||
\'location':{},
|
\'location':{},
|
||||||
\'callstack':[]}
|
\'callstack':[],
|
||||||
|
\'evaluateExpressions':[]}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! vebugger#std#setStandardReadResultTemplate(debugger)
|
function! vebugger#std#setStandardReadResultTemplate(debugger)
|
||||||
let a:debugger.readResultTemplate.std={
|
let a:debugger.readResultTemplate.std={
|
||||||
\'location':{},
|
\'location':{},
|
||||||
\'callstack':{}}
|
\'callstack':{},
|
||||||
|
\'evaluatedExpression':{}}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! vebugger#std#setStandardWriteactionsTemplate(debugger)
|
function! vebugger#std#setStandardWriteactionsTemplate(debugger)
|
||||||
let a:debugger.writeActionsTemplate.std={
|
let a:debugger.writeActionsTemplate.std={
|
||||||
\'flow':'',
|
\'flow':'',
|
||||||
\'breakpoints':[]}
|
\'breakpoints':[],
|
||||||
|
\'evaluateExpressions':[]}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! vebugger#std#addStandardFunctions(debugger)
|
function! vebugger#std#addStandardFunctions(debugger)
|
||||||
@ -65,6 +68,15 @@ function! s:standardFunctions.addAllBreakpointActions(breakpoints) dict
|
|||||||
endfor
|
endfor
|
||||||
endfunction
|
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={}
|
let s:standardThinkHandlers={}
|
||||||
function! s:standardThinkHandlers.moveToCurrentLine(readResult,debugger) dict
|
function! s:standardThinkHandlers.moveToCurrentLine(readResult,debugger) dict
|
||||||
if !empty(a:readResult.std.location)
|
if !empty(a:readResult.std.location)
|
||||||
@ -97,6 +109,21 @@ function! s:standardThinkHandlers.updateCallStack(readResult,debugger) dict
|
|||||||
endif
|
endif
|
||||||
endfunction
|
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={}
|
let s:standardCloseHandlers={}
|
||||||
function! s:standardCloseHandlers.removeCurrentMarker(debugger) dict
|
function! s:standardCloseHandlers.removeCurrentMarker(debugger) dict
|
||||||
let a:debugger.state.std.location={}
|
let a:debugger.state.std.location={}
|
||||||
@ -168,3 +195,10 @@ function! vebugger#std#clearBreakpoints()
|
|||||||
call vebugger#std#updateMarksForFile(l:debuggerState,l:file)
|
call vebugger#std#updateMarksForFile(l:debuggerState,l:file)
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
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 VBGtoggleBreakpointThisLine call vebugger#std#toggleBreakpoint(expand('%:~:.'),line('.'))
|
||||||
command! -nargs=0 VBGclearBreakpints call vebugger#std#clearBreakpoints()
|
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 exists('g:vebugger_leader')
|
||||||
if !empty(g:vebugger_leader)
|
if !empty(g:vebugger_leader)
|
||||||
for s:mapping in items({
|
for s:mapping in items({
|
||||||
@ -20,8 +37,13 @@ if exists('g:vebugger_leader')
|
|||||||
\'O':'VBGstepOut',
|
\'O':'VBGstepOut',
|
||||||
\'c':'VBGcontinue',
|
\'c':'VBGcontinue',
|
||||||
\'l':'VBGtoggleLogBuffer',
|
\'l':'VBGtoggleLogBuffer',
|
||||||
\'b':'VBGtoggleBreakpointThisLine'})
|
\'b':'VBGtoggleBreakpointThisLine',
|
||||||
|
\'e':'VBGevalWordUnderCursor'})
|
||||||
exe 'nnoremap '.g:vebugger_leader.s:mapping[0].' :'.s:mapping[1].'<Cr>'
|
exe 'nnoremap '.g:vebugger_leader.s:mapping[0].' :'.s:mapping[1].'<Cr>'
|
||||||
endfor
|
endfor
|
||||||
|
for s:mapping in items({
|
||||||
|
\'e':'VBGevalSelectedText'})
|
||||||
|
exe 'vnoremap '.g:vebugger_leader.s:mapping[0].' :'.s:mapping[1].'<Cr>'
|
||||||
|
endfor
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user