fixing linting errors in python files

This commit is contained in:
dsych 2021-01-03 00:42:06 -05:00 committed by Ben Jackson
commit e0b1d6ed81
3 changed files with 57 additions and 29 deletions

View file

@ -521,7 +521,7 @@ class DebugSession( object ):
@IfConnected() @IfConnected()
def ExpandVariable( self, lineNum = -1 ): def ExpandVariable( self, lineNum = -1 ):
self._variablesView.ExpandVariable(lineNum) self._variablesView.ExpandVariable( lineNum )
@IfConnected() @IfConnected()
def AddWatch( self, expression ): def AddWatch( self, expression ):
@ -540,7 +540,7 @@ class DebugSession( object ):
@IfConnected() @IfConnected()
def ShowTooltip(self, winnr, expression, is_hover): 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,9 +556,9 @@ class DebugSession( object ):
return '' return ''
# Return variable aware function # Return variable aware function
return self._variablesView.VariableEval(frame, expression, is_hover) return self._variablesView.VariableEval( frame, expression, is_hover )
def _CleanUpTooltip(self): def _CleanUpTooltip( self ):
return self._variablesView._CleanUpTooltip() return self._variablesView._CleanUpTooltip()
@IfConnected() @IfConnected()

View file

@ -640,9 +640,13 @@ def DisplayBaloon( is_term, display, is_hover = False ):
# Refer https://github.com/vim/vim/issues/1512#issuecomment-492070685 # Refer https://github.com/vim/vim/issues/1512#issuecomment-492070685
display = '\n'.join( display ) display = '\n'.join( display )
rc = int( vim.eval( "vimspector#internal#balloon#CreateTooltip({}, {})".format(is_hover, json.dumps( display )) ) ) rc = int( vim.eval(
"vimspector#internal#balloon#CreateTooltip({}, {})".format(
is_hover, json.dumps( display )
)
) )
vim.eval("vimspector#internal#balloon#nvim_resize_tooltip()") vim.eval( "vimspector#internal#balloon#nvim_resize_tooltip()" )
return rc return rc

View file

@ -122,10 +122,10 @@ class View:
lines: typing.Dict[ int, Expandable ] lines: typing.Dict[ int, Expandable ]
draw: typing.Callable draw: typing.Callable
def __init__( self, win, lines, draw): def __init__( self, win, lines, draw ):
self.lines = lines self.lines = lines
self.draw = draw self.draw = draw
if (win is not None): if ( win is not None ):
self.buf = win.buffer self.buf = win.buffer
utils.SetUpUIWindow( win ) utils.SetUpUIWindow( win )
@ -138,8 +138,8 @@ class VariablesView( object ):
self._connection = None self._connection = None
self._current_syntax = '' self._current_syntax = ''
self._variable_eval = None self._variable_eval: Scope = None
self._variable_eval_view = None self._variable_eval_view: View = None
def AddExpandMappings(): def AddExpandMappings():
vim.command( 'nnoremap <silent> <buffer> <CR> ' vim.command( 'nnoremap <silent> <buffer> <CR> '
@ -186,7 +186,9 @@ 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#HoverTooltip()' vim.options[ 'balloonexpr' ] = "vimspector#internal#"
"balloon#HoverTooltip()"
vim.options[ 'balloondelay' ] = 250 vim.options[ 'balloondelay' ] = 250
if has_balloon: if has_balloon:
@ -270,28 +272,38 @@ class VariablesView( object ):
}, },
} ) } )
def _DrawEval(self): def _DrawEval( self ):
with utils.RestoreCursorPosition(): with utils.RestoreCursorPosition():
with utils.ModifiableScratchBuffer( self._variable_eval_view.buf ): with utils.ModifiableScratchBuffer( self._variable_eval_view.buf ):
utils.ClearBuffer( self._variable_eval_view.buf ) utils.ClearBuffer( self._variable_eval_view.buf )
# if we only have a single non-expandable variable, it means we ran into a simple type # if we only have a single non-expandable variable,
# it means we ran into a simple type
# hence, there is no need to draw additional fluff around the value # hence, there is no need to draw additional fluff around the value
if(len(self._variable_eval.variables) == 1 and self._variable_eval.variables[0].IsExpandable() == False): if(
len( self._variable_eval.variables ) == 1
and self._variable_eval.variables[ 0 ].IsExpandable() is False
):
utils.AppendToBuffer( utils.AppendToBuffer(
self._variable_eval_view.buf, self._variable_eval_view.buf,
self._variable_eval.variables[0].variable.get( 'value', '<unknown>' ) self._variable_eval.variables[ 0 ]
) .variable.get( 'value', '<unknown>' )
)
else: else:
self._DrawVariables( self._variable_eval_view, self._variable_eval.variables, 2 , True) self._DrawVariables(
self._variable_eval_view,
self._variable_eval.variables,
2,
True
)
vim.eval("vimspector#internal#balloon#nvim_resize_tooltip()") vim.eval( "vimspector#internal#balloon#nvim_resize_tooltip()" )
def _CleanUpTooltip(self): def _CleanUpTooltip( self ) :
# remove reference to old tooltip window # remove reference to old tooltip window
self._variable_eval_view = None self._variable_eval_view = None
return '' return ''
def VariableEval(self, frame, expression, is_hover): 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 ''
@ -299,16 +311,24 @@ class VariablesView( object ):
def handler( message ): def handler( message ):
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 = utils.DisplayBaloon( self._is_term, [], is_hover )
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
# to get a reference to its window # to get a reference to its window
# we will emulate python's window object ourselves # we will emulate python's window object ourselves
self._variable_eval_view = View(type('__vim__window__', (object,), {'options': {}, 'buffer': vim.buffers[float_buf_nr]}), {}, self._DrawEval) self._variable_eval_view = View(
type(
'__vim__window__',
( object, ),
{ 'options': {}, 'buffer': vim.buffers[ float_buf_nr ] }
),
{},
self._DrawEval
)
if(self._variable_eval.VariablesReference() > 0): if( self._variable_eval.VariablesReference() > 0 ):
self._connection.DoRequest( partial( self._ConsumeVariables, self._connection.DoRequest( partial( self._ConsumeVariables,
self._DrawEval, self._DrawEval,
self._variable_eval ), { self._variable_eval ), {
@ -318,9 +338,12 @@ class VariablesView( object ):
}, },
} ) } )
else: else:
# in case that there is nothing to expand, we need to simulate a response from 'variables' request # in case that there is nothing to expand,
# we need to simulate a response from 'variables' request
# it returns [Variable] # it returns [Variable]
self._variable_eval.variables = [Variable({ 'type': body['type'], 'value': body['result']})] self._variable_eval.variables = [
Variable( { 'type': body[ 'type' ], 'value': body[ 'result' ] } )
]
self._DrawEval() self._DrawEval()
@ -422,7 +445,7 @@ class VariablesView( object ):
else: else:
return return
current_line = vim.current.window.cursor[0] if lineNum <= 0 else lineNum current_line = vim.current.window.cursor[ 0 ] if lineNum <= 0 else lineNum
if current_line not in view.lines: if current_line not in view.lines:
return return
@ -474,7 +497,8 @@ class VariablesView( object ):
line = utils.AppendToBuffer( line = utils.AppendToBuffer(
view.buf, view.buf,
text.split( '\n' )) text.split( '\n' )
)
view.lines[ line ] = variable view.lines[ line ] = variable