diff --git a/python3/vimspector/breakpoints.py b/python3/vimspector/breakpoints.py index ea50fd6..b6a975d 100644 --- a/python3/vimspector/breakpoints.py +++ b/python3/vimspector/breakpoints.py @@ -82,7 +82,7 @@ class ProjectBreakpoints( object ): # FIXME: If the adapter type changes, we should probably forget this ? - def ListBreakpoints( self ): + def BreakpointsAsQuickFix( self ): # FIXME: Handling of breakpoints is a mess, split between _codeView and this # object. This makes no sense and should be centralised so that we don't # have this duplication and bug factory. @@ -115,7 +115,8 @@ class ProjectBreakpoints( object ): bp[ 'options' ] ), } ) - vim.eval( 'setqflist( {} )'.format( json.dumps( qf ) ) ) + return qf + def ClearBreakpoints( self ): # These are the user-entered breakpoints. diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 5d07f46..c434c5a 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -979,7 +979,13 @@ class DebugSession( object ): self._stackTraceView.OnStopped( event ) def ListBreakpoints( self ): - return self._breakpoints.ListBreakpoints() + if self._connection: + qf = self._codeView.BreakpointsAsQuickFix() + else: + qf = self._breakpoints.BreakpointsAsQuickFix() + + vim.eval( 'setqflist( {} )'.format( json.dumps( qf ) ) ) + vim.command( 'copen' ) def ToggleBreakpoint( self, options ): return self._breakpoints.ToggleBreakpoint( options ) diff --git a/tests/breakpoints.test.vim b/tests/breakpoints.test.vim index fe3b303..0d2fa6c 100644 --- a/tests/breakpoints.test.vim +++ b/tests/breakpoints.test.vim @@ -452,3 +452,77 @@ endfunction " %bwipeout! " throw "xfail cpptools doesn't seem to honour conditions on function bps" " endfunction + +function! s:CheckQuickFixEntries( entries ) + let qf = getqflist() + let i = 0 + for entry in a:entries + if i >= len( qf ) + call assert_report( "Expected more quickfix entries" ) + endif + for key in keys( entry ) + call assert_equal( entry[ key ], + \ qf[ i ][ key ], + \ key . ' in ' . string( qf[ i ] ) + \ . ' expected ' . entry[ key ] ) + endfor + let i = i+1 + endfor +endfunction + +function! Test_ListBreakpoints() + lcd testdata/cpp/simple + edit simple.cpp + call setpos( '.', [ 0, 15, 1 ] ) + + call vimspector#ListBreakpoints() + wincmd p + cclose + call s:CheckQuickFixEntries( [] ) + + call vimspector#ToggleBreakpoint() + call assert_equal( [], getqflist() ) + + call vimspector#ListBreakpoints() + call s:CheckQuickFixEntries( [ + \ { 'lnum': 15, 'col': 1, 'bufnr': bufnr( 'simple.cpp', 0 ) } + \ ] ) + + " Cursor jumps to the quickfix window + call assert_equal( 'quickfix', &buftype ) + cclose + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 ) + + call vimspector#Launch() + " break on main + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 ) + + call vimspector#ListBreakpoints() + call s:CheckQuickFixEntries( [ + \ { 'lnum': 15, 'col': 1, 'bufnr': bufnr( 'simple.cpp', 0 ) } + \ ] ) + call assert_equal( 'quickfix', &buftype ) + wincmd p + cclose + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 ) + + " Add a breakpoint that moves (from line 5 to line 9) + call cursor( [ 5, 1 ] ) + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 5, 1 ) + call vimspector#ToggleBreakpoint() + + function! Check() + call vimspector#ListBreakpoints() + wincmd p + return assert_equal( 2, len( getqflist() ) ) + endfunction + call WaitForAssert( function( 'Check' ) ) + + call s:CheckQuickFixEntries( [ + \ { 'lnum': 15, 'col': 1, 'bufnr': bufnr( 'simple.cpp', 0 ) }, + \ { 'lnum': 9, 'col': 1, 'bufnr': bufnr( 'simple.cpp', 0 ) }, + \ ] ) + + call vimspector#test#setup#Reset() + %bwipe! +endfunction