Merge pull request #156 from puremourning/watch-improve

Improve the watch window with a WinBar
This commit is contained in:
mergify[bot] 2020-04-27 20:52:42 +00:00 • committed by GitHub
commit 16e1ae143b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 22 deletions

View file

@ -59,10 +59,54 @@ For a tutorial and usage overview, take a look at the
<!--te--> <!--te-->
# Motivation
A message from the author about the motivation for this plugin:
> Many development environments have a built-in debugger. I spend an inordinate
> amount of my time in Vim. I do all my development in Vim and I have even
> customised my workflows for building code, running tests etc.
>
> For many years I have observed myself, friends and colleagues have been
> writing `printf`, `puts`, `print`, etc. debugging statements in all sorts of
> files simply because there is no _easy_ way to run a debugger for _whatever_
> language we happen to be developing in.
>
> I truly believe that interactive, graphical debugging environments are the
> best way to understand and reason about both unfamiliar and familiar code, and
> that the lack of ready, simple access to a debugger is a huge hidden
> productivity hole for many.
>
> Don't get me wrong, I know there are literally millions of developers out
> there that are more than competent at developing without a graphical debugger,
> but I maintain that if they had the ability to _just press a key_ and jump
> into the debugger, it would be faster and more enjoyable that just cerebral
> code comprehension.
>
> I created Vimsepctor because I find changing tools frustrating. `gdb` for c++,
> `pdb` for python, etc. Each has its own syntax. Each its own lexicon. Each its
> own foibles.
>
> I designed the configuration system in such a way that the configuration can
> be committed to source control so that it _just works_ for any of your
> colleagues, friends, collaborators or complete strangers.
>
> I made remote debugging a first-class feature because that's a primary use
> case for me in my job.
>
> With Vimspector I can _just hit `<F5>`_ in all of the languages I develop in
> and debug locally or remotely using the exact same workflow, mappings and UI.
> I have integrated this with my Vim in such a way that I can hit a button and
> _run the test under the cursor in Vimspector_. This kind of integration has
> massively improved my workflow and productivity. It's even made the process
> of learning a new codebase... fun.
>
> \- Ben Jackson, Creator.
# Features and Usage # Features and Usage
The plugin is a capable Vim graphical debugger for multiple languages. The plugin is a capable Vim graphical debugger for multiple languages.
It's mostly tested for c++ and python, but in theory supports any It's mostly tested for c++, python and TCL, but in theory supports any
language that Visual Studio Code supports (but see caveats). language that Visual Studio Code supports (but see caveats).
The [Vimspector website][website] has an overview of the UI, along with basic The [Vimspector website][website] has an overview of the UI, along with basic

View file

@ -97,8 +97,18 @@ function! vimspector#GoToFrame() abort
py3 _vimspector_session.ExpandFrameOrThread() py3 _vimspector_session.ExpandFrameOrThread()
endfunction endfunction
function! vimspector#AddWatch( expr ) abort function! vimspector#AddWatch( ... ) abort
py3 _vimspector_session.AddWatch( vim.eval( 'a:expr' ) ) 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 endfunction
function! vimspector#AddWatchPrompt( expr ) abort function! vimspector#AddWatchPrompt( expr ) abort

View file

@ -59,6 +59,13 @@ class VariablesView( object ):
vim.command( vim.command(
'nnoremap <buffer> <DEL> :call vimspector#DeleteWatch()<CR>' ) 'nnoremap <buffer> <DEL> :call vimspector#DeleteWatch()<CR>' )
vim.command( 'nnoremenu 1.1 WinBar.New '
':call vimspector#AddWatch()<CR>' )
vim.command( 'nnoremenu 1.2 WinBar.Expand/Collapse '
':call vimspector#ExpandVariable()<CR>' )
vim.command( 'nnoremenu 1.3 WinBar.Delete '
':call vimspector#DeleteWatch()<CR>' )
utils.SetUpScratchBuffer( self._vars.win.buffer, 'vimspector.Variables' ) utils.SetUpScratchBuffer( self._vars.win.buffer, 'vimspector.Variables' )
utils.SetUpPromptBuffer( self._watch.win.buffer, utils.SetUpPromptBuffer( self._watch.win.buffer,
'vimspector.Watches', 'vimspector.Watches',
@ -165,12 +172,18 @@ class VariablesView( object ):
current_line = vim.current.window.cursor[ 0 ] current_line = vim.current.window.cursor[ 0 ]
best_index = -1
for index, watch in enumerate( self._watches ): for index, watch in enumerate( self._watches ):
if '_line' in watch and watch[ '_line' ] == current_line: if ( '_line' in watch
del self._watches[ index ] and watch[ '_line' ] <= current_line
utils.UserMessage( 'Deleted' ) and watch[ '_line' ] > best_index ):
self._DrawWatches() best_index = index
return
if best_index >= 0:
del self._watches[ best_index ]
utils.UserMessage( 'Deleted' )
self._DrawWatches()
return
utils.UserMessage( 'No watch found' ) utils.UserMessage( 'No watch found' )