diff --git a/autoload/vimspector/internal/state.vim b/autoload/vimspector/internal/state.vim index d9d8cd2..ade14bb 100644 --- a/autoload/vimspector/internal/state.vim +++ b/autoload/vimspector/internal/state.vim @@ -58,10 +58,28 @@ function! vimspector#internal#state#Tooltip() abort \ . 'vim.eval( "expand(\"\")" ) )' ) endfunction +function! vimspector#internal#state#CreateTooltip() abort + +endfunction + function! vimspector#internal#state#TooltipExec(body) abort let buf = nvim_create_buf(v:false, v:true) call nvim_buf_set_lines(buf, 0, -1, v:true, a:body) - let opts = { 'relative': 'cursor', 'width': 40, 'height': 2, 'col': 0, 'row': 1, 'anchor': 'NW', 'style': 'minimal' } + + " get the max width on a line + let width = 0 + let maxWidth = winwidth() + + for w in a:body + let width = max(len(w), width) + " reached the max size, no point in looping more + if width > maxWidth + let width = maxWidth + break + endif + endfor + + let opts = { 'relative': 'cursor', 'width': width, 'height': len(a:body), 'col': 0, 'row': 1, 'anchor': 'NW', 'style': 'minimal' } let g:float_win = nvim_open_win(buf, 0, opts) augroup vimspector#internal#balloon#nvim_float diff --git a/python3/vimspector/variables.py b/python3/vimspector/variables.py index 4028722..a67c06e 100644 --- a/python3/vimspector/variables.py +++ b/python3/vimspector/variables.py @@ -371,6 +371,10 @@ class VariablesView( object ): }, } ) + + + + def _DrawVariables( self, view, variables, indent ): assert indent > 0 for variable in variables: @@ -531,5 +535,92 @@ class VariablesView( object ): syntax, self._vars.buf, self._watch.buf ) +class VariableEval + def __init__(self, stackTrace): + self.stackTrace = stackTrace + self._connection = None + self.variable = Variable() + def _ConsumeVariables(self, parent, message): + new_variables = [] + for variable_body in message[ 'body' ][ 'variables' ]: + if parent.variables is None: + parent.variables = [] + + # Find the variable in parent + found = False + for index, v in enumerate( parent.variables ): + if v.variable[ 'name' ] == variable_body[ 'name' ]: + variable = v + found = True + break + + if not found: + variable = Variable( variable_body ) + else: + variable.Update( variable_body ) + + new_variables.append( variable ) + + if variable.IsExpandable() and variable.IsExpanded(): + self._connection.DoRequest( partial( self._ConsumeVariables, + draw, + variable ), { + 'command': 'variables', + 'arguments': { + 'variablesReference': variable.VariablesReference() + }, + } ) + + parent.variables = new_variables + + def _DrawVariables( self, variables, indent ): + assert indent > 0 + for variable in variables: + line = utils.AppendToBuffer( + view.buf, + '{indent}{marker}{icon} {name} ({type_}): {value}'.format( + # We borrow 1 space of indent to draw the change marker + indent = ' ' * ( indent - 1 ), + marker = '*' if variable.changed else ' ', + icon = '+' if ( variable.IsExpandable() + and not variable.IsExpanded() ) else '-', + name = variable.variable[ 'name' ], + type_ = variable.variable.get( 'type', '' ), + value = variable.variable.get( 'value', + '' ) ).split( '\n' ) ) + view.lines[ line ] = variable + + if variable.ShouldDrawDrillDown(): + self._DrawVariables( view, variable.variables, indent + 2 ) + + def AddVariableEval( self, bufid ): + current_symbol = vim.eval("expand('')") + + def handler( message ): + # TODO: this result count be expandable, but we have no way to allow the + # user to interact with the balloon to expand it, unless we use a popup + # instead, but even then we don't really want to trap the cursor. + _ConsumeVariables(self, self.variable, message) + variableEvalView = View( variables_win, {}, self._DrawScopes ) + _DrawVariables(self, self.variable, 0) + + + def failure_handler(reason, message): + vim.eval("echom {}".format(message)) + + self._connection.DoRequest( handler, { + 'command': 'evaluate', + 'arguments': { + 'expression': expression, + 'frameId': frame[ 'id' ], + 'context': 'hover', + } + }, failure_handler ) + + def ConnectionUp( self, connection ): + self._connection = connection + + def ConnectionClosed(self): + self._connection = None # vim: sw=2