From 733843a6d47ef6f17166d59e6f50d3abc66f9a9b Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Thu, 3 Sep 2020 17:46:06 +0100 Subject: [PATCH] Support completion for console and watches. Add omnifunc for prompt buffers This synchronous completion can be used with any completion system including built-in CTRL-X CTRL-O. The filetype of the prompt buffers is set to VimspectorPrompt so that it can be identified by completion systems. For example, this works well with YCM: let g:ycm_semantic_triggers = { \ 'VimspectorPrompt': [ '.', '->', ':', '<' ] \ } --- autoload/vimspector.vim | 103 +++++++++++++++++++++++++++- python3/vimspector/debug_session.py | 3 +- python3/vimspector/output.py | 3 +- python3/vimspector/utils.py | 9 ++- python3/vimspector/variables.py | 3 +- 5 files changed, 113 insertions(+), 8 deletions(-) diff --git a/autoload/vimspector.vim b/autoload/vimspector.vim index 302b34d..df0b6a9 100644 --- a/autoload/vimspector.vim +++ b/autoload/vimspector.vim @@ -232,17 +232,114 @@ function! vimspector#CompleteOutput( ArgLead, CmdLine, CursorPos ) abort return join( buffers, "\n" ) endfunction +py3 < s:latest_completion_request.start_pos + " fix up the text (insert anything that is already present in the line + " that would be erased by the fixed-up earlier start position) + " + " both start_pos and item.start are 1-based + let item.text = s:latest_completion_request.text[ + \ s:latest_completion_request.start_pos + pfxlen - 1 : + \ item.start + pfxlen - 1 ] . item.text + endif + + call add( items, { 'word': item.text, + \ 'abbr': item.label, + \ 'menu': get( item, 'type', '' ), + \ 'icase': 1, + \ } ) + endfor + let s:latest_completion_request = {} + return { 'words': items, 'refresh': 'always' } + endif +endfunction + +function! vimspector#OmniFuncWatch( find_start, query ) abort + return vimspector#CompleteFuncSync( 'Expression: ', a:find_start, a:query ) +endfunction + +function! vimspector#OmniFuncConsole( find_start, query ) abort + return vimspector#CompleteFuncSync( '> ', a:find_start, a:query ) +endfunction + function! vimspector#Install( bang, ... ) abort if !s:enabled return diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 5a542c6..6a40294 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -554,8 +554,7 @@ class DebugSession( object ): # TODO: # - start / length # - sortText - return [ i.get( 'text' ) or i[ 'label' ] - for i in response[ 'body' ][ 'targets' ] ] + return response[ 'body' ][ 'targets' ] def _SetUpUI( self ): diff --git a/python3/vimspector/output.py b/python3/vimspector/output.py index 90df09d..71c81e9 100644 --- a/python3/vimspector/output.py +++ b/python3/vimspector/output.py @@ -192,7 +192,8 @@ class OutputView( object ): utils.SetUpPromptBuffer( tab_buffer.buf, name, '> ', - 'vimspector#EvaluateConsole' ) + 'vimspector#EvaluateConsole', + 'vimspector#OmniFuncConsole' ) else: utils.SetUpHiddenBuffer( tab_buffer.buf, name ) diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index 17c8166..2874635 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -135,7 +135,7 @@ def SetUpHiddenBuffer( buf, name ): buf.name = name -def SetUpPromptBuffer( buf, name, prompt, callback ): +def SetUpPromptBuffer( buf, name, prompt, callback, omnifunc ): # This feature is _super_ new, so only enable when available if not Exists( '*prompt_setprompt' ): return SetUpHiddenBuffer( buf, name ) @@ -148,6 +148,7 @@ def SetUpPromptBuffer( buf, name, prompt, callback ): buf.options[ 'buflisted' ] = False buf.options[ 'bufhidden' ] = 'hide' buf.options[ 'textwidth' ] = 0 + buf.options[ 'omnifunc' ] = omnifunc buf.name = name vim.eval( "prompt_setprompt( {0}, '{1}' )".format( buf.number, @@ -156,6 +157,12 @@ def SetUpPromptBuffer( buf, name, prompt, callback ): buf.number, Escape( callback ) ) ) + # This serves a few purposes, mainly to ensure that completion systems have + # something to work with. In particular it makes YCM use its identifier engine + # and you can config ycm to trigger semantic (annoyingly, synchronously) using + # some let g:ycm_auto_trggier + Call( 'setbufvar', buf.number, '&filetype', 'VimspectorPrompt' ) + def SetUpUIWindow( win ): win.options[ 'wrap' ] = False diff --git a/python3/vimspector/variables.py b/python3/vimspector/variables.py index d82090a..5694e46 100644 --- a/python3/vimspector/variables.py +++ b/python3/vimspector/variables.py @@ -147,7 +147,8 @@ class VariablesView( object ): utils.SetUpPromptBuffer( self._watch.buf, 'vimspector.Watches', 'Expression: ', - 'vimspector#AddWatchPrompt' ) + 'vimspector#AddWatchPrompt', + 'vimspector#OmniFuncWatch' ) with utils.LetCurrentWindow( watches_win ): vim.command( 'nnoremap :call vimspector#ExpandVariable()' )