From 355f0f0e0c09569f0dba29a12be55075da4d16dc Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 17 Jan 2020 00:02:24 +0000 Subject: [PATCH] Implement command line completion for watch/eval --- autoload/vimspector.vim | 5 +++- plugin/vimspector.vim | 4 +-- .../vimspector/debug_adapter_connection.py | 27 +++++++++++++++++++ python3/vimspector/debug_session.py | 20 ++++++++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/autoload/vimspector.vim b/autoload/vimspector.vim index c3ead44..f2b39d5 100644 --- a/autoload/vimspector.vim +++ b/autoload/vimspector.vim @@ -121,7 +121,10 @@ function! vimspector#CompleteOutput( ArgLead, CmdLine, CursorPos ) abort endfunction function! vimspector#CompleteExpr( ArgLead, CmdLine, CursorPos ) abort - return [] + return join( py3eval( '_vimspector_session.GetCompletionsSync( ' + \.' vim.eval( "a:CmdLine" ),' + \.' int( vim.eval( "a:CursorPos" ) ) )' ), + \ "\n" ) endfunction " Boilerplate {{{ diff --git a/plugin/vimspector.vim b/plugin/vimspector.vim index 61c956a..0c71090 100644 --- a/plugin/vimspector.vim +++ b/plugin/vimspector.vim @@ -71,13 +71,13 @@ elseif s:mappings ==# 'HUMAN' nmap VimspectorStepOut endif -command! -bar -nargs=1 -complete=customlist,vimspector#CompleteExpr +command! -bar -nargs=1 -complete=custom,vimspector#CompleteExpr \ VimspectorWatch \ call vimspector#AddWatch( ) command! -bar -nargs=1 -complete=custom,vimspector#CompleteOutput \ VimspectorShowOutput \ call vimspector#ShowOutput( ) -command! -bar -nargs=1 -complete=customlist,vimspector#CompleteExpr +command! -bar -nargs=1 -complete=custom,vimspector#CompleteExpr \ VimspectorEval \ call vimspector#Evaluate( ) command! -bar diff --git a/python3/vimspector/debug_adapter_connection.py b/python3/vimspector/debug_adapter_connection.py index 73a4549..295b83d 100644 --- a/python3/vimspector/debug_adapter_connection.py +++ b/python3/vimspector/debug_adapter_connection.py @@ -65,6 +65,33 @@ class DebugAdapterConnection( object ): if not self._SendMessage( msg ): self._AbortRequest( request, 'Unable to send message' ) + + def DoRequestSync( self, msg, timeout = 5000 ): + result = {} + + def handler( msg ): + result[ 'response' ] = msg + + def failure_handler( reason, msg ): + result[ 'response' ] = msg + result[ 'exception' ] = RuntimeError( reason ) + + self.DoRequest( handler, msg, failure_handler, timeout ) + + bug_catcher = 1000 + while not result and bug_catcher >= 0: + vim.command( 'sleep 10m' ) + bug_catcher -= 10 + + if result.get( 'exception' ) is not None: + raise result[ 'exception' ] + + if result.get( 'response' ) is None: + raise RuntimeError( "No response" ) + + return result[ 'response' ] + + def OnRequestTimeout( self, timer_id ): request_id = None for seq, request in self._outstanding_requests.items(): diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index a4d801b..474e3d0 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -406,6 +406,26 @@ class DebugSession( object ): def GetOutputBuffers( self ): return self._outputView.GetCategories() + def GetCompletionsSync( self, text_line, column_in_bytes ): + if not self._server_capabilities.get( 'supportsCompletionsRequest' ): + return [] + + response = self._connection.DoRequestSync( { + 'command': 'completions', + 'arguments': { + 'frameId': self._stackTraceView.GetCurrentFrame()[ 'id' ], + # TODO: encoding ? bytes/codepoints + 'text': text_line, + 'column': column_in_bytes + } + } ) + # TODO: + # - start / length + # - sortText + return [ i.get( 'text' ) or i[ 'label' ] + for i in response[ 'body' ][ 'targets' ] ] + + def _SetUpUI( self ): vim.command( 'tabnew' ) self._uiTab = vim.current.tabpage