forked from VimPlug/jedi
evaluate.get_scopes_for_name -> evaluate.find_name
This commit is contained in:
@@ -162,7 +162,7 @@ def get_names_of_scope(scope, position=None, star_search=True,
|
|||||||
yield builtin_scope, builtin_scope.get_defined_names()
|
yield builtin_scope, builtin_scope.get_defined_names()
|
||||||
|
|
||||||
|
|
||||||
def get_scopes_for_name(scope, name_str, position=None, search_global=False,
|
def find_name(scope, name_str, position=None, search_global=False,
|
||||||
is_goto=False):
|
is_goto=False):
|
||||||
"""
|
"""
|
||||||
This is the search function. The most important part to debug.
|
This is the search function. The most important part to debug.
|
||||||
@@ -193,8 +193,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False,
|
|||||||
if r.is_global():
|
if r.is_global():
|
||||||
for token_name in r.token_list[1:]:
|
for token_name in r.token_list[1:]:
|
||||||
if isinstance(token_name, pr.Name):
|
if isinstance(token_name, pr.Name):
|
||||||
add = get_scopes_for_name(r.parent,
|
add = find_name(r.parent, str(token_name))
|
||||||
str(token_name))
|
|
||||||
else:
|
else:
|
||||||
# generated objects are used within executions, but these
|
# generated objects are used within executions, but these
|
||||||
# objects are in functions, and we have to dynamically
|
# objects are in functions, and we have to dynamically
|
||||||
@@ -660,12 +659,12 @@ def follow_call_path(path, scope, position):
|
|||||||
else:
|
else:
|
||||||
if isinstance(current, pr.NamePart):
|
if isinstance(current, pr.NamePart):
|
||||||
# This is the first global lookup.
|
# This is the first global lookup.
|
||||||
scopes = get_scopes_for_name(scope, current, position=position,
|
scopes = find_name(scope, current, position=position,
|
||||||
search_global=True)
|
search_global=True)
|
||||||
else:
|
else:
|
||||||
if current.type in (pr.Call.STRING, pr.Call.NUMBER):
|
if current.type in (pr.Call.STRING, pr.Call.NUMBER):
|
||||||
t = type(current.name).__name__
|
t = type(current.name).__name__
|
||||||
scopes = get_scopes_for_name(builtin.Builtin.scope, t)
|
scopes = find_name(builtin.Builtin.scope, t)
|
||||||
else:
|
else:
|
||||||
debug.warning('unknown type:', current.type, current)
|
debug.warning('unknown type:', current.type, current)
|
||||||
scopes = []
|
scopes = []
|
||||||
@@ -734,7 +733,7 @@ def follow_path(path, scope, call_scope, position=None):
|
|||||||
# This is the typical lookup while chaining things.
|
# This is the typical lookup while chaining things.
|
||||||
if filter_private_variable(scope, call_scope, current):
|
if filter_private_variable(scope, call_scope, current):
|
||||||
return []
|
return []
|
||||||
result = imports.strip_imports(get_scopes_for_name(scope, current,
|
result = imports.strip_imports(find_name(scope, current,
|
||||||
position=position))
|
position=position))
|
||||||
return follow_paths(path, set(result), call_scope, position=position)
|
return follow_paths(path, set(result), call_scope, position=position)
|
||||||
|
|
||||||
@@ -769,6 +768,6 @@ def goto(stmt, call_path=None):
|
|||||||
search_global = True
|
search_global = True
|
||||||
follow_res = []
|
follow_res = []
|
||||||
for s in scopes:
|
for s in scopes:
|
||||||
follow_res += get_scopes_for_name(s, search, pos,
|
follow_res += find_name(s, search, pos,
|
||||||
search_global=search_global, is_goto=True)
|
search_global=search_global, is_goto=True)
|
||||||
return follow_res, search
|
return follow_res, search
|
||||||
|
|||||||
@@ -248,8 +248,7 @@ class Class(use_metaclass(cache.CachedMetaClass, pr.Base)):
|
|||||||
supers.append(cls)
|
supers.append(cls)
|
||||||
if not supers and self.base.parent != builtin.Builtin.scope:
|
if not supers and self.base.parent != builtin.Builtin.scope:
|
||||||
# add `object` to classes
|
# add `object` to classes
|
||||||
supers += evaluate.get_scopes_for_name(builtin.Builtin.scope,
|
supers += evaluate.find_name(builtin.Builtin.scope, 'object')
|
||||||
'object')
|
|
||||||
return supers
|
return supers
|
||||||
|
|
||||||
@cache.memoize_default(default=[])
|
@cache.memoize_default(default=[])
|
||||||
@@ -813,8 +812,7 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base)):
|
|||||||
It returns e.g. for a list: append, pop, ...
|
It returns e.g. for a list: append, pop, ...
|
||||||
"""
|
"""
|
||||||
# `array.type` is a string with the type, e.g. 'list'.
|
# `array.type` is a string with the type, e.g. 'list'.
|
||||||
scope = evaluate.get_scopes_for_name(builtin.Builtin.scope,
|
scope = evaluate.find_name(builtin.Builtin.scope, self._array.type)[0]
|
||||||
self._array.type)[0]
|
|
||||||
scope = Instance(scope)
|
scope = Instance(scope)
|
||||||
names = scope.get_defined_names()
|
names = scope.get_defined_names()
|
||||||
return [ArrayElement(n) for n in names]
|
return [ArrayElement(n) for n in names]
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ class ImportPath(pr.Base):
|
|||||||
elif rest:
|
elif rest:
|
||||||
if is_goto:
|
if is_goto:
|
||||||
scopes = itertools.chain.from_iterable(
|
scopes = itertools.chain.from_iterable(
|
||||||
evaluate.get_scopes_for_name(s, rest[0], is_goto=True)
|
evaluate.find_name(s, rest[0], is_goto=True)
|
||||||
for s in scopes)
|
for s in scopes)
|
||||||
else:
|
else:
|
||||||
scopes = itertools.chain.from_iterable(
|
scopes = itertools.chain.from_iterable(
|
||||||
|
|||||||
Reference in New Issue
Block a user