Skip to content

Commit 789e8f8

Browse files
committed
WIP: Allow editing of breakpoint options in breakpoints window; fix winbar in neovim
1 parent 4354061 commit 789e8f8

File tree

4 files changed

+100
-44
lines changed

4 files changed

+100
-44
lines changed

autoload/vimspector.vim

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -173,33 +173,18 @@ function! vimspector#ClearBreakpoints() abort
173173
py3 _vimspector_session.ClearBreakpoints()
174174
endfunction
175175

176-
let s:extended_breakpoint_properties = [
177-
\ { 'prop': 'condition', 'msg': 'Enter condition expression' },
178-
\ { 'prop': 'hitCondition', 'msg': 'Enter hit count expression' },
179-
\ { 'prop': 'logMessage',
180-
\ 'msg': 'Enter log expression (to make log point)' },
181-
\ ]
182-
183-
function! s:AskForInput( ... ) abort
184-
return py3eval( '__import__( "vimspector", fromlist=[ "utils" ] )'
185-
\ . '.utils.AskForInput( *vim.eval( "a:000" ) )' )
176+
function! vimspector#ResetExceptionBreakpoints() abort
177+
if !s:Enabled()
178+
return
179+
endif
180+
py3 _vimspector_session.ResetExceptionBreakpoints()
186181
endfunction
187182

188-
function! s:GetAdvancedBreakpointOptions() abort
189-
let options = {}
190-
for spec in s:extended_breakpoint_properties
191-
let response = s:AskForInput( spec.msg . ': ' )
192-
if response is s:None
193-
return s:None
194-
elseif response !=# ''
195-
let options[ spec.prop ] = response
196-
endif
197-
endfor
198-
199-
return options
183+
function! s:GetAdvancedBreakpointOptions( ... ) abort
184+
return py3eval( '__import__( "vimspector", fromlist=[ "breakpoints" ] )'
185+
\ . '.breakpoints.GetAdvancedBreakpointOptions()' )
200186
endfunction
201187

202-
203188
function! vimspector#ToggleAdvancedBreakpoint() abort
204189
let options = s:GetAdvancedBreakpointOptions()
205190
if options is s:None
@@ -600,6 +585,13 @@ function! vimspector#JumpToBreakpointViewBreakpoint() abort
600585
py3 _vimspector_session.JumpToBreakpointViewBreakpoint()
601586
endfunction
602587

588+
function! vimspector#EditBreakpointOptionsViewBreakpoint() abort
589+
if !s:Enabled()
590+
return
591+
endif
592+
py3 _vimspector_session.EditBreakpointOptionsViewBreakpoint()
593+
endfunction
594+
603595
function! vimspector#JumpToNextBreakpoint() abort
604596
if !s:Enabled()
605597
return

python3/vimspector/breakpoints.py

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -100,27 +100,7 @@ def _UpdateView( self, breakpoint_list, show=True ):
100100

101101
utils.SetSyntax( '', 'vimspector-breakpoints', self._buffer )
102102

103-
if utils.UseWinBar():
104-
vim.command( 'nnoremenu <silent> 1.1 WinBar.Delete '
105-
':call vimspector#DeleteBreakpointViewBreakpoint()<CR>' )
106-
vim.command( 'nnoremenu <silent> 1.2 WinBar.Toggle '
107-
':call vimspector#ToggleBreakpointViewBreakpoint()<CR>' )
108-
vim.command( 'nnoremenu <silent> 1.2 WinBar.*Toggle '
109-
':call'
110-
' vimspector#ToggleAllBreakpointsViewBreakpoint()<CR>' )
111-
vim.command( 'nnoremenu <silent> 1.3 WinBar.Jump\\ To '
112-
':call vimspector#JumpToBreakpointViewBreakpoint()<CR>' )
113-
# TODO: Add tests for this function
114-
vim.command( 'nnoremenu <silent> 1.4 WinBar.+Line '
115-
':call vimspector#SetAdvancedLineBreakpoint()<CR>' )
116-
vim.command( 'nnoremenu <silent> 1.4 WinBar.+Function '
117-
':call vimspector#AddAdvancedFunctionBreakpoint()<CR>' )
118-
vim.command( 'nnoremenu <silent> 1.4 WinBar.Clear '
119-
':call vimspector#ClearBreakpoints()<CR>' )
120-
vim.command( 'nnoremenu <silent> 1.4 WinBar.Save '
121-
':call vimspector#WriteSessionFile()<CR>' )
122-
vim.command( 'nnoremenu <silent> 1.4 WinBar.Load '
123-
':call vimspector#ReadSessionFile()<CR>' )
103+
self._RenderWinBar()
124104

125105
# we want to maintain the height of the window
126106
self._win.options[ "winfixheight" ] = True
@@ -141,6 +121,28 @@ def FormatEntry( el ):
141121
utils.SetBufferContents( self._buffer,
142122
list( map( FormatEntry, breakpoint_list ) ) )
143123

124+
125+
def _RenderWinBar( self ):
126+
if not utils.UseWinBar():
127+
return
128+
129+
if not self._HasWindow():
130+
return
131+
132+
with utils.LetCurrentWindow( self._win ):
133+
utils.SetWinBar(
134+
( 'Del', 'vimspector#DeleteBreakpointViewBreakpoint()' ),
135+
( 'On/Off', 'vimspector#ToggleBreakpointViewBreakpoint()' ),
136+
( 'Edit', 'vimspector#EditBreakpointOptionsViewBreakpoint()' ),
137+
( '+Line', 'vimspector#SetAdvancedLineBreakpoint()' ),
138+
( '+Func', 'vimspector#AddAdvancedFunctionBreakpoint()' ),
139+
( 'Clr All', 'vimspector#ClearBreakpoints()' ),
140+
( 'Clr Excp', 'vimspector#ResetExceptionBreakpoints()' ),
141+
( 'Save', 'vimspector#WriteSessionFile()' ),
142+
( 'Load', 'vimspector#ReadSessionFile()' ),
143+
)
144+
145+
144146
def CloseBreakpoints( self ):
145147
if not self._HasWindow():
146148
return
@@ -337,6 +339,22 @@ def JumpToBreakpointViewBreakpoint( self ):
337339

338340
_JumpToBreakpoint( bp )
339341

342+
def EditBreakpointOptionsViewBreakpoint( self ):
343+
vbp = self._breakpoints_view.GetBreakpointForLine()
344+
if not vbp:
345+
return
346+
347+
# Try to find the actual breakpoint
348+
bp, index = self._FindLineBreakpoint( vbp.get( 'filename' ),
349+
vbp.get( 'lnum' ) )
350+
351+
if not bp:
352+
return
353+
354+
bp[ 'options' ] = GetAdvancedBreakpointOptions( bp[ 'options' ] )
355+
self.UpdateUI()
356+
357+
340358
def JumpToNextBreakpoint( self, reverse=False ):
341359
bps = self._breakpoints_view._breakpoint_list
342360
if not bps:
@@ -441,6 +459,12 @@ def ClearBreakpoints( self ):
441459
self.UpdateUI()
442460

443461

462+
def ResetExceptionBreakpoints( self ):
463+
# TODO: Should exceptoni breakpoints be per-session!?
464+
self._exception_breakpoints = None
465+
self.UpdateUI()
466+
467+
444468
def _FindLineBreakpoint( self, file_name, line ):
445469
for bp, index in self._AllBreakpointsOnLine( file_name, line ):
446470
return bp, index
@@ -1224,3 +1248,26 @@ def _SignToLine( self, file_name, bp ):
12241248
bp[ 'line' ] = int( signs[ 0 ][ 'signs' ][ 0 ][ 'lnum' ] )
12251249

12261250
return
1251+
1252+
1253+
_extended_breakpoint_properties = [
1254+
{ 'prop': 'condition', 'msg': 'Enter condition expression' },
1255+
{ 'prop': 'hitCondition', 'msg': 'Enter hit count expression' },
1256+
{ 'prop': 'logMessage',
1257+
'msg': 'Enter log expression (to make log point)' },
1258+
]
1259+
1260+
1261+
def GetAdvancedBreakpointOptions( existing_options = None ):
1262+
# TODO: Port the vimscript function to here, call it (initially) from
1263+
# vimscript, then also call it from EditBreakpointOptionsViewBreakpoint
1264+
options = existing_options if existing_options is not None else {}
1265+
for spec in _extended_breakpoint_properties:
1266+
response = utils.AskForInput( spec[ 'msg' ] + ': ',
1267+
options.get( spec[ 'prop' ] ) )
1268+
if response is None:
1269+
return None
1270+
elif response:
1271+
options[ spec[ 'prop' ] ] = response
1272+
1273+
return options

python3/vimspector/debug_session.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,9 @@ def DeleteBreakpointViewBreakpoint( self ):
21222122
def JumpToBreakpointViewBreakpoint( self ):
21232123
self._breakpoints.JumpToBreakpointViewBreakpoint()
21242124

2125+
def EditBreakpointOptionsViewBreakpoint( self ):
2126+
self._breakpoints.EditBreakpointOptionsViewBreakpoint()
2127+
21252128
def JumpToNextBreakpoint( self ):
21262129
self._breakpoints.JumpToNextBreakpoint()
21272130

@@ -2199,6 +2202,9 @@ def ClearLineBreakpoint( self, file_name, line_num ):
21992202
def ClearBreakpoints( self ):
22002203
return self._breakpoints.ClearBreakpoints()
22012204

2205+
def ResetExceptionBreakpoints( self ):
2206+
return self._breakpoints.ResetExceptionBreakpoints()
2207+
22022208
def AddFunctionBreakpoint( self, function, options ):
22032209
return self._breakpoints.AddFunctionBreakpoint( function, options )
22042210

support/test/python/simple_python/.vimspector.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@
126126
}
127127
}
128128
},
129+
"run - no exception bp override": {
130+
"adapter": "debugpy",
131+
"configuration": {
132+
"request": "launch",
133+
"type": "python",
134+
"cwd": "${workspaceRoot}",
135+
"program": "${file}",
136+
"stopOnEntry": false,
137+
"console": "integratedTerminal"
138+
}
139+
},
129140
"run - debugpy-python2": {
130141
"adapter": "debugpy-python2",
131142
"configuration": {

0 commit comments

Comments
 (0)