working on variables view
This commit is contained in:
parent
7c4eef9096
commit
4c0ba92ac6
2 changed files with 110 additions and 1 deletions
|
|
@ -58,10 +58,28 @@ function! vimspector#internal#state#Tooltip() abort
|
||||||
\ . 'vim.eval( "expand(\"<cexpr>\")" ) )' )
|
\ . 'vim.eval( "expand(\"<cexpr>\")" ) )' )
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! vimspector#internal#state#CreateTooltip() abort
|
||||||
|
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! vimspector#internal#state#TooltipExec(body) abort
|
function! vimspector#internal#state#TooltipExec(body) abort
|
||||||
let buf = nvim_create_buf(v:false, v:true)
|
let buf = nvim_create_buf(v:false, v:true)
|
||||||
call nvim_buf_set_lines(buf, 0, -1, v:true, a:body)
|
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)
|
let g:float_win = nvim_open_win(buf, 0, opts)
|
||||||
|
|
||||||
augroup vimspector#internal#balloon#nvim_float
|
augroup vimspector#internal#balloon#nvim_float
|
||||||
|
|
|
||||||
|
|
@ -371,6 +371,10 @@ class VariablesView( object ):
|
||||||
},
|
},
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _DrawVariables( self, view, variables, indent ):
|
def _DrawVariables( self, view, variables, indent ):
|
||||||
assert indent > 0
|
assert indent > 0
|
||||||
for variable in variables:
|
for variable in variables:
|
||||||
|
|
@ -531,5 +535,92 @@ class VariablesView( object ):
|
||||||
syntax,
|
syntax,
|
||||||
self._vars.buf,
|
self._vars.buf,
|
||||||
self._watch.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',
|
||||||
|
'<unknown>' ) ).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('<cexpr>')")
|
||||||
|
|
||||||
|
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
|
# vim: sw=2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue