mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
find_references -> get_references, see #1476
This commit is contained in:
@@ -23,7 +23,7 @@ Changelog
|
|||||||
- ``goto_assignments`` deprecated, use ``goto`` instead
|
- ``goto_assignments`` deprecated, use ``goto`` instead
|
||||||
- ``goto_definitions`` deprecated, use ``infer`` instead
|
- ``goto_definitions`` deprecated, use ``infer`` instead
|
||||||
- ``call_signatures`` deprecated, use ``find_signatures`` instead
|
- ``call_signatures`` deprecated, use ``find_signatures`` instead
|
||||||
- ``usages`` deprecated, use ``find_references`` instead
|
- ``usages`` deprecated, use ``get_references`` instead
|
||||||
- ``jedi.names`` deprecated, use ``jedi.Script(...).names()``
|
- ``jedi.names`` deprecated, use ``jedi.Script(...).names()``
|
||||||
- ``BaseDefinition.goto_assignments`` renamed to ``BaseDefinition.goto``
|
- ``BaseDefinition.goto_assignments`` renamed to ``BaseDefinition.goto``
|
||||||
- Python 2 support deprecated. For this release it is best effort. Python 2 has
|
- Python 2 support deprecated. For this release it is best effort. Python 2 has
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ Please check the API for a good explanation. There are the following commands:
|
|||||||
|
|
||||||
- ``jedi.Script.goto``
|
- ``jedi.Script.goto``
|
||||||
- ``jedi.Script.complete``
|
- ``jedi.Script.complete``
|
||||||
- ``jedi.Script.find_references``
|
- ``jedi.Script.get_references``
|
||||||
|
|
||||||
The returned objects are very powerful and really all you might need.
|
The returned objects are very powerful and really all you might need.
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ References:
|
|||||||
... else:
|
... else:
|
||||||
... del x'''
|
... del x'''
|
||||||
>>> script = jedi.Script(source, '')
|
>>> script = jedi.Script(source, '')
|
||||||
>>> rns = script.find_references(5, 8)
|
>>> rns = script.get_references(5, 8)
|
||||||
>>> rns
|
>>> rns
|
||||||
[<Definition full_name='__main__.x', description='x = 3'>,
|
[<Definition full_name='__main__.x', description='x = 3'>,
|
||||||
<Definition full_name='__main__.x', description='x'>]
|
<Definition full_name='__main__.x', description='x'>]
|
||||||
|
|||||||
@@ -363,10 +363,10 @@ class Script(object):
|
|||||||
|
|
||||||
def usages(self, **kwargs):
|
def usages(self, **kwargs):
|
||||||
# Deprecated, will be removed.
|
# Deprecated, will be removed.
|
||||||
return self.find_references(*self._pos, **kwargs)
|
return self.get_references(*self._pos, **kwargs)
|
||||||
|
|
||||||
@validate_line_column
|
@validate_line_column
|
||||||
def find_references(self, line=None, column=None, **kwargs):
|
def get_references(self, line=None, column=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Return :class:`classes.Definition` 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
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ def rename(script, new_name):
|
|||||||
:param script: The source Script object.
|
:param script: The source Script object.
|
||||||
:return: list of changed lines/changed files
|
:return: list of changed lines/changed files
|
||||||
"""
|
"""
|
||||||
return Refactoring(_rename(script.find_references(), new_name))
|
return Refactoring(_rename(script.get_references(), new_name))
|
||||||
|
|
||||||
|
|
||||||
def _rename(names, replace_str):
|
def _rename(names, replace_str):
|
||||||
@@ -169,7 +169,7 @@ def inline(script):
|
|||||||
definitions = script.goto()
|
definitions = script.goto()
|
||||||
assert len(definitions) == 1
|
assert len(definitions) == 1
|
||||||
stmt = definitions[0]._definition
|
stmt = definitions[0]._definition
|
||||||
references = script.find_references()
|
references = script.get_references()
|
||||||
inlines = [r for r in references
|
inlines = [r for r in references
|
||||||
if not stmt.start_pos <= (r.line, r.column) <= stmt.end_pos]
|
if not stmt.start_pos <= (r.line, r.column) <= stmt.end_pos]
|
||||||
inlines = sorted(inlines, key=lambda x: (x.module_path, x.line, x.column),
|
inlines = sorted(inlines, key=lambda x: (x.module_path, x.line, x.column),
|
||||||
|
|||||||
2
sith.py
2
sith.py
@@ -95,7 +95,7 @@ class TestCase(object):
|
|||||||
args = json.load(f)
|
args = json.load(f)
|
||||||
return cls(*args)
|
return cls(*args)
|
||||||
|
|
||||||
operations = ['complete', 'goto', 'infer', 'find_references', 'find_signatures']
|
operations = ['complete', 'goto', 'infer', 'get_references', 'find_signatures']
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def generate(cls, file_path):
|
def generate(cls, file_path):
|
||||||
|
|||||||
@@ -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.find_references`.
|
`Script.get_references`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# --- simple
|
# --- simple
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ class IntegrationTestCase(BaseTestCase):
|
|||||||
TEST_COMPLETIONS: self.run_completion,
|
TEST_COMPLETIONS: self.run_completion,
|
||||||
TEST_INFERENCE: self.run_inference,
|
TEST_INFERENCE: self.run_inference,
|
||||||
TEST_GOTO: self.run_goto,
|
TEST_GOTO: self.run_goto,
|
||||||
TEST_REFERENCES: self.run_find_references,
|
TEST_REFERENCES: self.run_get_references,
|
||||||
}
|
}
|
||||||
if (self.path.endswith('pytest.py') or self.path.endswith('conftest.py')) \
|
if (self.path.endswith('pytest.py') or self.path.endswith('conftest.py')) \
|
||||||
and environment.executable != os.path.realpath(sys.executable):
|
and environment.executable != os.path.realpath(sys.executable):
|
||||||
@@ -261,8 +261,8 @@ class IntegrationTestCase(BaseTestCase):
|
|||||||
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_find_references(self, compare_cb, environment):
|
def run_get_references(self, compare_cb, environment):
|
||||||
result = self.script(environment).find_references(self.line_nr, self.column)
|
result = self.script(environment).get_references(self.line_nr, self.column)
|
||||||
self.correct = self.correct.strip()
|
self.correct = self.correct.strip()
|
||||||
compare = sorted(
|
compare = sorted(
|
||||||
(('stub:' if r.is_stub() else '')
|
(('stub:' if r.is_stub() else '')
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ def test_line_number_errors(Script):
|
|||||||
|
|
||||||
# ok
|
# ok
|
||||||
Script(s).find_signatures(1, 0)
|
Script(s).find_signatures(1, 0)
|
||||||
Script(s).find_references(1, len(s))
|
Script(s).get_references(1, len(s))
|
||||||
|
|
||||||
|
|
||||||
def _check_number(Script, source, result='float'):
|
def _check_number(Script, source, result='float'):
|
||||||
@@ -163,7 +163,7 @@ def test_goto_definition_not_multiple(Script):
|
|||||||
|
|
||||||
|
|
||||||
def test_reference_description(Script):
|
def test_reference_description(Script):
|
||||||
descs = [u.description for u in Script("foo = ''; foo").find_references()]
|
descs = [u.description for u in Script("foo = ''; foo").get_references()]
|
||||||
assert set(descs) == {"foo = ''", 'foo'}
|
assert set(descs) == {"foo = ''", 'foo'}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ def test_basedefinition_type(Script, names):
|
|||||||
definitions += script.infer(len(lines), len('variable'))
|
definitions += script.infer(len(lines), len('variable'))
|
||||||
|
|
||||||
script2 = Script(source, path=None)
|
script2 = Script(source, path=None)
|
||||||
definitions += script2.find_references(4, len('class C'))
|
definitions += script2.get_references(4, len('class C'))
|
||||||
|
|
||||||
source_param = "def f(a): return a"
|
source_param = "def f(a): return a"
|
||||||
script_param = Script(source_param, path=None)
|
script_param = Script(source_param, path=None)
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
def test_import_references(Script):
|
def test_import_references(Script):
|
||||||
s = Script("from .. import foo", path="foo.py")
|
s = Script("from .. import foo", path="foo.py")
|
||||||
assert [usage.line for usage in s.find_references(line=1, column=18)] == [1]
|
assert [usage.line for usage in s.get_references(line=1, column=18)] == [1]
|
||||||
|
|
||||||
|
|
||||||
def test_exclude_builtin_modules(Script):
|
def test_exclude_builtin_modules(Script):
|
||||||
def get(include):
|
def get(include):
|
||||||
from jedi.api.project import Project
|
from jedi.api.project import Project
|
||||||
script = Script(source, _project=Project('', sys_path=[]))
|
script = Script(source, _project=Project('', sys_path=[]))
|
||||||
references = script.find_references(column=8, include_builtins=include)
|
references = script.get_references(column=8, include_builtins=include)
|
||||||
return [(d.line, d.column) for d in references]
|
return [(d.line, d.column) for d in references]
|
||||||
source = '''import sys\nprint(sys.path)'''
|
source = '''import sys\nprint(sys.path)'''
|
||||||
places = get(include=True)
|
places = get(include=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user