diff --git a/autoload/vimspector.vim b/autoload/vimspector.vim index 3852753..f37f27e 100644 --- a/autoload/vimspector.vim +++ b/autoload/vimspector.vim @@ -97,8 +97,18 @@ function! vimspector#GoToFrame() abort py3 _vimspector_session.ExpandFrameOrThread() endfunction -function! vimspector#AddWatch( expr ) abort - py3 _vimspector_session.AddWatch( vim.eval( 'a:expr' ) ) +function! vimspector#AddWatch( ... ) abort + if a:0 == 0 + let expr = input( 'Enter watch expression: ' ) + else + let expr = a:1 + endif + + if expr ==# '' + return + endif + + py3 _vimspector_session.AddWatch( vim.eval( 'expr' ) ) endfunction function! vimspector#AddWatchPrompt( expr ) abort diff --git a/python3/vimspector/variables.py b/python3/vimspector/variables.py index e1a21ce..89ff9d1 100644 --- a/python3/vimspector/variables.py +++ b/python3/vimspector/variables.py @@ -59,6 +59,13 @@ class VariablesView( object ): vim.command( 'nnoremap :call vimspector#DeleteWatch()' ) + vim.command( 'nnoremenu 1.1 WinBar.New ' + ':call vimspector#AddWatch()' ) + vim.command( 'nnoremenu 1.2 WinBar.Expand/Collapse ' + ':call vimspector#ExpandVariable()' ) + vim.command( 'nnoremenu 1.3 WinBar.Delete ' + ':call vimspector#DeleteWatch()' ) + utils.SetUpScratchBuffer( self._vars.win.buffer, 'vimspector.Variables' ) utils.SetUpPromptBuffer( self._watch.win.buffer, 'vimspector.Watches', @@ -165,12 +172,18 @@ class VariablesView( object ): current_line = vim.current.window.cursor[ 0 ] + best_index = -1 for index, watch in enumerate( self._watches ): - if '_line' in watch and watch[ '_line' ] == current_line: - del self._watches[ index ] - utils.UserMessage( 'Deleted' ) - self._DrawWatches() - return + if ( '_line' in watch + and watch[ '_line' ] <= current_line + and watch[ '_line' ] > best_index ): + best_index = index + + if best_index >= 0: + del self._watches[ best_index ] + utils.UserMessage( 'Deleted' ) + self._DrawWatches() + return utils.UserMessage( 'No watch found' )