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': [ '.', '->', ':', '<' ]
  \ }
This commit is contained in:
Ben Jackson 2020-09-03 17:46:06 +01:00
commit 733843a6d4
5 changed files with 113 additions and 8 deletions

View file

@ -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 ):

View file

@ -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 )

View file

@ -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

View file

@ -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 <buffer> <CR> :call vimspector#ExpandVariable()<CR>' )