From ed6beff03b99e38ff124e8041cb65d2207649692 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sun, 15 Dec 2019 10:12:19 +0000 Subject: [PATCH] Enable syntax highlighting for watches and locals --- python3/vimspector/code.py | 5 +++++ python3/vimspector/debug_session.py | 1 + python3/vimspector/utils.py | 6 ++++++ python3/vimspector/variables.py | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/python3/vimspector/code.py b/python3/vimspector/code.py index f28a1b5..509008d 100644 --- a/python3/vimspector/code.py +++ b/python3/vimspector/code.py @@ -27,6 +27,7 @@ class CodeView( object ): self._terminal_window = None self._terminal_buffer_number = None + self.current_syntax = None self._logger = logging.getLogger( __name__ ) utils.SetUpLogging( self._logger ) @@ -93,6 +94,9 @@ class CodeView( object ): frame[ 'line' ], frame[ 'source' ][ 'path' ] ) ) + self.current_syntax = utils.ToUnicode( + vim.current.buffer.options[ 'syntax' ] ) + return True def Clear( self ): @@ -102,6 +106,7 @@ class CodeView( object ): self._signs[ 'vimspectorPC' ] = None self._UndisplaySigns() + self.current_syntax = None def Reset( self ): self.ClearBreakpoints() diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 5e98491..42b7cb8 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -427,6 +427,7 @@ class DebugSession( object ): return False if frame: + self._variablesView.SetSyntax( self._codeView.current_syntax ) self._variablesView.LoadScopes( frame ) self._variablesView.EvaluateWatches() else: diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index 73e2fea..e4f06bc 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -434,3 +434,9 @@ def GetBufferFilepath( buf ): return '' return os.path.normpath( buf.name ) + + +def ToUnicode( b ): + if isinstance( b, bytes ): + return b.decode( 'utf-8' ) + return b diff --git a/python3/vimspector/variables.py b/python3/vimspector/variables.py index d9882c8..a8a5d0f 100644 --- a/python3/vimspector/variables.py +++ b/python3/vimspector/variables.py @@ -31,6 +31,7 @@ class VariablesView( object ): self._vars = View( variables_win, {}, self._DrawScopes ) self._watch = View( watches_win, {}, self._DrawWatches ) self._connection = connection + self._current_syntax = '' # Allows us to hit to expand/collapse variables with utils.LetCurrentWindow( self._vars.win ): @@ -91,6 +92,7 @@ class VariablesView( object ): utils.ClearBuffer( self._vars.win.buffer ) with utils.ModifiableScratchBuffer( self._watch.win.buffer ): utils.ClearBuffer( self._watch.win.buffer ) + self._current_syntax = '' def ConnectionUp( self, connection ): self._connection = connection @@ -373,3 +375,19 @@ class VariablesView( object ): 'context': 'hover', } }, failure_handler ) + + + def SetSyntax( self, syntax ): + if not syntax: + syntax = '' + + if self._current_syntax == syntax: + return + + self._current_syntax = syntax + + with utils.LetCurrentWindow( self._vars.win ): + vim.command( 'set syntax={}'.format( utils.Escape( syntax ) ) ) + + with utils.LetCurrentWindow( self._watch.win ): + vim.command( 'set syntax={}'.format( utils.Escape( syntax ) ) )