1
0
forked from VimPlug/jedi

Now remove Usage completely.

This commit is contained in:
Dave Halter
2014-04-18 14:45:03 +02:00
parent f0e7b5583d
commit 0301606d18
2 changed files with 6 additions and 14 deletions

View File

@@ -491,14 +491,14 @@ class Script(object):
def usages(self, additional_module_paths=()): def usages(self, additional_module_paths=()):
""" """
Return :class:`classes.Usage` objects, which contain all Return :class:`classes.Definition` 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:`classes.Usage` :rtype: list of :class:`classes.Definition`
""" """
temp, settings.dynamic_flow_information = \ temp, settings.dynamic_flow_information = \
settings.dynamic_flow_information, False settings.dynamic_flow_information, False
@@ -520,13 +520,13 @@ class Script(object):
for d in set(definitions): for d in set(definitions):
if isinstance(d, (pr.Module, compiled.CompiledObject)): if isinstance(d, (pr.Module, compiled.CompiledObject)):
names.append(usages.Usage(self._evaluator, d)) names.append(classes.Definition(self._evaluator, d))
elif isinstance(d, er.Instance): elif isinstance(d, er.Instance):
# Instances can be ignored, because they have been created by # Instances can be ignored, because they have been created by
# ``__getattr__``. # ``__getattr__``.
pass pass
else: else:
names.append(usages.Usage(self._evaluator, d.names[-1], d)) names.append(classes.Definition(self._evaluator, d.names[-1]))
settings.dynamic_flow_information = temp settings.dynamic_flow_information = temp
return helpers.sorted_definitions(set(names)) return helpers.sorted_definitions(set(names))

View File

@@ -6,13 +6,6 @@ from jedi.evaluate import imports
from jedi.evaluate import helpers from jedi.evaluate import helpers
class Usage(classes.Definition):
"""TODO: document this"""
def __init__(self, evaluator, name_part, scope=None):
super(Usage, self).__init__(evaluator, name_part)
self._start_pos = name_part.start_pos
def usages(evaluator, definitions, search_name, mods): def usages(evaluator, definitions, search_name, mods):
def compare_array(definitions): def compare_array(definitions):
""" `definitions` are being compared by module/start_pos, because """ `definitions` are being compared by module/start_pos, because
@@ -58,8 +51,7 @@ def usages(evaluator, definitions, search_name, mods):
compare_follow_res = compare_array(follow_res) compare_follow_res = compare_array(follow_res)
# 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 yield classes.Definition(evaluator, search)
yield Usage(evaluator, search, scope)
if not definitions: if not definitions:
return set() return set()
@@ -87,7 +79,7 @@ def usages(evaluator, 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(Usage(evaluator, name_part, stmt)) names.append(classes.Definition(evaluator, name_part))
else: else:
for call in helpers.scan_statement_for_calls(stmt, search_name, assignment_details=True): for call in helpers.scan_statement_for_calls(stmt, search_name, assignment_details=True):
names += check_call_for_usage(call) names += check_call_for_usage(call)