From bd09206caf5d441f22dd7362341e9c0e5644f173 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sun, 27 Sep 2020 21:19:47 +0100 Subject: [PATCH] While debugging, use the correct path for breakpoints --- python3/vimspector/breakpoints.py | 5 +- python3/vimspector/code.py | 3 +- .../python/multiple_files/.vimspector.json | 21 ++++++ support/test/python/multiple_files/cow.py | 15 ++++ support/test/python/multiple_files/moo.py | 13 ++++ tests/breakpoints.test.vim | 73 ++++++++++++++++++- tests/breakpoints_doublewidth.test.vim | 73 ++++++++++++++++++- tests/lib/autoload/vimspector/test/signs.vim | 8 +- 8 files changed, 203 insertions(+), 8 deletions(-) create mode 100644 support/test/python/multiple_files/.vimspector.json create mode 100644 support/test/python/multiple_files/cow.py create mode 100644 support/test/python/multiple_files/moo.py diff --git a/python3/vimspector/breakpoints.py b/python3/vimspector/breakpoints.py index 617ae6c..6ab14f5 100644 --- a/python3/vimspector/breakpoints.py +++ b/python3/vimspector/breakpoints.py @@ -268,7 +268,10 @@ class ProjectBreakpoints( object ): awaiting = awaiting + 1 self._connection.DoRequest( - lambda msg: response_handler( source, msg ), + # The source=source here is critical to ensure that we capture each + # source in the iteration, rather than ending up passing the same source + # to each callback. + lambda msg, source=source: response_handler( source, msg ), { 'command': 'setBreakpoints', 'arguments': { diff --git a/python3/vimspector/code.py b/python3/vimspector/code.py index c462272..ab4fb39 100644 --- a/python3/vimspector/code.py +++ b/python3/vimspector/code.py @@ -119,7 +119,6 @@ class CodeView( object ): return False self._current_frame = frame - self._DisplayPC() if not self._window.valid: return False @@ -148,6 +147,8 @@ class CodeView( object ): self.current_syntax = utils.ToUnicode( vim.current.buffer.options[ 'syntax' ] ) + self.ShowBreakpoints() + return True def Clear( self ): diff --git a/support/test/python/multiple_files/.vimspector.json b/support/test/python/multiple_files/.vimspector.json new file mode 100644 index 0000000..aff2cb6 --- /dev/null +++ b/support/test/python/multiple_files/.vimspector.json @@ -0,0 +1,21 @@ +{ + "configurations": { + "run": { + "adapter": "debugpy", + "default": true, + "configuration": { + "request": "launch", + "program": "${workspaceRoot}/moo.py", + "cwd": "${workspaceRoot}", + "stopOnEntry": true + }, + "breakpoints": { + "exception": { + "raised": "N", + "uncaught": "", + "userUnhandled": "" + } + } + } + } +} diff --git a/support/test/python/multiple_files/cow.py b/support/test/python/multiple_files/cow.py new file mode 100644 index 0000000..88d7082 --- /dev/null +++ b/support/test/python/multiple_files/cow.py @@ -0,0 +1,15 @@ +def Say( *args, **kwargs ): + print( *args, **kwargs ) + + + + + + + + + + + +def Quiet(): + pass diff --git a/support/test/python/multiple_files/moo.py b/support/test/python/multiple_files/moo.py new file mode 100644 index 0000000..f8da4b1 --- /dev/null +++ b/support/test/python/multiple_files/moo.py @@ -0,0 +1,13 @@ +import cow + + +def Moo(): + for i in range( 1, 100 ): + cow.Say( 'Moo' ) + + for i in range( 1, 100 ): + cow.Say( 'Ooom' ) + + +if __name__ == '__main__': + Moo() diff --git a/tests/breakpoints.test.vim b/tests/breakpoints.test.vim index b380837..f6cafa5 100644 --- a/tests/breakpoints.test.vim +++ b/tests/breakpoints.test.vim @@ -576,7 +576,7 @@ function! Test_Custom_Breakpoint_Priority() \ 'vimspectorBPDisabled', \ 4 ) call vimspector#ToggleBreakpoint() - call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 15 ) + call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 16 ) call setpos( '.', [ 0, 17, 1 ] ) call vimspector#ToggleBreakpoint( { 'condition': '1' } ) @@ -663,7 +663,7 @@ function! Test_Custom_Breakpoint_Priority_Partial() \ 'vimspectorBPDisabled', \ 4 ) call vimspector#ToggleBreakpoint() - call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 15 ) + call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 16 ) call setpos( '.', [ 0, 17, 1 ] ) call vimspector#ToggleBreakpoint( { 'condition': '1' } ) @@ -723,3 +723,72 @@ function! Test_Custom_Breakpoint_Priority_Partial() %bwipeout! unlet! g:vimspector_sign_priority endfunction + + +function! Test_Add_Line_BP_In_Other_File_While_Debugging() + let moo = 'moo.py' + let cow = 'cow.py' + lcd ../support/test/python/multiple_files + exe 'edit' moo + + call vimspector#Launch() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( moo, 1, 1 ) + call vimspector#test#signs#AssertPCIsAtLineInBuffer( moo, 1 ) + + call cursor( 6, 3 ) + call vimspector#ToggleBreakpoint() + call vimspector#test#signs#AssertPCIsAtLineInBuffer( moo, 1 ) + call WaitForAssert( {-> + \vimspector#test#signs#AssertSignGroupSingletonAtLine( + \ 'VimspectorCode', + \ 6, + \ 'vimspectorBP', + \ 9 ) } ) + + exe 'edit' cow + call cursor( 2, 1 ) + call vimspector#ToggleBreakpoint() + call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 6 ) + call WaitForAssert( {-> + \ vimspector#test#signs#AssertSignGroupSingletonAtLine( + \ 'VimspectorCode', + \ 2, + \ 'vimspectorBP', + \ 9 ) } ) + + call vimspector#Continue() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( moo, 6, 1 ) + call vimspector#test#signs#AssertPCIsAtLineInBuffer( moo, 6 ) + + call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 2 ) + call vimspector#test#signs#AssertSignAtLine( + \ 'VimspectorCode', + \ 6, + \ 'vimspectorBP', + \ 9 ) + call vimspector#test#signs#AssertSignAtLine( + \ 'VimspectorCode', + \ 6, + \ 'vimspectorPCBP', + \ 200 ) + + call vimspector#Continue() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( cow, 2, 1 ) + call vimspector#test#signs#AssertPCIsAtLineInBuffer( cow, 2 ) + + call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 6 ) + call vimspector#test#signs#AssertSignAtLine( + \ 'VimspectorCode', + \ 2, + \ 'vimspectorBP', + \ 9 ) + call vimspector#test#signs#AssertSignAtLine( + \ 'VimspectorCode', + \ 2, + \ 'vimspectorPCBP', + \ 200 ) + + lcd - + call vimspector#test#setup#Reset() + %bwipe! +endfunction diff --git a/tests/breakpoints_doublewidth.test.vim b/tests/breakpoints_doublewidth.test.vim index 12756da..8ab35bb 100644 --- a/tests/breakpoints_doublewidth.test.vim +++ b/tests/breakpoints_doublewidth.test.vim @@ -577,7 +577,7 @@ function! Test_Custom_Breakpoint_Priority() \ 'vimspectorBPDisabled', \ 4 ) call vimspector#ToggleBreakpoint() - call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 15 ) + call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 16 ) call setpos( '.', [ 0, 17, 1 ] ) call vimspector#ToggleBreakpoint( { 'condition': '1' } ) @@ -664,7 +664,7 @@ function! Test_Custom_Breakpoint_Priority_Partial() \ 'vimspectorBPDisabled', \ 4 ) call vimspector#ToggleBreakpoint() - call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 15 ) + call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 16 ) call setpos( '.', [ 0, 17, 1 ] ) call vimspector#ToggleBreakpoint( { 'condition': '1' } ) @@ -724,3 +724,72 @@ function! Test_Custom_Breakpoint_Priority_Partial() %bwipeout! unlet! g:vimspector_sign_priority endfunction + + +function! Test_Add_Line_BP_In_Other_File_While_Debugging() + let moo = 'moo.py' + let cow = 'cow.py' + lcd ../support/test/python/multiple_files + exe 'edit' moo + + call vimspector#Launch() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( moo, 1, 1 ) + call vimspector#test#signs#AssertPCIsAtLineInBuffer( moo, 1 ) + + call cursor( 6, 3 ) + call vimspector#ToggleBreakpoint() + call vimspector#test#signs#AssertPCIsAtLineInBuffer( moo, 1 ) + call WaitForAssert( {-> + \vimspector#test#signs#AssertSignGroupSingletonAtLine( + \ 'VimspectorCode', + \ 6, + \ 'vimspectorBP', + \ 9 ) } ) + + exe 'edit' cow + call cursor( 2, 1 ) + call vimspector#ToggleBreakpoint() + call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 6 ) + call WaitForAssert( {-> + \ vimspector#test#signs#AssertSignGroupSingletonAtLine( + \ 'VimspectorCode', + \ 2, + \ 'vimspectorBP', + \ 9 ) } ) + + call vimspector#Continue() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( moo, 6, 1 ) + call vimspector#test#signs#AssertPCIsAtLineInBuffer( moo, 6 ) + + call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 2 ) + call vimspector#test#signs#AssertSignAtLine( + \ 'VimspectorCode', + \ 6, + \ 'vimspectorBP', + \ 9 ) + call vimspector#test#signs#AssertSignAtLine( + \ 'VimspectorCode', + \ 6, + \ 'vimspectorPCBP', + \ 200 ) + + call vimspector#Continue() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( cow, 2, 1 ) + call vimspector#test#signs#AssertPCIsAtLineInBuffer( cow, 2 ) + + call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorCode', 6 ) + call vimspector#test#signs#AssertSignAtLine( + \ 'VimspectorCode', + \ 2, + \ 'vimspectorBP', + \ 9 ) + call vimspector#test#signs#AssertSignAtLine( + \ 'VimspectorCode', + \ 2, + \ 'vimspectorPCBP', + \ 200 ) + + lcd - + call vimspector#test#setup#Reset() + %bwipe! +endfunction diff --git a/tests/lib/autoload/vimspector/test/signs.vim b/tests/lib/autoload/vimspector/test/signs.vim index 66cca19..a6bb698 100644 --- a/tests/lib/autoload/vimspector/test/signs.vim +++ b/tests/lib/autoload/vimspector/test/signs.vim @@ -70,7 +70,11 @@ function! vimspector#test#signs#AssertSignGroupSingletonAtLine( group, endfunction -function! vimspector#test#signs#AssertSignAtLine( group, line, sign_name, priority ) abort +function! vimspector#test#signs#AssertSignAtLine( + \ group, + \ line, + \ sign_name, + \ priority ) abort let signs = sign_getplaced( '%', { \ 'group': a:group, @@ -106,7 +110,7 @@ endfunction function! vimspector#test#signs#AssertSignGroupEmptyAtLine( group, line ) abort let signs = sign_getplaced( '%', { \ 'group': a:group, - \ 'lnum': line( '.' ) + \ 'lnum': a:line, \ } ) return assert_equal( 1,