From 51cc6c4d3ac770445a083b726869303f8047dbd4 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Thu, 27 Aug 2020 18:09:48 +0100 Subject: [PATCH] Add VimspectorToggleLog --- CONTRIBUTING.md | 7 +++++++ README.md | 10 ++++++++++ autoload/vimspector.vim | 7 +++++++ plugin/vimspector.vim | 3 +++ python3/vimspector/debug_session.py | 26 +++++++++++++++++++++++++- python3/vimspector/output.py | 6 ++++-- 6 files changed, 56 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9c9d8fb..cfa6c9d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,6 +33,13 @@ work, please always include _all_ of the diagnostics requested in the [issue template][issue-template]. Please do not be offended if your request is ignored if it does not include the requested diagnostics. +The Vimspector log file contains a full trace of the communication between +Vimspector and the debug adapter. This is the primary source of diagnostic +information when something goes wrong that's not a clear Vim traceback. + +If you just want to see the Vimspector log file, use `:VimspectorToggleLog`, +which will tail it in a little window (doesn't work on Windows). + ## Issues The GitHub issue tracker is for *bug reports* and *features requests* for the diff --git a/README.md b/README.md index 4fe0286..1ee251b 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ For a tutorial and usage overview, take a look at the * [Stack Traces](#stack-traces) * [Program Output](#program-output) * [Console](#console) + * [Log View](#log-view) * [Closing debugger](#closing-debugger) * [Debug adapter configuration](#debug-adapter-configuration) * [C, C , Rust, etc.](#c-c-rust-etc) @@ -779,6 +780,15 @@ NOTE: See also [Watches](#watches) above. If the output window is closed, a new one can be opened with `:VimspectorShowOutput Console`. +### Log View + +The Vimspector log file contains a full trace of the communication between +Vimspector and the debug adapter. This is the primary source of diagnostic +information when something goes wrong that's not a Vim traceback. + +If you just want to see the Vimspector log file, use `:VimspectorToggleLog`, +which will tail it in a little window (doesn't work on Windows). + ## Closing debugger To close the debugger, use: diff --git a/autoload/vimspector.vim b/autoload/vimspector.vim index 929a8b3..302b34d 100644 --- a/autoload/vimspector.vim +++ b/autoload/vimspector.vim @@ -209,6 +209,13 @@ function! vimspector#ShowOutputInWindow( win_id, category ) abort \ vim.eval( 'a:category' ) ) endfunction +function! vimspector#ToggleLog() abort + if !s:enabled + return + endif + py3 _vimspector_session.ToggleLog() +endfunction + function! vimspector#ListBreakpoints() abort if !s:enabled return diff --git a/plugin/vimspector.vim b/plugin/vimspector.vim index 0aa5f13..b1e9481 100644 --- a/plugin/vimspector.vim +++ b/plugin/vimspector.vim @@ -91,6 +91,9 @@ command! -bar -nargs=1 -complete=custom,vimspector#CompleteExpr command! -bar -nargs=? -complete=custom,vimspector#CompleteOutput \ VimspectorShowOutput \ call vimspector#ShowOutput( ) +command! -bar + \ VimspectorToggleLog + \ call vimspector#ToggleLog() command! -bar -nargs=1 -complete=custom,vimspector#CompleteExpr \ VimspectorEval \ call vimspector#Evaluate( ) diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 15ff90c..13d4b1e 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -55,6 +55,7 @@ class DebugSession( object ): install.GetGadgetDir( VIMSPECTOR_HOME ) ) self._uiTab = None + self._logView = None self._stackTraceView = None self._variablesView = None self._outputView = None @@ -332,12 +333,15 @@ class DebugSession( object ): return wrapper return decorator + def _HasUI( self ): + return self._uiTab and self._uiTab.valid + def RequiresUI( otherwise=None ): """Decorator, call fct if self._connected else echo warning""" def decorator( fct ): @functools.wraps( fct ) def wrapper( self, *args, **kwargs ): - if not self._uiTab or not self._uiTab.valid: + if not self._HasUI(): utils.UserMessage( 'Vimspector is not active', persist=False, @@ -492,6 +496,26 @@ class DebugSession( object ): def ExpandFrameOrThread( self ): self._stackTraceView.ExpandFrameOrThread() + def ToggleLog( self ): + if self._HasUI(): + return self.ShowOutput( 'Vimspector' ) + + if self._logView and self._logView.WindowIsValid(): + self._logView.Reset() + self._logView = None + return + + if self._logView: + self._logView.Reset() + + # TODO: The UI code is too scattered. Re-organise into a UI class that + # just deals with these thigns like window layout and custmisattion. + vim.command( f'botright { settings.Int( "bottombar_height", 10 ) }new' ) + win = vim.current.window + self._logView = output.OutputView( win, self._api_prefix ) + self._logView.AddLogFileView() + self._logView.ShowOutput( 'Vimspector' ) + @RequiresUI() def ShowOutput( self, category ): if not self._outputView.WindowIsValid(): diff --git a/python3/vimspector/output.py b/python3/vimspector/output.py index 1d349aa..43dd240 100644 --- a/python3/vimspector/output.py +++ b/python3/vimspector/output.py @@ -187,7 +187,6 @@ class OutputView( object ): syntax, self._buffers[ category ].buf ) - def _RenderWinBar( self, category ): if not self._window.valid: return @@ -216,6 +215,9 @@ class OutputView( object ): def GetCategories( self ): return list( self._buffers.keys() ) + def AddLogFileView( self, file_name = utils.LOG_FILE ): + self._CreateBuffer( 'Vimspector', file_name = file_name ) + class DAPOutputView( OutputView ): """Specialised OutputView which adds the DAP Console (REPL)""" @@ -226,7 +228,7 @@ class DAPOutputView( OutputView ): for b in set( BUFFER_MAP.values() ): self._CreateBuffer( b ) - self._CreateBuffer( 'Vimspector', file_name = utils.LOG_FILE ) + self.AddLogFileView() self._ShowOutput( 'Console' ) def ConnectionUp( self, connection ):