making sure to open popup relative to cursor

This commit is contained in:
dsych 2020-12-13 22:25:27 -05:00 • committed by Ben Jackson
commit d2990d7bae
5 changed files with 29 additions and 31 deletions

View file

@ -524,7 +524,7 @@ function! vimspector#OnBufferCreated( file_name ) abort
endfunction endfunction
function! vimspector#ShowTooltip() abort function! vimspector#ShowTooltip() abort
return py3eval('_vimspector_session.ShowTooltip(int( vim.eval( "winnr()" ) ) ,vim.eval( "expand(\"<cexpr>\")" ) )') return py3eval('_vimspector_session.ShowTooltip(int( vim.eval( "winnr()" ) ) ,vim.eval( "expand(\"<cexpr>\")" ), 0)')
endfunction endfunction

View file

@ -30,13 +30,8 @@ function! vimspector#internal#balloon#BalloonExpr() abort
endfunction endfunction
" Returns: py.ShowBalloon( winnr, expresssion ) " Returns: py.ShowBalloon( winnr, expresssion )
function! vimspector#internal#balloon#Tooltip() abort function! vimspector#internal#balloon#HoverTooltip() abort
" winnr + 1 because for *no good reason* winnr is 0 based here unlike return py3eval('_vimspector_session.ShowTooltip(int( vim.eval( "v:beval_winnr" ) ) + 1 ,vim.eval( "v:beval_text"), 1)')
" everywhere else
" int() because for *no good reason* winnr is a string.
return py3eval('_vimspector_session.ShowBalloon('
\ . 'int( vim.eval( "v:beval_winnr" ) ) + 1,'
\ . 'vim.eval( "expand(\"<cexpr>\")" ) )' )
endfunction endfunction
@ -47,11 +42,16 @@ function! vimspector#internal#balloon#closeCallback() abort
return py3eval('_vimspector_session._CleanUpTooltip()') return py3eval('_vimspector_session._CleanUpTooltip()')
endfunction endfunction
function! vimspector#internal#balloon#CreateTooltip() abort function! vimspector#internal#balloon#CreateTooltip(is_hover, ...)
let body = []
if a:0 > 0
let body = a:1
endif
if has('nvim') if has('nvim')
let buf = nvim_create_buf(v:false, v:true) let buf = nvim_create_buf(v:false, v:true)
" call nvim_buf_set_option(buf, 'modifiable', v:false) " call nvim_buf_set_option(buf, 'modifiable', v:false)
call nvim_buf_set_lines(buf, 0, -1, v:true, []) call nvim_buf_set_lines(buf, 0, -1, v:true, body)
" default the dimensions for now. they can be easily overwritten later " default the dimensions for now. they can be easily overwritten later
let opts = #{ let opts = #{
@ -117,7 +117,7 @@ function! vimspector#internal#balloon#CreateTooltip() abort
call vimspector#internal#balloon#closeCallback() call vimspector#internal#balloon#closeCallback()
endif endif
let s:float_win = popup_create([], #{ let config = #{
\ filter: "MyFilter", \ filter: "MyFilter",
\ cursorline: 1, \ cursorline: 1,
\ wrap: 1, \ wrap: 1,
@ -125,9 +125,14 @@ function! vimspector#internal#balloon#CreateTooltip() abort
\ maxwidth: 50, \ maxwidth: 50,
\ maxheight: 5, \ maxheight: 5,
\ scrollbar: 1, \ scrollbar: 1,
\ moved: "any", \ }
\ }) if a:is_hover
" call setbufvar(winbufnr(s:float_win), '&buflisted', 1) let config['mousemoved'] = "word"
let s:float_win = popup_beval(body, config)
else
let config['moved'] = "any"
let s:float_win = popup_atcursor(body, config)
endif
endif endif

View file

@ -540,7 +540,7 @@ class DebugSession( object ):
@IfConnected() @IfConnected()
def ShowTooltip(self, winnr, expression): def ShowTooltip(self, winnr, expression, is_hover):
"""Proxy: ballonexpr -> variables.ShowBallon""" """Proxy: ballonexpr -> variables.ShowBallon"""
frame = self._stackTraceView.GetCurrentFrame() frame = self._stackTraceView.GetCurrentFrame()
# Check if RIP is in a frame # Check if RIP is in a frame
@ -556,7 +556,7 @@ class DebugSession( object ):
return '' return ''
# Return variable aware function # Return variable aware function
return self._variablesView.VariableEval(frame, expression) return self._variablesView.VariableEval(frame, expression, is_hover)
def _CleanUpTooltip(self): def _CleanUpTooltip(self):
return self._variablesView._CleanUpTooltip() return self._variablesView._CleanUpTooltip()

View file

@ -634,19 +634,13 @@ def ParseVariables( variables_list,
return new_variables return new_variables
def DisplayBaloon( is_term, display ): def DisplayBaloon( is_term, display, is_hover = False ):
if int(vim.eval("has('nvim')")):
vim.eval("vimspector#internal#state#TooltipExec({})".format(display))
return
if not is_term: if not is_term:
display = '\n'.join( display )
# To enable the Windows GUI to display the balloon correctly # To enable the Windows GUI to display the balloon correctly
# Refer https://github.com/vim/vim/issues/1512#issuecomment-492070685 # Refer https://github.com/vim/vim/issues/1512#issuecomment-492070685
vim.eval( "balloon_show( '' )" ) display = '\n'.join( display )
vim.eval( "balloon_show( {0} )".format( return int( vim.eval( "vimspector#internal#balloon#CreateTooltip({}, {})".format(is_hover, json.dumps( display )) ) )
json.dumps( display ) ) )
def GetBufferFilepath( buf ): def GetBufferFilepath( buf ):

View file

@ -186,7 +186,7 @@ class VariablesView( object ):
'balloonexpr': vim.options[ 'balloonexpr' ], 'balloonexpr': vim.options[ 'balloonexpr' ],
'balloondelay': vim.options[ 'balloondelay' ], 'balloondelay': vim.options[ 'balloondelay' ],
} }
vim.options[ 'balloonexpr' ] = 'vimspector#internal#balloon#BalloonExpr()' vim.options[ 'balloonexpr' ] = 'vimspector#internal#balloon#HoverTooltip()'
vim.options[ 'balloondelay' ] = 250 vim.options[ 'balloondelay' ] = 250
if has_balloon: if has_balloon:
@ -282,7 +282,7 @@ class VariablesView( object ):
self._variable_eval_view = None self._variable_eval_view = None
return '' return ''
def VariableEval(self, frame, expression): def VariableEval(self, frame, expression, is_hover):
"""Callback to display variable under cursor `:h ballonexpr`""" """Callback to display variable under cursor `:h ballonexpr`"""
if not self._connection: if not self._connection:
return '' return ''
@ -291,8 +291,7 @@ class VariablesView( object ):
body = message[ 'body' ] body = message[ 'body' ]
self._variable_eval = Scope(body) self._variable_eval = Scope(body)
float_win_id = utils.DisplayBaloon(self._is_term, [], is_hover)
float_win_id = vim.eval("vimspector#internal#balloon#CreateTooltip()")
float_buf_nr = int(vim.eval("winbufnr({})".format(float_win_id))) float_buf_nr = int(vim.eval("winbufnr({})".format(float_win_id)))
# since vim's popup cant be focused there is no way # since vim's popup cant be focused there is no way
@ -318,7 +317,7 @@ class VariablesView( object ):
def failure_handler( reason, message ): def failure_handler( reason, message ):
display = [ reason ] display = [ reason ]
utils.DisplayBaloon( self._is_term, display ) utils.DisplayBaloon( self._is_term, display, is_hover )
# Send async request # Send async request
self._connection.DoRequest( handler, { self._connection.DoRequest( handler, {
@ -331,7 +330,7 @@ class VariablesView( object ):
}, failure_handler ) }, failure_handler )
# Return working (meanwhile) # Return working (meanwhile)
return '...' return ''
def AddWatch( self, frame, expression ): def AddWatch( self, frame, expression ):
watch = { watch = {