diff --git a/jedi/api.py b/jedi/api.py index 2fdea535..e4f7f532 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -168,8 +168,10 @@ class Script(object): x.name.lower())) def _prepare_goto(self, goto_path, is_like_search=False): - """ Base for completions, goto and definition. Basically it returns - the resolved scopes under cursor. """ + """ + Base for completions/goto. Basically it returns the resolved scopes + under cursor. + """ debug.dbg('start: %s in %s' % (goto_path, self._parser.user_scope)) user_stmt = self._parser.user_stmt diff --git a/test/base.py b/test/base.py index 6226a431..548e4cfe 100644 --- a/test/base.py +++ b/test/base.py @@ -24,9 +24,9 @@ class TestBase(unittest.TestCase): pos = len(lines), len(lines[-1]) return jedi.Script(src, pos[0], pos[1], path) - def definition(self, src, pos=None): + def goto_definitions(self, src, pos=None): script = self.get_script(src, pos) - return script.definition() + return script.goto_definitions() def completions(self, src, pos=None, path=None): script = self.get_script(src, pos, path) diff --git a/test/test_api_classes.py b/test/test_api_classes.py index a36551ab..65a9d0d2 100644 --- a/test/test_api_classes.py +++ b/test/test_api_classes.py @@ -35,7 +35,7 @@ def make_definitions(): variable = sys or C or x or f or g or g() or h""") lines = source.splitlines() script = api.Script(source, len(lines), len('variable'), None) - definitions += script.definition() + definitions += script.goto_definitions() script2 = api.Script(source, 4, len('class C'), None) definitions += script2.usages() diff --git a/test/test_regression.py b/test/test_regression.py index 0e237d39..30721a09 100755 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -49,7 +49,7 @@ class TestRegression(TestBase): self.function_definition(s, pos) assert self.function_definition(s, pos) - def test_definition_cursor(self): + def test_goto_definition_cursor(self): s = ("class A():\n" " def _something(self):\n" @@ -68,7 +68,7 @@ class TestRegression(TestBase): diff_line = 4, 10 should2 = 8, 10 - get_def = lambda pos: [d.description for d in self.definition(s, pos)] + get_def = lambda pos: [d.description for d in self.goto_definitions(s, pos)] in_name = get_def(in_name) under_score = get_def(under_score) should1 = get_def(should1) @@ -84,20 +84,20 @@ class TestRegression(TestBase): self.assertRaises(jedi.NotFoundError, get_def, cls) def test_keyword_doc(self): - r = list(self.definition("or", (1, 1))) + r = list(self.goto_definitions("or", (1, 1))) assert len(r) == 1 assert len(r[0].doc) > 100 - r = list(self.definition("asfdasfd", (1, 1))) + r = list(self.goto_definitions("asfdasfd", (1, 1))) assert len(r) == 0 def test_operator_doc(self): - r = list(self.definition("a == b", (1, 3))) + r = list(self.goto_definitions("a == b", (1, 3))) assert len(r) == 1 assert len(r[0].doc) > 100 def test_function_call_signature(self): - defs = self.definition(""" + defs = self.goto_definitions(""" def f(x, y=1, z='a'): pass f""") @@ -105,7 +105,7 @@ class TestRegression(TestBase): assert "f(x, y = 1, z = 'a')" in doc def test_class_call_signature(self): - defs = self.definition(""" + defs = self.goto_definitions(""" class Foo: def __init__(self, x, y=1, z='a'): pass @@ -113,12 +113,12 @@ class TestRegression(TestBase): doc = defs[0].doc assert "Foo(self, x, y = 1, z = 'a')" in doc - def test_definition_at_zero(self): - assert self.definition("a", (1, 1)) == [] - s = self.definition("str", (1, 1)) + def test_goto_definition_at_zero(self): + assert self.goto_definitions("a", (1, 1)) == [] + s = self.goto_definitions("str", (1, 1)) assert len(s) == 1 assert list(s)[0].description == 'class str' - assert self.definition("", (1, 0)) == [] + assert self.goto_definitions("", (1, 0)) == [] def test_complete_at_zero(self): s = self.completions("str", (1, 3)) @@ -128,9 +128,9 @@ class TestRegression(TestBase): s = self.completions("", (1, 0)) assert len(s) > 0 - def test_definition_on_import(self): - assert self.definition("import sys_blabla", (1, 8)) == [] - assert len(self.definition("import sys", (1, 8))) == 1 + def test_goto_definition_on_import(self): + assert self.goto_definitions("import sys_blabla", (1, 8)) == [] + assert len(self.goto_definitions("import sys", (1, 8))) == 1 @cwd_at('jedi') def test_complete_on_empty_import(self): @@ -263,15 +263,15 @@ class TestRegression(TestBase): # .parser to load the module api.modules.Module(os.path.abspath('dynamic.py'), src2).parser script = jedi.Script(src1, 1, len(src1), '../setup.py') - result = script.definition() + result = script.goto_definitions() assert len(result) == 1 assert result[0].description == 'class int' def test_named_import(self): """ named import - jedi-vim issue #8 """ s = "import time as dt" - assert len(jedi.Script(s, 1, 15, '/').definition()) == 1 - assert len(jedi.Script(s, 1, 10, '/').definition()) == 1 + assert len(jedi.Script(s, 1, 15, '/').goto_definitions()) == 1 + assert len(jedi.Script(s, 1, 10, '/').goto_definitions()) == 1 def test_unicode_script(self): """ normally no unicode objects are being used. (<=2.7) """ @@ -328,10 +328,10 @@ class TestRegression(TestBase): def test_keyword_definition_doc(self): """ github jedi-vim issue #44 """ - defs = self.definition("print") + defs = self.goto_definitions("print") assert [d.doc for d in defs] - defs = self.definition("import") + defs = self.goto_definitions("import") assert len(defs) == 1 assert [d.doc for d in defs] @@ -380,7 +380,7 @@ class TestRegression(TestBase): variable = f or C""") lines = source.splitlines() - defs = self.definition(source, (len(lines), 3)) + defs = self.goto_definitions(source, (len(lines), 3)) defs = sorted(defs, key=lambda d: d.line) self.assertEqual([d.description for d in defs], ['def f', 'class C']) @@ -389,21 +389,21 @@ class TestRegression(TestBase): class TestDocstring(TestBase): def test_function_doc(self): - defs = self.definition(""" + defs = self.goto_definitions(""" def func(): '''Docstring of `func`.''' func""") self.assertEqual(defs[0].raw_doc, 'Docstring of `func`.') def test_attribute_docstring(self): - defs = self.definition(""" + defs = self.goto_definitions(""" x = None '''Docstring of `x`.''' x""") self.assertEqual(defs[0].raw_doc, 'Docstring of `x`.') def test_multiple_docstrings(self): - defs = self.definition(""" + defs = self.goto_definitions(""" def func(): '''Original docstring.''' x = func @@ -435,7 +435,7 @@ class TestFeature(TestBase): import re any_re = re.compile('.*') any_re""" - self.assertEqual(self.definition(s)[0].full_name, 're.RegexObject') + self.assertEqual(self.goto_definitions(s)[0].full_name, 're.RegexObject') def test_quick_completion(self): sources = [