mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
removed related_names occurences in favor of usages
This commit is contained in:
@@ -340,7 +340,7 @@ class Script(object):
|
|||||||
|
|
||||||
def _goto(self, add_import_name=False):
|
def _goto(self, add_import_name=False):
|
||||||
"""
|
"""
|
||||||
Used for goto and related_names.
|
Used for goto and usages.
|
||||||
:param add_import_name: TODO add description
|
:param add_import_name: TODO add description
|
||||||
"""
|
"""
|
||||||
def follow_inexistent_imports(defs):
|
def follow_inexistent_imports(defs):
|
||||||
@@ -409,12 +409,12 @@ class Script(object):
|
|||||||
if unicode(v.names[-1]) == search_name]
|
if unicode(v.names[-1]) == search_name]
|
||||||
if not isinstance(user_stmt, pr.Import):
|
if not isinstance(user_stmt, pr.Import):
|
||||||
# import case is looked at with add_import_name option
|
# import case is looked at with add_import_name option
|
||||||
definitions = dynamic.related_name_add_import_modules(definitions,
|
definitions = dynamic.usages_add_import_modules(definitions,
|
||||||
search_name)
|
search_name)
|
||||||
|
|
||||||
module = set([d.get_parent_until() for d in definitions])
|
module = set([d.get_parent_until() for d in definitions])
|
||||||
module.add(self._parser.module)
|
module.add(self._parser.module)
|
||||||
names = dynamic.related_names(definitions, search_name, module)
|
names = dynamic.usages(definitions, search_name, module)
|
||||||
|
|
||||||
for d in set(definitions):
|
for d in set(definitions):
|
||||||
if isinstance(d, pr.Module):
|
if isinstance(d, pr.Module):
|
||||||
|
|||||||
@@ -417,7 +417,7 @@ class ArrayInstance(pr.Base):
|
|||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
def related_names(definitions, search_name, mods):
|
def usages(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
|
||||||
sometimes the id's of the objects change (e.g. executions).
|
sometimes the id's of the objects change (e.g. executions).
|
||||||
@@ -439,7 +439,7 @@ def related_names(definitions, search_name, mods):
|
|||||||
|
|
||||||
for f in follow:
|
for f in follow:
|
||||||
follow_res, search = evaluate.goto(call.parent, f)
|
follow_res, search = evaluate.goto(call.parent, f)
|
||||||
follow_res = related_name_add_import_modules(follow_res, search)
|
follow_res = usages_add_import_modules(follow_res, search)
|
||||||
|
|
||||||
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
|
||||||
@@ -483,7 +483,7 @@ def related_names(definitions, search_name, mods):
|
|||||||
return names
|
return names
|
||||||
|
|
||||||
|
|
||||||
def related_name_add_import_modules(definitions, search_name):
|
def usages_add_import_modules(definitions, search_name):
|
||||||
""" Adds the modules of the imports """
|
""" Adds the modules of the imports """
|
||||||
new = set()
|
new = set()
|
||||||
for d in definitions:
|
for d in definitions:
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ def rename(script, new_name):
|
|||||||
:type source: str
|
:type source: str
|
||||||
:return: list of changed lines/changed files
|
:return: list of changed lines/changed files
|
||||||
"""
|
"""
|
||||||
return Refactoring(_rename(script.related_names(), new_name))
|
return Refactoring(_rename(script.usages(), new_name))
|
||||||
|
|
||||||
|
|
||||||
def _rename(names, replace_str):
|
def _rename(names, replace_str):
|
||||||
@@ -171,8 +171,8 @@ def inline(script):
|
|||||||
with common.ignored(AssertionError):
|
with common.ignored(AssertionError):
|
||||||
assert len(definitions) == 1
|
assert len(definitions) == 1
|
||||||
stmt = definitions[0]._definition
|
stmt = definitions[0]._definition
|
||||||
related_names = script.related_names()
|
usages = script.usages()
|
||||||
inlines = [r for r in related_names
|
inlines = [r for r in usages
|
||||||
if not stmt.start_pos <= r.start_pos <= stmt.end_pos]
|
if not stmt.start_pos <= r.start_pos <= stmt.end_pos]
|
||||||
inlines = sorted(inlines, key=lambda x: (x.module_path, x.start_pos),
|
inlines = sorted(inlines, key=lambda x: (x.module_path, x.start_pos),
|
||||||
reverse=True)
|
reverse=True)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
Test coverage for renaming is mostly being done by testing
|
Test coverage for renaming is mostly being done by testing
|
||||||
`Script.get_related_names`.
|
`Script.usages`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# --- simple
|
# --- simple
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ class IntegrationTestCase(object):
|
|||||||
TEST_COMPLETIONS: self.run_completion,
|
TEST_COMPLETIONS: self.run_completion,
|
||||||
TEST_DEFINITIONS: self.run_definition,
|
TEST_DEFINITIONS: self.run_definition,
|
||||||
TEST_ASSIGNMENTS: self.run_goto,
|
TEST_ASSIGNMENTS: self.run_goto,
|
||||||
TEST_USAGES: self.run_related_name,
|
TEST_USAGES: self.run_usages,
|
||||||
}
|
}
|
||||||
return testers[self.test_type](compare_cb)
|
return testers[self.test_type](compare_cb)
|
||||||
|
|
||||||
@@ -192,8 +192,8 @@ class IntegrationTestCase(object):
|
|||||||
comp_str = str(sorted(str(r.description) for r in result))
|
comp_str = str(sorted(str(r.description) for r in result))
|
||||||
return compare_cb(self, comp_str, self.correct)
|
return compare_cb(self, comp_str, self.correct)
|
||||||
|
|
||||||
def run_related_name(self, compare_cb):
|
def run_usages(self, compare_cb):
|
||||||
result = self.script().related_names()
|
result = self.script().usages()
|
||||||
self.correct = self.correct.strip()
|
self.correct = self.correct.strip()
|
||||||
compare = sorted((r.module_name, r.start_pos[0], r.start_pos[1])
|
compare = sorted((r.module_name, r.start_pos[0], r.start_pos[1])
|
||||||
for r in result)
|
for r in result)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ def make_definitions():
|
|||||||
definitions += script.definition()
|
definitions += script.definition()
|
||||||
|
|
||||||
script2 = api.Script(source, 4, len('class C'), None)
|
script2 = api.Script(source, 4, len('class C'), None)
|
||||||
definitions += script2.related_names()
|
definitions += script2.usages()
|
||||||
|
|
||||||
source_param = "def f(a): return a"
|
source_param = "def f(a): return a"
|
||||||
script_param = api.Script(source_param, 1, len(source_param), None)
|
script_param = api.Script(source_param, 1, len(source_param), None)
|
||||||
|
|||||||
Reference in New Issue
Block a user