removed a lot of the goto usages, used goto_assignments instead. Did the same also for a lot of definition uses

This commit is contained in:
David Halter
2013-05-03 21:26:11 +04:30
parent edd0a08351
commit 7c8fee1257
10 changed files with 41 additions and 40 deletions

View File

@@ -37,7 +37,7 @@ class NotFoundError(Exception):
class Script(object):
"""
A Script is the base for a completion, goto or whatever you want to do with
A Script is the base for completions, goto or whatever you want to do with
|jedi|.
:param source: The source code of the current file, separated by newlines.
@@ -264,13 +264,13 @@ class Script(object):
@api_classes._clear_caches_after_call
def goto_definitions(self):
"""
Return the definitions of a the path under the cursor. This is not a
goto function! This follows complicated paths and returns the end, not
the first definition. The big difference between :meth:`goto` and
:meth:`definition` is that :meth:`goto` doesn't follow imports and
statements. Multiple objects may be returned, because Python itself is
a dynamic language, which means depending on an option you can have two
different versions of a function.
Return the definitions of a the path under the cursor. goto function!
This follows complicated paths and returns the end, not the first
definition. The big difference between :meth:`goto_assignments` and
:meth:`goto_definitions` is that :meth:`goto_assignments` doesn't
follow imports and statements. Multiple objects may be returned,
because Python itself is a dynamic language, which means depending on
an option you can have two different versions of a function.
:rtype: list of :class:`api_classes.Definition`
"""
@@ -328,10 +328,10 @@ class Script(object):
@api_classes._clear_caches_after_call
def goto_assignments(self):
"""
Return the first definition found by goto. Imports and statements
aren't followed. Multiple objects may be returned, because Python
itself is a dynamic language, which means depending on an option you
can have two different versions of a function.
Return the first definition found. Imports and statements aren't
followed. Multiple objects may be returned, because Python itself is a
dynamic language, which means depending on an option you can have two
different versions of a function.
:rtype: list of :class:`api_classes.Definition`
"""
@@ -340,7 +340,8 @@ class Script(object):
def _goto(self, add_import_name=False):
"""
Used for goto and usages.
Used for goto_assignments and usages.
:param add_import_name: TODO add description
"""
def follow_inexistent_imports(defs):

View File

@@ -415,8 +415,8 @@ class Completion(BaseDefinition):
class Definition(BaseDefinition):
"""
*Definition* objects are returned from :meth:`api.Script.goto` or
:meth:`api.Script.definition`.
*Definition* objects are returned from :meth:`api.Script.goto_assignments`
or :meth:`api.Script.goto_definitions`.
"""
def __init__(self, definition):
super(Definition, self).__init__(definition, definition.start_pos)

View File

@@ -359,7 +359,7 @@ class SubModule(Scope, Module):
@property
def name(self):
""" This is used for the goto function. """
""" This is used for the goto functions. """
if self._name is not None:
return self._name
if self.path is None:

View File

@@ -32,9 +32,9 @@ class TestBase(unittest.TestCase):
script = self.get_script(src, pos, path)
return script.completions()
def goto(self, src, pos=None):
def goto_assignments(self, src, pos=None):
script = self.get_script(src, pos)
return script.goto()
return script.goto_assignments()
def function_definition(self, src, pos=None):
script = self.get_script(src, pos)

View File

@@ -1,4 +1,4 @@
# goto command tests are a different in syntax
# goto_assignments command tests are different in syntax
definition = 3
#! 0 ['a = definition']

View File

@@ -1,5 +1,5 @@
"""
Renaming tests. This means search for related names.
Renaming tests. This means search for usages.
I always leave a little bit of space to add room for additions, because the
results always contain position informations.
"""

View File

@@ -10,8 +10,7 @@ el.description
scopes, path, dot, like = \
functions.prepare_goto(source, row, column,
source_path, True)
api._prepare_goto(source, row, column, source_path, True)
# has problems with that (sometimes) very deep nesting.
#? set()

View File

@@ -10,9 +10,9 @@ tests.
There are different kind of tests:
- completions / definitions ``#?``
- goto: ``#!``
- related names: ``#<``
- completions / goto_definitions ``#?``
- goto_assignments: ``#!``
- usages: ``#<``
How to run tests?
+++++++++++++++++
@@ -63,8 +63,8 @@ For example::
Because it follows ``a.rea`` and a is an ``int``, which has a ``real``
property.
Definition
++++++++++
Goto Definitions
+++++++++++++++
Definition tests use the same symbols like completion tests. This is
possible because the completion tests are defined with a list::
@@ -72,8 +72,8 @@ possible because the completion tests are defined with a list::
#? int()
ab = 3; ab
Goto
++++
Goto Assignments
++++++++++++++++
Tests look like this::
@@ -87,7 +87,7 @@ the test (otherwise it's just end of line)::
#! 2 ['abc=1']
abc
Related Names
Usages
+++++++++++++
Tests look like this::
@@ -141,8 +141,8 @@ class IntegrationTestCase(object):
def run(self, compare_cb):
testers = {
TEST_COMPLETIONS: self.run_completion,
TEST_DEFINITIONS: self.run_definition,
TEST_ASSIGNMENTS: self.run_goto,
TEST_DEFINITIONS: self.run_goto_definitions,
TEST_ASSIGNMENTS: self.run_goto_assignments,
TEST_USAGES: self.run_usages,
}
return testers[self.test_type](compare_cb)
@@ -154,11 +154,11 @@ class IntegrationTestCase(object):
comp_str = set([c.name for c in completions])
return compare_cb(self, comp_str, set(literal_eval(self.correct)))
def run_definition(self, compare_cb):
def run_goto_definitions(self, compare_cb):
def definition(correct, correct_start, path):
def defs(line_nr, indent):
s = jedi.Script(self.source, line_nr, indent, path)
return set(s.definition())
return set(s.goto_definitions())
should_be = set()
number = 0
@@ -183,12 +183,12 @@ class IntegrationTestCase(object):
script = self.script()
should_str = definition(self.correct, self.start, script.source_path)
result = script.definition()
result = script.goto_definitions()
is_str = set(r.desc_with_module for r in result)
return compare_cb(self, is_str, should_str)
def run_goto(self, compare_cb):
result = self.script().goto()
def run_goto_assignments(self, compare_cb):
result = self.script().goto_assignments()
comp_str = str(sorted(str(r.description) for r in result))
return compare_cb(self, comp_str, self.correct)
@@ -242,7 +242,7 @@ def collect_file_tests(lines, lines_to_execute):
else:
try:
r = re.search(r'(?:^|(?<=\s))#([?!<])\s*([^\n]+)', line)
# test_type is ? for completion and ! for goto
# test_type is ? for completion and ! for goto_assignments
test_type = r.group(1)
correct = r.group(2)
start = r.start()

View File

@@ -42,7 +42,7 @@ def make_definitions():
source_param = "def f(a): return a"
script_param = api.Script(source_param, 1, len(source_param), None)
definitions += script_param.goto()
definitions += script_param.goto_assignments()
return definitions

View File

@@ -336,7 +336,8 @@ class TestRegression(TestBase):
assert [d.doc for d in defs]
def test_goto_following_on_imports(self):
g = self.goto("import multiprocessing.dummy; multiprocessing.dummy")
s = "import multiprocessing.dummy; multiprocessing.dummy"
g = self.goto_assignments(s)
assert len(g) == 1
assert g[0].start_pos != (0, 0)