Don't goto while building found_names for the current file

But goto for all non_matching_reference_maps items later
This commit is contained in:
muffinmad
2020-05-24 22:58:04 +03:00
parent 7459d67fee
commit 1c342d36e5
2 changed files with 21 additions and 0 deletions

View File

@@ -166,6 +166,8 @@ class AbstractTreeName(AbstractNameDefinition):
node_type = par.type
if node_type == 'argument' and par.children[1] == '=' and par.children[0] == name:
# Named param goto.
if not all_scopes:
return [self]
trailer = par.parent
if trailer.type == 'arglist':
trailer = trailer.parent
@@ -200,6 +202,8 @@ class AbstractTreeName(AbstractNameDefinition):
)
if node_type == 'trailer' and par.children[0] == '.':
if not all_scopes:
return [self]
values = infer_call_of_leaf(context, name, cut_own_trailer=True)
return values.goto(name, name_context=context)
else:

View File

@@ -144,6 +144,11 @@ def find_references(module_context, tree_name, all_scopes=True):
search_name,
)
gotos = set()
if not all_scopes:
for name in found_names_dct.values():
gotos |= set(name.goto())
non_matching_reference_maps = {}
for module_context in potential_modules:
for name_leaf in module_context.tree_node.get_used_names().get(search_name, []):
@@ -162,6 +167,18 @@ def find_references(module_context, tree_name, all_scopes=True):
else:
for name in new:
non_matching_reference_maps.setdefault(name, []).append(new)
if not all_scopes:
def in_gotos(g):
for g_ in gotos:
if g.start_pos == g_.start_pos and g.get_root_context() == g_.get_root_context():
return True
for dct_list in non_matching_reference_maps.values():
for dct in dct_list:
for k, v in dct.items():
if any(in_gotos(g) for g in v.goto()):
found_names_dct[k] = v
return found_names_dct.values()