Skip to content

Commit 9bc1678

Browse files
author
Benji Fisher
committed
Allow for persistent code evaluation in the watch window.
After ":VdebugEval! code", continue to evaluate code in the watch window after running through the code. Clear with ":VdebugEval!".
1 parent b808b02 commit 9bc1678

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

plugin/python/start_vdebug.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ def eval_under_cursor(self):
120120
except Exception as e:
121121
self.handle_exception(e)
122122

123+
def save_eval(self,args):
124+
"""Save a code snippet for later display in the watch window.
125+
"""
126+
try:
127+
return self.runner.save_code(args)
128+
except Exception as e:
129+
self.handle_exception(e)
130+
123131
def toggle_breakpoint_window(self):
124132
"""Open or close the breakpoint window.
125133
"""

plugin/python/vdebug/runner.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def __init__(self):
2222
self.breakpoints = vdebug.breakpoint.Store()
2323
self.keymapper = vdebug.util.Keymapper()
2424
self.ui = vdebug.ui.vimui.Ui(self.breakpoints)
25+
self.saved_code = ''
2526

2627
def open(self):
2728
""" Open the connection and debugging vdebug.ui.
@@ -87,6 +88,12 @@ def set_features(self):
8788
error_str = "Failed to set feature %s: %s" %(name,str(e.args[0]))
8889
self.ui.error(error_str)
8990

91+
def save_code(self,code):
92+
"""Save a code snippet for later display in the watch window.
93+
"""
94+
self.saved_code = code
95+
return code
96+
9097
def refresh(self,status):
9198
"""The main action performed after a deubugger step.
9299
@@ -121,7 +128,10 @@ def refresh(self,status):
121128
self.cur_file,\
122129
self.cur_lineno)
123130

124-
self.get_context(0)
131+
if self.saved_code != '':
132+
self.eval(self.saved_code)
133+
else:
134+
self.get_context(0)
125135

126136
def get_context(self,context_id = 0):
127137
self.ui.watchwin.clean()

plugin/vdebug.vim

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ command! -nargs=? -complete=customlist,s:BreakpointTypes Breakpoint python debug
115115
command! VdebugStart python debugger.run()
116116
command! -nargs=? BreakpointRemove python debugger.remove_breakpoint(<q-args>)
117117
command! BreakpointWindow python debugger.toggle_breakpoint_window()
118-
command! -nargs=? VdebugEval python debugger.handle_eval(<q-args>)
118+
command! -nargs=? -bang VdebugEval call s:HandleEval('<bang>', <q-args>)
119119
command! -nargs=+ -complete=customlist,s:OptionNames VdebugOpt python debugger.handle_opt(<f-args>)
120120

121121
" Signs and highlighted lines for breakpoints, etc.
@@ -137,6 +137,16 @@ function! s:BreakpointTypes(A,L,P)
137137
endif
138138
endfunction
139139

140+
function! s:HandleEval(bang,code)
141+
let code = escape(a:code,'"')
142+
if strlen(a:bang)
143+
execute 'python debugger.save_eval("'.code.'")'
144+
endif
145+
if strlen(a:code)
146+
execute 'python debugger.handle_eval("'.code.'")'
147+
endif
148+
endfunction
149+
140150
" Reload options dictionary, by merging with default options.
141151
"
142152
" This should be called if you want to update the options after vdebug has

0 commit comments

Comments
 (0)