mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Usages fix for more complex situations
This commit is contained in:
@@ -41,11 +41,22 @@ def usages(module_context, tree_name):
|
|||||||
modules = set(d.get_root_context() for d in found_names.values())
|
modules = set(d.get_root_context() for d in found_names.values())
|
||||||
modules = set(m for m in modules if isinstance(m, ModuleContext))
|
modules = set(m for m in modules if isinstance(m, ModuleContext))
|
||||||
|
|
||||||
|
non_matching_usage_maps = {}
|
||||||
for m in imports.get_modules_containing_name(module_context.evaluator, modules, search_name):
|
for m in imports.get_modules_containing_name(module_context.evaluator, modules, search_name):
|
||||||
for name_leaf in m.tree_node.get_used_names().get(search_name, []):
|
for name_leaf in m.tree_node.get_used_names().get(search_name, []):
|
||||||
new = _find_names(m, name_leaf)
|
new = _find_names(m, name_leaf)
|
||||||
for tree_name in new:
|
if any(tree_name in found_names for tree_name in new):
|
||||||
if tree_name in found_names:
|
found_names.update(new)
|
||||||
found_names.update(new)
|
for tree_name in new:
|
||||||
break
|
for dct in non_matching_usage_maps.get(tree_name, []):
|
||||||
|
# A usage that was previously searched for matches with
|
||||||
|
# a now found name. Merge.
|
||||||
|
found_names.update(dct)
|
||||||
|
try:
|
||||||
|
del non_matching_usage_maps[tree_name]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
for name in new:
|
||||||
|
non_matching_usage_maps.setdefault(name, []).append(new)
|
||||||
return found_names.values()
|
return found_names.values()
|
||||||
|
|||||||
@@ -302,3 +302,14 @@ x = 3
|
|||||||
{x:1 for x in something}
|
{x:1 for x in something}
|
||||||
#< 10 (0,1), (0,10)
|
#< 10 (0,1), (0,10)
|
||||||
{x:1 for x in something}
|
{x:1 for x in something}
|
||||||
|
|
||||||
|
def x():
|
||||||
|
zzz = 3
|
||||||
|
if UNDEFINED:
|
||||||
|
zzz = 5
|
||||||
|
if UNDEFINED2:
|
||||||
|
zzz
|
||||||
|
else:
|
||||||
|
#< (0, 8), (1, 4), (-3, 12), (-5, 8), (-7, 4)
|
||||||
|
zzz
|
||||||
|
zzz
|
||||||
|
|||||||
Reference in New Issue
Block a user