From 8d7de7172a9ec742939affb82131336598021cb0 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Mon, 14 Oct 2019 13:39:16 +0100 Subject: [PATCH 1/9] Allow arbitrary ssh args --- python3/vimspector/debug_session.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 42ca1c2..be2b359 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -508,8 +508,8 @@ class DebugSession( object ): # TODO: Use the 'tarminate' request if supportsTerminateRequest set + def _PrepareAttach( self, adapter_config, launch_config ): - atttach_config = adapter_config.get( 'attach' ) if not atttach_config: @@ -520,13 +520,9 @@ class DebugSession( object ): # e.g. expand variables when we use them, not all at once. This would # remove the whole %PID% hack. remote = atttach_config[ 'remote' ] - ssh = [ 'ssh' ] - - if 'account' in remote: - ssh.append( remote[ 'account' ] + '@' + remote[ 'host' ] ) - else: - ssh.append( remote[ 'host' ] ) + ssh = self._GetSSHCommand( remote ) + # FIXME: Why does this not use self._GetCommands ? cmd = ssh + remote[ 'pidCommand' ] self._logger.debug( 'Getting PID: %s', cmd ) @@ -574,12 +570,7 @@ class DebugSession( object ): if 'remote' in run_config: remote = run_config[ 'remote' ] - ssh = [ 'ssh' ] - if 'account' in remote: - ssh.append( remote[ 'account' ] + '@' + remote[ 'host' ] ) - else: - ssh.append( remote[ 'host' ] ) - + ssh = self._GetSSHCommand( remote ) commands = self._GetCommands( remote, 'run' ) for index, command in enumerate( commands ): @@ -599,6 +590,16 @@ class DebugSession( object ): full_cmd ) + def _GetSSHCommand( self, remote ): + ssh = [ 'ssh' ] + remote.get( 'ssh', {} ).get( 'args', [] ) + if 'account' in remote: + ssh.append( remote[ 'account' ] + '@' + remote[ 'host' ] ) + else: + ssh.append( remote[ 'host' ] ) + + return ssh + + def _GetCommands( self, remote, pfx ): commands = remote.get( pfx + 'Commands', None ) From b95fe208456d0d206af379bb8bf1e4362600576f Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Thu, 31 Oct 2019 10:18:23 +0000 Subject: [PATCH 2/9] Frame is not reqiured for evaluation --- python3/vimspector/output.py | 14 +++++++------- python3/vimspector/variables.py | 10 +++++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/python3/vimspector/output.py b/python3/vimspector/output.py index be722af..d4cf1af 100644 --- a/python3/vimspector/output.py +++ b/python3/vimspector/output.py @@ -115,10 +115,6 @@ class OutputView( object ): self._ShowOutput( category ) def Evaluate( self, frame, expression ): - if not frame: - self.Print( 'Console', 'There is no current stack frame' ) - return - console = self._buffers[ 'Console' ].buf utils.AppendToBuffer( console, 'Evaluating: ' + expression ) @@ -132,14 +128,18 @@ class OutputView( object ): utils.AppendToBuffer( console, ' Result: ' + result ) - self._connection.DoRequest( print_result, { + request = { 'command': 'evaluate', 'arguments': { 'expression': expression, 'context': 'repl', - 'frameId': frame[ 'id' ], } - } ) + } + + if frame: + request[ 'arguments' ][ 'frameId' ] = frame[ 'id' ] + + self._connection.DoRequest( print_result, request ) def _ToggleFlag( self, category, flag ): if self._buffers[ category ].flag != flag: diff --git a/python3/vimspector/variables.py b/python3/vimspector/variables.py index 7260a43..f0ff99e 100644 --- a/python3/vimspector/variables.py +++ b/python3/vimspector/variables.py @@ -143,10 +143,12 @@ class VariablesView( object ): def AddWatch( self, frame, expression ): watch = { - 'expression': expression, - 'frameId': frame[ 'id' ], - 'context': 'watch', + 'expression': expression, + 'context': 'watch', } + if frame: + watch[ 'frameId' ] = frame[ 'id' ] + self._watches.append( watch ) self.EvaluateWatches() @@ -395,3 +397,5 @@ class VariablesView( object ): with utils.LetCurrentWindow( self._watch.win ): vim.command( 'set syntax={}'.format( utils.Escape( syntax ) ) ) + +# vim: sw=2 From 2c347c79209b1cd32406fdc20b2ac64ea0c2894b Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Wed, 27 Nov 2019 12:12:34 +0000 Subject: [PATCH 3/9] Enalbe snippets for json --- .ycm_extra_conf.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py index 77feee6..d988326 100644 --- a/.ycm_extra_conf.py +++ b/.ycm_extra_conf.py @@ -26,6 +26,15 @@ def Settings( **kwargs ): } ] } + }, + 'capabilities': { + 'textDocument': { + 'completion': { + 'completionItem': { + 'snippetSupport': True + } + } + } } } From d950352545085e3c1322190a1df8043be19b6bce Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 20 Dec 2019 12:01:44 +0000 Subject: [PATCH 4/9] Install vscode java debugger somewhere --- install_gadget.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/install_gadget.py b/install_gadget.py index f56d48f..8cd8023 100755 --- a/install_gadget.py +++ b/install_gadget.py @@ -107,6 +107,26 @@ GADGETS = { } }, }, + 'vscode-java-debug': { + 'language': 'java', + 'enabled': False, + 'download': { + 'url': 'https://github.com/microsoft/vscode-java-debug/releases/download/' + '${version}/${file_name}', + }, + 'all': { + 'version': '0.23.0', + 'file_name': 'vscode-java-debug-0.23.0.vsix', + 'checksum': + '', + }, + 'adapters': { + "vscode-java": { + "name": "vscode-java", + "port": "ask", + } + }, + }, 'tclpro': { 'language': 'tcl', 'repo': { From 8bb7017a49c83cc3b33e80a2b63fcdd71ac442ff Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 20 Dec 2019 12:02:26 +0000 Subject: [PATCH 5/9] Handle failed breakpoint messages --- python3/vimspector/breakpoints.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/python3/vimspector/breakpoints.py b/python3/vimspector/breakpoints.py index 01da54d..7e767d0 100644 --- a/python3/vimspector/breakpoints.py +++ b/python3/vimspector/breakpoints.py @@ -203,14 +203,18 @@ class ProjectBreakpoints( object ): awaiting = 0 - def response_handler( source, msg ): - if msg: - self._breakpoints_handler.AddBreakpoints( source, msg ) + def response_received(): nonlocal awaiting awaiting = awaiting - 1 if awaiting == 0 and doneHandler: doneHandler() + def response_handler( source, msg ): + if msg: + self._breakpoints_handler.AddBreakpoints( source, msg ) + response_received() + + # TODO: add the _configured_breakpoints to line_breakpoints # TODO: the line numbers might have changed since pressing the F9 key! @@ -244,7 +248,8 @@ class ProjectBreakpoints( object ): 'breakpoints': breakpoints, }, 'sourceModified': False, # TODO: We can actually check this - } + }, + failure_handler = lambda *_: response_received() ) # TODO: Add the _configured_breakpoints to function breakpoints @@ -261,7 +266,8 @@ class ProjectBreakpoints( object ): for bp in self._func_breakpoints if bp[ 'state' ] == 'ENABLED' ], } - } + }, + failure_handler = lambda *_: response_received() ) if self._exception_breakpoints is None: @@ -274,7 +280,8 @@ class ProjectBreakpoints( object ): { 'command': 'setExceptionBreakpoints', 'arguments': self._exception_breakpoints - } + }, + failure_handler = lambda *_: response_received() ) if awaiting == 0 and doneHandler: From 55bb50d2962166d8c6115cd09f32b02ed09fc5d3 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 20 Dec 2019 12:03:04 +0000 Subject: [PATCH 6/9] line sometiems not supplied; source is optional --- python3/vimspector/stack_trace.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python3/vimspector/stack_trace.py b/python3/vimspector/stack_trace.py index bc150f4..cf3be50 100644 --- a/python3/vimspector/stack_trace.py +++ b/python3/vimspector/stack_trace.py @@ -172,8 +172,9 @@ class StackTraceView( object ): if 'line' in frame and frame[ 'line' ] > 0: self._currentFrame = frame return self._session.SetCurrentFrame( self._currentFrame ) + return False - source = frame.get( 'source', {} ) + source = frame.get( 'source' ) or {} if source.get( 'sourceReference', 0 ) > 0: def handle_resolved_source( resolved_source ): frame[ 'source' ] = resolved_source From bbaab0ebc1a2af7dab3110f46cd247c089b2352f Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Thu, 9 Jan 2020 13:20:08 +0000 Subject: [PATCH 7/9] Fix true/false in JSON when setting up adapter --- python3/vimspector/debug_session.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index be2b359..a5a81aa 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -473,10 +473,11 @@ class DebugSession( object ): if 'cwd' not in self._adapter: self._adapter[ 'cwd' ] = os.getcwd() + vim.vars[ '_vimspector_adapter_spec' ] = self._adapter channel_send_func = vim.bindeval( - "vimspector#internal#{}#StartDebugSession( {} )".format( - self._connection_type, - json.dumps( self._adapter ) ) ) + "vimspector#internal#{}#StartDebugSession( " + " g:_vimspector_adapter_spec " + ")".format( self._connection_type ) ) if channel_send_func is None: self._logger.error( "Unable to start debug server" ) From 8a57104a0ede1e01237ffc72dcf2a2e0b4ff220a Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Thu, 9 Jan 2020 14:14:15 +0000 Subject: [PATCH 8/9] Expand references in non-shell variables too --- python3/vimspector/utils.py | 97 +++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index e4f06bc..66e39bb 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -323,58 +323,57 @@ def SetBufferContents( buf, lines, modified=False ): def IsCurrent( window, buf ): return vim.current.window == window and vim.current.window.buffer == buf +def ExpandReferencesInObject( obj, mapping, user_choices ): + if isinstance( obj, dict ): + ExpandReferencesInDict( obj, mapping, user_choices ) + elif isinstance( obj, list ): + for i, _ in enumerate( obj ): + # FIXME: We are assuming that it is a list of string, but could be a + # list of list of a list of dict, etc. + obj[ i ] = ExpandReferencesInObject( obj[ i ], mapping, user_choices ) + elif isinstance( obj, str ): + obj = ExpandReferencesInString( obj, mapping, user_choices ) + + return obj + +def ExpandReferencesInString( orig_s, mapping, user_choices): + s = os.path.expanduser( orig_s ) + s = os.path.expandvars( s ) + + # Parse any variables passed in in mapping, and ask for any that weren't, + # storing the result in mapping + bug_catcher = 0 + while bug_catcher < 100: + ++bug_catcher + + try: + s = string.Template( s ).substitute( mapping ) + break + except KeyError as e: + # HACK: This is seemingly the only way to get the key. str( e ) returns + # the key surrounded by '' for unknowable reasons. + key = e.args[ 0 ] + default_value = user_choices.get( key, None ) + mapping[ key ] = AskForInput( 'Enter value for {}: '.format( key ), + default_value ) + user_choices[ key ] = mapping[ key ] + _logger.debug( "Value for %s not set in %s (from %s): set to %s", + key, + s, + orig_s, + mapping[ key ] ) + except ValueError as e: + UserMessage( 'Invalid $ in string {}: {}'.format( s, e ), + persist = True ) + break + + return s # TODO: Should we just run the substitution on the whole JSON string instead? # That woul dallow expansion in bool and number values, such as ports etc. ? def ExpandReferencesInDict( obj, mapping, user_choices ): - def expand_refs_in_string( orig_s ): - s = os.path.expanduser( orig_s ) - s = os.path.expandvars( s ) - - # Parse any variables passed in in mapping, and ask for any that weren't, - # storing the result in mapping - bug_catcher = 0 - while bug_catcher < 100: - ++bug_catcher - - try: - s = string.Template( s ).substitute( mapping ) - break - except KeyError as e: - # HACK: This is seemingly the only way to get the key. str( e ) returns - # the key surrounded by '' for unknowable reasons. - key = e.args[ 0 ] - default_value = user_choices.get( key, None ) - mapping[ key ] = AskForInput( 'Enter value for {}: '.format( key ), - default_value ) - user_choices[ key ] = mapping[ key ] - _logger.debug( "Value for %s not set in %s (from %s): set to %s", - key, - s, - orig_s, - mapping[ key ] ) - except ValueError as e: - UserMessage( 'Invalid $ in string {}: {}'.format( s, e ), - persist = True ) - break - - return s - - def expand_refs_in_object( obj ): - if isinstance( obj, dict ): - ExpandReferencesInDict( obj, mapping, user_choices ) - elif isinstance( obj, list ): - for i, _ in enumerate( obj ): - # FIXME: We are assuming that it is a list of string, but could be a - # list of list of a list of dict, etc. - obj[ i ] = expand_refs_in_object( obj[ i ] ) - elif isinstance( obj, str ): - obj = expand_refs_in_string( obj ) - - return obj - for k in obj.keys(): - obj[ k ] = expand_refs_in_object( obj[ k ] ) + obj[ k ] = ExpandReferencesInObject( obj[ k ], mapping, user_choices ) def ParseVariables( variables_list, mapping, user_choices ): @@ -416,7 +415,9 @@ def ParseVariables( variables_list, mapping, user_choices ): raise ValueError( "Unsupported variable defn {}: Missing 'shell'".format( n ) ) else: - new_variables[ n ] = v + new_variables[ n ] = ExpandReferencesInObject( v, + mapping, + user_choices ) return new_variables From 9f0becab7b620948aaeb1ffd05b8210df96473c1 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 10 Jan 2020 12:19:58 +0000 Subject: [PATCH 9/9] Flake8 fixes --- python3/vimspector/debug_session.py | 2 +- python3/vimspector/utils.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index a5a81aa..1cf7d52 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -509,7 +509,7 @@ class DebugSession( object ): # TODO: Use the 'tarminate' request if supportsTerminateRequest set - + def _PrepareAttach( self, adapter_config, launch_config ): atttach_config = adapter_config.get( 'attach' ) diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index 66e39bb..d17492b 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -323,6 +323,7 @@ def SetBufferContents( buf, lines, modified=False ): def IsCurrent( window, buf ): return vim.current.window == window and vim.current.window.buffer == buf + def ExpandReferencesInObject( obj, mapping, user_choices ): if isinstance( obj, dict ): ExpandReferencesInDict( obj, mapping, user_choices ) @@ -336,6 +337,7 @@ def ExpandReferencesInObject( obj, mapping, user_choices ): return obj + def ExpandReferencesInString( orig_s, mapping, user_choices): s = os.path.expanduser( orig_s ) s = os.path.expandvars( s ) @@ -369,6 +371,7 @@ def ExpandReferencesInString( orig_s, mapping, user_choices): return s + # TODO: Should we just run the substitution on the whole JSON string instead? # That woul dallow expansion in bool and number values, such as ports etc. ? def ExpandReferencesInDict( obj, mapping, user_choices ):