Add some type hints (requires python 3.6) and update flake8
This commit is contained in:
parent
2117a0515d
commit
39212f4ffc
2 changed files with 29 additions and 15 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
flake8==3.7.7
|
flake8==3.8.3
|
||||||
vim-vint==0.3.21
|
vim-vint==0.3.21
|
||||||
flake8-comprehensions
|
flake8-comprehensions==3.2.3
|
||||||
flake8-ycm>= 0.1.0
|
flake8-ycm>= 0.1.0
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import vim
|
||||||
import logging
|
import logging
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
import typing
|
||||||
|
|
||||||
from vimspector import utils
|
from vimspector import utils
|
||||||
|
|
||||||
|
|
@ -25,10 +26,17 @@ View = namedtuple( 'View', [ 'win', 'lines', 'draw' ] )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VariablesContainer:
|
class Expandable:
|
||||||
|
"""Base for anything which might contain a hierarchy of values represented by
|
||||||
|
a 'variablesReference' to be resolved by the 'variables' request. Records the
|
||||||
|
current state expanded/collapsed. Implementations just implement
|
||||||
|
VariablesReference to get the variables."""
|
||||||
def __init__( self ):
|
def __init__( self ):
|
||||||
self.variables = None
|
self.variables: typing.List[ 'Variable' ] = None
|
||||||
self.expanded = None
|
# None is Falsy and represents collapsed _by default_. WHen set to False,
|
||||||
|
# this means the user explicitly collapsed it. When True, the user expanded
|
||||||
|
# it.
|
||||||
|
self.expanded: bool = None
|
||||||
|
|
||||||
def IsCollapsedByUser( self ):
|
def IsCollapsedByUser( self ):
|
||||||
return self.expanded is False
|
return self.expanded is False
|
||||||
|
|
@ -47,8 +55,9 @@ class VariablesContainer:
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
|
||||||
class Scope( VariablesContainer ):
|
class Scope( Expandable ):
|
||||||
def __init__( self, scope ):
|
"""Holds an expandable scope (a DAP scope dict), with expand/collapse state"""
|
||||||
|
def __init__( self, scope: dict ):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.scope = scope
|
self.scope = scope
|
||||||
|
|
||||||
|
|
@ -56,8 +65,9 @@ class Scope( VariablesContainer ):
|
||||||
return self.scope.get( 'variablesReference', 0 )
|
return self.scope.get( 'variablesReference', 0 )
|
||||||
|
|
||||||
|
|
||||||
class WatchResult( VariablesContainer ):
|
class WatchResult( Expandable ):
|
||||||
def __init__( self, result ):
|
"""Holds the result of a Watch expression with expand/collapse."""
|
||||||
|
def __init__( self, result: dict ):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.result = result
|
self.result = result
|
||||||
|
|
||||||
|
|
@ -65,8 +75,9 @@ class WatchResult( VariablesContainer ):
|
||||||
return self.result.get( 'variablesReference', 0 )
|
return self.result.get( 'variablesReference', 0 )
|
||||||
|
|
||||||
|
|
||||||
class Variable( VariablesContainer ):
|
class Variable( Expandable ):
|
||||||
def __init__( self, variable ):
|
"""Holds one level of an expanded value tree. Also itself expandable."""
|
||||||
|
def __init__( self, variable: dict ):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.variable = variable
|
self.variable = variable
|
||||||
|
|
||||||
|
|
@ -75,7 +86,10 @@ class Variable( VariablesContainer ):
|
||||||
|
|
||||||
|
|
||||||
class Watch:
|
class Watch:
|
||||||
def __init__( self, expression ):
|
"""Holds a user watch expression (DAP request) and the result (WatchResult)"""
|
||||||
|
def __init__( self, expression: dict ):
|
||||||
|
self.result: WatchResult
|
||||||
|
|
||||||
self.expression = expression
|
self.expression = expression
|
||||||
self.result = None
|
self.result = None
|
||||||
|
|
||||||
|
|
@ -96,10 +110,10 @@ class VariablesView( object ):
|
||||||
'nnoremap <buffer> <CR> :call vimspector#ExpandVariable()<CR>' )
|
'nnoremap <buffer> <CR> :call vimspector#ExpandVariable()<CR>' )
|
||||||
|
|
||||||
# List of current scopes of type Scope
|
# List of current scopes of type Scope
|
||||||
self._scopes = []
|
self._scopes: typing.List[ 'Scope' ] = []
|
||||||
|
|
||||||
# List of current Watches of type Watch
|
# List of current Watches of type Watch
|
||||||
self._watches = []
|
self._watches: typing.List[ 'Watch' ] = []
|
||||||
|
|
||||||
# Allows us to hit <CR> to expand/collapse variables
|
# Allows us to hit <CR> to expand/collapse variables
|
||||||
with utils.LetCurrentWindow( self._watch.win ):
|
with utils.LetCurrentWindow( self._watch.win ):
|
||||||
|
|
@ -257,7 +271,7 @@ class VariablesView( object ):
|
||||||
'arguments': watch.expression,
|
'arguments': watch.expression,
|
||||||
} )
|
} )
|
||||||
|
|
||||||
def _UpdateWatchExpression( self, watch, message ):
|
def _UpdateWatchExpression( self, watch: Watch, message: dict ):
|
||||||
if watch.result is not None:
|
if watch.result is not None:
|
||||||
watch.result.result = message[ 'body' ]
|
watch.result.result = message[ 'body' ]
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue