forked from VimPlug/jedi
api_classes.RelatedName -> Usage
This commit is contained in:
@@ -391,14 +391,14 @@ class Script(object):
|
|||||||
@api_classes._clear_caches_after_call
|
@api_classes._clear_caches_after_call
|
||||||
def usages(self, additional_module_paths=()):
|
def usages(self, additional_module_paths=()):
|
||||||
"""
|
"""
|
||||||
Return :class:`api_classes.RelatedName` objects, which contain all
|
Return :class:`api_classes.Usage` objects, which contain all
|
||||||
names that point to the definition of the name under the cursor. This
|
names that point to the definition of the name under the cursor. This
|
||||||
is very useful for refactoring (renaming), or to show all usages of a
|
is very useful for refactoring (renaming), or to show all usages of a
|
||||||
variable.
|
variable.
|
||||||
|
|
||||||
.. todo:: Implement additional_module_paths
|
.. todo:: Implement additional_module_paths
|
||||||
|
|
||||||
:rtype: list of :class:`api_classes.RelatedName`
|
:rtype: list of :class:`api_classes.Usage`
|
||||||
"""
|
"""
|
||||||
user_stmt = self._parser.user_stmt
|
user_stmt = self._parser.user_stmt
|
||||||
definitions, search_name = self._goto(add_import_name=True)
|
definitions, search_name = self._goto(add_import_name=True)
|
||||||
@@ -418,9 +418,9 @@ class Script(object):
|
|||||||
|
|
||||||
for d in set(definitions):
|
for d in set(definitions):
|
||||||
if isinstance(d, pr.Module):
|
if isinstance(d, pr.Module):
|
||||||
names.append(api_classes.RelatedName(d, d))
|
names.append(api_classes.Usage(d, d))
|
||||||
else:
|
else:
|
||||||
names.append(api_classes.RelatedName(d.names[-1], d))
|
names.append(api_classes.Usage(d.names[-1], d))
|
||||||
|
|
||||||
return self._sorted_defs(set(names))
|
return self._sorted_defs(set(names))
|
||||||
|
|
||||||
|
|||||||
@@ -528,10 +528,10 @@ def _defined_names(scope):
|
|||||||
return [Definition(d) for d in sorted(names, key=lambda s: s.start_pos)]
|
return [Definition(d) for d in sorted(names, key=lambda s: s.start_pos)]
|
||||||
|
|
||||||
|
|
||||||
class RelatedName(BaseDefinition):
|
class Usage(BaseDefinition):
|
||||||
"""TODO: document this"""
|
"""TODO: document this"""
|
||||||
def __init__(self, name_part, scope):
|
def __init__(self, name_part, scope):
|
||||||
super(RelatedName, self).__init__(scope, name_part.start_pos)
|
super(Usage, self).__init__(scope, name_part.start_pos)
|
||||||
self.text = unicode(name_part)
|
self.text = unicode(name_part)
|
||||||
self.end_pos = name_part.end_pos
|
self.end_pos = name_part.end_pos
|
||||||
|
|
||||||
|
|||||||
@@ -445,7 +445,7 @@ def usages(definitions, search_name, mods):
|
|||||||
# compare to see if they match
|
# compare to see if they match
|
||||||
if any(r in compare_definitions for r in compare_follow_res):
|
if any(r in compare_definitions for r in compare_follow_res):
|
||||||
scope = call.parent
|
scope = call.parent
|
||||||
result.append(api_classes.RelatedName(search, scope))
|
result.append(api_classes.Usage(search, scope))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -475,7 +475,7 @@ def usages(definitions, search_name, mods):
|
|||||||
direct_resolve=True)
|
direct_resolve=True)
|
||||||
f = i.follow(is_goto=True)
|
f = i.follow(is_goto=True)
|
||||||
if set(f) & set(definitions):
|
if set(f) & set(definitions):
|
||||||
names.append(api_classes.RelatedName(name_part, stmt))
|
names.append(api_classes.Usage(name_part, stmt))
|
||||||
else:
|
else:
|
||||||
for call in _scan_statement(stmt, search_name,
|
for call in _scan_statement(stmt, search_name,
|
||||||
assignment_details=True):
|
assignment_details=True):
|
||||||
|
|||||||
Reference in New Issue
Block a user