forked from VimPlug/jedi
set user_scope right in fast_parser
This commit is contained in:
@@ -89,11 +89,11 @@ class ParserNode(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# with fast_parser we have either 1 subscope or only statements.
|
# with fast_parser we have either 1 subscope or only statements.
|
||||||
self._content_scope = parser.module.subscopes[0]
|
self.content_scope = parser.module.subscopes[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
self._content_scope = parser.module
|
self.content_scope = parser.module
|
||||||
|
|
||||||
scope = self._content_scope
|
scope = self.content_scope
|
||||||
self._contents = {}
|
self._contents = {}
|
||||||
for c in SCOPE_CONTENTS:
|
for c in SCOPE_CONTENTS:
|
||||||
self._contents[c] = list(getattr(scope, c))
|
self._contents[c] = list(getattr(scope, c))
|
||||||
@@ -103,11 +103,11 @@ class ParserNode(object):
|
|||||||
self.children = []
|
self.children = []
|
||||||
|
|
||||||
def reset_contents(self):
|
def reset_contents(self):
|
||||||
scope = self._content_scope
|
scope = self.content_scope
|
||||||
for key, c in self._contents.items():
|
for key, c in self._contents.items():
|
||||||
setattr(scope, key, list(c))
|
setattr(scope, key, list(c))
|
||||||
scope.is_generator = self._is_generator
|
scope.is_generator = self._is_generator
|
||||||
self.parser.user_scope = None
|
self.parser.user_scope = self.parser.module
|
||||||
|
|
||||||
if self.parent is None:
|
if self.parent is None:
|
||||||
# Global vars of the first one can be deleted, in the global scope
|
# Global vars of the first one can be deleted, in the global scope
|
||||||
@@ -146,7 +146,7 @@ class ParserNode(object):
|
|||||||
|
|
||||||
def _set_items(self, parser, set_parent=False):
|
def _set_items(self, parser, set_parent=False):
|
||||||
# insert parser objects into current structure
|
# insert parser objects into current structure
|
||||||
scope = self._content_scope
|
scope = self.content_scope
|
||||||
for c in SCOPE_CONTENTS:
|
for c in SCOPE_CONTENTS:
|
||||||
content = getattr(scope, c)
|
content = getattr(scope, c)
|
||||||
items = getattr(parser.module, c)
|
items = getattr(parser.module, c)
|
||||||
@@ -159,9 +159,6 @@ class ParserNode(object):
|
|||||||
for d in i.decorators:
|
for d in i.decorators:
|
||||||
d.parent = scope.use_as_parent
|
d.parent = scope.use_as_parent
|
||||||
content += items
|
content += items
|
||||||
if isinstance(parser.user_scope, pr.SubModule) \
|
|
||||||
and parser.start_pos <= parser.user_position < parser.end_pos:
|
|
||||||
parser.user_scope = scope
|
|
||||||
|
|
||||||
# global_vars
|
# global_vars
|
||||||
cur = self
|
cur = self
|
||||||
@@ -226,14 +223,12 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
|
|
||||||
self._parse(code)
|
self._parse(code)
|
||||||
|
|
||||||
def scan_user_scope(self, sub_module):
|
def _scan_user_scope(self, sub_module):
|
||||||
""" Scan with self.user_position.
|
""" Scan with self.user_position. """
|
||||||
:type sub_module: pr.SubModule
|
|
||||||
"""
|
|
||||||
for scope in sub_module.statements + sub_module.subscopes:
|
for scope in sub_module.statements + sub_module.subscopes:
|
||||||
if isinstance(scope, pr.Scope):
|
if isinstance(scope, pr.Scope):
|
||||||
if scope.start_pos <= self.user_position <= scope.end_pos:
|
if scope.start_pos <= self.user_position <= scope.end_pos:
|
||||||
return self.scan_user_scope(scope) or scope
|
return self._scan_user_scope(scope) or scope
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _split_parts(self, code):
|
def _split_parts(self, code):
|
||||||
@@ -359,6 +354,12 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
self.current_node.add_parser(p, code_part)
|
self.current_node.add_parser(p, code_part)
|
||||||
else:
|
else:
|
||||||
self.current_node = self.current_node.add_node(node)
|
self.current_node = self.current_node.add_node(node)
|
||||||
|
|
||||||
|
if self.current_node.parent and (isinstance(p.user_scope,
|
||||||
|
pr.SubModule) or p.user_scope is None) \
|
||||||
|
and p.start_pos <= self.user_position < p.end_pos:
|
||||||
|
p.user_scope = self.current_node.parent.content_scope
|
||||||
|
|
||||||
self.parsers.append(p)
|
self.parsers.append(p)
|
||||||
|
|
||||||
is_first = False
|
is_first = False
|
||||||
@@ -409,7 +410,8 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
if p.user_stmt:
|
if p.user_stmt:
|
||||||
p.user_scope = p.user_stmt.parent
|
p.user_scope = p.user_stmt.parent
|
||||||
else:
|
else:
|
||||||
p.user_scope = self.scan_user_scope(m) or self.module
|
p.user_scope = self._scan_user_scope(m) or m
|
||||||
|
|
||||||
return p, node
|
return p, node
|
||||||
|
|
||||||
def reset_caches(self):
|
def reset_caches(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user