From 7723d58cf804fe4feea55d884c99e7047a8220f2 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 5 Mar 2021 21:09:39 +0000 Subject: [PATCH 1/2] Allow forcing selection from the menu with F5 --- autoload/vimspector.vim | 4 ++-- plugin/vimspector.vim | 3 +++ python3/vimspector/debug_session.py | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/autoload/vimspector.vim b/autoload/vimspector.vim index e94a177..c4a1756 100644 --- a/autoload/vimspector.vim +++ b/autoload/vimspector.vim @@ -41,11 +41,11 @@ function! s:Enabled() abort return s:enabled endfunction -function! vimspector#Launch() abort +function! vimspector#Launch( ... ) abort if !s:Enabled() return endif - py3 _vimspector_session.Start() + py3 _vimspector_session.Start( *vim.eval( 'a:000' ) ) endfunction function! vimspector#LaunchWithSettings( settings ) abort diff --git a/plugin/vimspector.vim b/plugin/vimspector.vim index 53855ef..24f8914 100644 --- a/plugin/vimspector.vim +++ b/plugin/vimspector.vim @@ -35,6 +35,8 @@ let s:mappings = get( g:, 'vimspector_enable_mappings', '' ) nnoremap VimspectorContinue \ :call vimspector#Continue() +nnoremap VimspectorLaunch + \ :call vimspector#Launch( v:true ) nnoremap VimspectorStop \ :call vimspector#Stop() nnoremap VimspectorRestart @@ -79,6 +81,7 @@ if s:mappings ==# 'VISUAL_STUDIO' nmap VimspectorStepOut elseif s:mappings ==# 'HUMAN' nmap VimspectorContinue + nmap VimspectorLaunch nmap VimspectorStop nmap VimspectorRestart nmap VimspectorPause diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 16f69be..5e49302 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -99,7 +99,7 @@ class DebugSession( object ): return launch_config_file, configurations - def Start( self, launch_variables = None ): + def Start( self, force_choose=False, launch_variables = None ): # We mutate launch_variables, so don't mutate the default argument. # https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments if launch_variables is None: @@ -134,6 +134,11 @@ class DebugSession( object ): if 'configuration' in launch_variables: configuration_name = launch_variables.pop( 'configuration' ) + elif force_choose: + # Always display the menu + configuration_name = utils.SelectFromList( + 'Which launch configuration?', + sorted( configurations.keys() ) ) elif ( len( configurations ) == 1 and next( iter( configurations.values() ) ).get( "autoselect", True ) ): configuration_name = next( iter( configurations.keys() ) ) From f3f458cdc7c48b5825341a4f58c4e157bfcb28fd Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 12 Mar 2021 20:10:55 +0000 Subject: [PATCH 2/2] Update README --- README.md | 51 ++++++++++++++++++++++------------------- tests/mappings.test.vim | 26 +++++++++++++++++++++ 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 42d4765..ed5cfe2 100644 --- a/README.md +++ b/README.md @@ -695,17 +695,17 @@ loading vimspector**: let g:vimspector_enable_mappings = 'VISUAL_STUDIO' ``` -| Key | Function | API | -| --- | --- | --- | -| `F5` | When debugging, continue. Otherwise start debugging. | `vimspector#Continue()` | -| `Shift F5` | Stop debugging. | `vimspector#Stop()` | -| `Ctrl Shift F5` | Restart debugging with the same configuration. | `vimspector#Restart()` | -| `F6` | Pause debuggee. | `vimspector#Pause()` | -| `F9` | Toggle line breakpoint on the current line. | `vimspector#ToggleBreakpoint()` | -| `Shift F9` | Add a function breakpoint for the expression under cursor | `vimspector#AddFunctionBreakpoint( '' )` | -| `F10` | Step Over | `vimspector#StepOver()` | -| `F11` | Step Into | `vimspector#StepInto()` | -| `Shift F11` | Step out of current function scope | `vimspector#StepOut()` | +| Key | Function | API | +| --- | --- | --- | +| `F5` | When debugging, continue. Otherwise start debugging. | `vimspector#Continue()` | +| `Shift F5` | Stop debugging. | `vimspector#Stop()` | +| `Ctrl Shift F5` | Restart debugging with the same configuration. | `vimspector#Restart()` | +| `F6` | Pause debuggee. | `vimspector#Pause()` | +| `F9` | Toggle line breakpoint on the current line. | `vimspector#ToggleBreakpoint()` | +| `Shift F9` | Add a function breakpoint for the expression under cursor | `vimspector#AddFunctionBreakpoint( '' )` | +| `F10` | Step Over | `vimspector#StepOver()` | +| `F11` | Step Into | `vimspector#StepInto()` | +| `Shift F11` | Step out of current function scope | `vimspector#StepOut()` | ## Human Mode @@ -720,19 +720,20 @@ loading vimspector**: let g:vimspector_enable_mappings = 'HUMAN' ``` -| Key | Function | API | -| --- | --- | --- | -| `F5` | When debugging, continue. Otherwise start debugging. | `vimspector#Continue()` | -| `F3` | Stop debugging. | `vimspector#Stop()` | -| `F4` | Restart debugging with the same configuration. | `vimspector#Restart()` | -| `F6` | Pause debuggee. | `vimspector#Pause()` | -| `F9` | Toggle line breakpoint on the current line. | `vimspector#ToggleBreakpoint()` | +| Key | Function | API | +| --- | --- | --- | +| `F5` | When debugging, continue. Otherwise start debugging. | `vimspector#Continue()` | +| `F5` | Start debugging, do not default the debug profile | `vimspector#Launch( v:true )` | +| `F3` | Stop debugging. | `vimspector#Stop()` | +| `F4` | Restart debugging with the same configuration. | `vimspector#Restart()` | +| `F6` | Pause debuggee. | `vimspector#Pause()` | +| `F9` | Toggle line breakpoint on the current line. | `vimspector#ToggleBreakpoint()` | | `F9` | Toggle conditional line breakpoint on the current line. | `vimspector#ToggleBreakpoint( { trigger expr, hit count expr } )` | -| `F8` | Add a function breakpoint for the expression under cursor | `vimspector#AddFunctionBreakpoint( '' )` | -| `F8` | Run to Cursor | `vimspector#RunToCursor()` | -| `F10` | Step Over | `vimspector#StepOver()` | -| `F11` | Step Into | `vimspector#StepInto()` | -| `F12` | Step out of current function scope | `vimspector#StepOut()` | +| `F8` | Add a function breakpoint for the expression under cursor | `vimspector#AddFunctionBreakpoint( '' )` | +| `F8` | Run to Cursor | `vimspector#RunToCursor()` | +| `F10` | Step Over | `vimspector#StepOver()` | +| `F11` | Step Into | `vimspector#StepInto()` | +| `F12` | Step out of current function scope | `vimspector#StepOut()` | In addition, I recommend adding a mapping to `VimspectorBalloonEval`, in normal and visual modes, for example: @@ -746,6 +747,10 @@ nmap di VimspectorBalloonEval xmap di VimspectorBalloonEval ``` +If you would like to have custom mappings, or mappings active only while +debugging, then take a look at the +[customisation sectoin](#custom-mappings-while-debugging). + # Usage and API This section defines detailed usage instructions, organised by feature. For most diff --git a/tests/mappings.test.vim b/tests/mappings.test.vim index b0e288c..862b06d 100644 --- a/tests/mappings.test.vim +++ b/tests/mappings.test.vim @@ -141,3 +141,29 @@ function! Test_Use_Mappings_HUMAN() %bwipeout! endfunction + +function! SetUp_Test_Use_Mappings_HUMAN_ForceMenu() + let g:vimspector_enable_mappings = 'HUMAN' +endfunction + +function! Test_Use_Mappings_HUMAN_ForceMenu() + call ThisTestIsFlaky() + lcd testdata/cpp/simple + edit simple.cpp + call setpos( '.', [ 0, 15, 1 ] ) + + " Comma is the leader + py3 <", "xt" )' ) + sfl.assert_called() +EOF + + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 ) + + call vimspector#test#setup#Reset() + + lcd - + %bwipeout! +endfunction