1
0
forked from VimPlug/jedi

removed keyword docstring functionality for goto_definitions - will be reintroduced with a Script.documentation function

This commit is contained in:
Dave Halter
2014-01-28 22:26:09 +01:00
parent 18f225200a
commit 2175416684
4 changed files with 28 additions and 59 deletions

View File

@@ -322,41 +322,32 @@ class Script(object):
goto_path = self._user_context.get_path_under_cursor() goto_path = self._user_context.get_path_under_cursor()
context = self._user_context.get_context() context = self._user_context.get_context()
scopes = set() definitions = set()
lower_priority_operators = ('()', '(', ',')
"""Operators that could hide callee.""" """Operators that could hide callee."""
if next(context) in ('class', 'def'): if next(context) in ('class', 'def'):
scopes = set([self._parser.user_scope()]) definitions = set([self._parser.user_scope()])
elif not goto_path: else:
op = self._user_context.get_operator_under_cursor() # Fetch definition of callee, if there's no path otherwise.
if op and op not in lower_priority_operators: if not goto_path:
scopes = set([keywords.get_operator(op, self._pos)]) (call, _) = self._func_call_and_param_index()
if call is not None:
while call.next is not None:
call = call.next
# reset cursor position:
(row, col) = call.name.end_pos
pos = (row, max(col - 1, 0))
self._user_context = UserContext(self.source, pos)
# then try to find the path again
goto_path = self._user_context.get_path_under_cursor()
# Fetch definition of callee, if there's no path otherwise. if not definitions:
if not goto_path:
(call, _) = self._func_call_and_param_index()
if call is not None:
while call.next is not None:
call = call.next
# reset cursor position:
(row, col) = call.name.end_pos
pos = (row, max(col - 1, 0))
self._user_context = UserContext(self.source, pos)
# then try to find the path again
goto_path = self._user_context.get_path_under_cursor()
if not scopes:
if goto_path: if goto_path:
scopes = set(self._prepare_goto(goto_path)) definitions = set(self._prepare_goto(goto_path))
elif op in lower_priority_operators: else:
scopes = set([keywords.get_operator(op, self._pos)]) definitions = set([])
scopes = resolve_import_paths(scopes) definitions = resolve_import_paths(definitions)
d = set([classes.Definition(self._evaluator, s) for s in definitions
# add keywords
scopes |= keywords.keywords(string=goto_path, pos=self._pos)
d = set([classes.Definition(self._evaluator, s) for s in scopes
if s is not imports.ImportPath.GlobalNamespace]) if s is not imports.ImportPath.GlobalNamespace])
return self._sorted_defs(d) return self._sorted_defs(d)

View File

@@ -10,8 +10,8 @@ import jedi
def test_is_keyword(): def test_is_keyword():
results = Script('import ', 1, 1, None).goto_definitions() #results = Script('import ', 1, 1, None).goto_definitions()
assert len(results) == 1 and results[0].is_keyword is True #assert len(results) == 1 and results[0].is_keyword is True
results = Script('str', 1, 1, None).goto_definitions() results = Script('str', 1, 1, None).goto_definitions()
assert len(results) == 1 and results[0].is_keyword is False assert len(results) == 1 and results[0].is_keyword is False

View File

@@ -4,6 +4,7 @@ Test of keywords and ``jedi.keywords``
import jedi import jedi
from jedi import Script, common from jedi import Script, common
def test_goto_assignments_keyword(): def test_goto_assignments_keyword():
""" """
Bug: goto assignments on ``in`` used to raise AttributeError:: Bug: goto assignments on ``in`` used to raise AttributeError::
@@ -12,35 +13,16 @@ def test_goto_assignments_keyword():
""" """
Script('in').goto_assignments() Script('in').goto_assignments()
def test_keyword_doc():
r = list(Script("or", 1, 1).goto_definitions())
assert len(r) == 1
assert len(r[0].doc) > 100
r = list(Script("asfdasfd", 1, 1).goto_definitions())
assert len(r) == 0
k = Script("fro").completions()[0]
imp_start = '\nThe ``import'
assert k.raw_doc.startswith(imp_start)
assert k.doc.startswith(imp_start)
def test_keyword(): def test_keyword():
""" github jedi-vim issue #44 """ """ github jedi-vim issue #44 """
defs = Script("print").goto_definitions() defs = Script("print").goto_definitions()
assert [d.doc for d in defs] assert [d.doc for d in defs]
defs = Script("import").goto_definitions()
assert len(defs) == 1 and [1 for d in defs if d.doc]
# unrelated to #44
defs = Script("import").goto_assignments() defs = Script("import").goto_assignments()
assert len(defs) == 0 assert len(defs) == 0
completions = Script("import", 1,1).completions() completions = Script("import", 1, 1).completions()
assert len(completions) == 0 assert len(completions) == 0
with common.ignored(jedi.NotFoundError): # TODO shouldn't throw that. with common.ignored(jedi.NotFoundError): # TODO shouldn't throw that.
defs = Script("assert").goto_definitions() defs = Script("assert").goto_definitions()
assert len(defs) == 1 assert len(defs) == 1
def test_lambda():
defs = Script('lambda x: x', column=0).goto_definitions()
assert [d.type for d in defs] == ['keyword']

View File

@@ -55,11 +55,6 @@ class TestRegression(TestCase):
self.assertRaises(jedi.NotFoundError, get_def, cls) self.assertRaises(jedi.NotFoundError, get_def, cls)
def test_operator_doc(self):
r = list(Script("a == b", 1, 3).goto_definitions())
assert len(r) == 1
assert len(r[0].doc) > 100
def test_goto_definition_at_zero(self): def test_goto_definition_at_zero(self):
assert Script("a", 1, 1).goto_definitions() == [] assert Script("a", 1, 1).goto_definitions() == []
s = Script("str", 1, 1).goto_definitions() s = Script("str", 1, 1).goto_definitions()
@@ -142,7 +137,8 @@ class TestRegression(TestCase):
break break
column = len(line) - len(after_cursor) column = len(line) - len(after_cursor)
defs = Script(source, i + 1, column).goto_definitions() defs = Script(source, i + 1, column).goto_definitions()
self.assertEqual([d.name for d in defs], names) print(defs)
assert [d.name for d in defs] == names
def test_backslash_continuation(self): def test_backslash_continuation(self):
""" """
@@ -163,7 +159,7 @@ class TestRegression(TestCase):
x = 0 x = 0
a = \ a = \
[1, 2, 3, 4, 5, 6, 7, 8, 9, (x)] # <-- here [1, 2, 3, 4, 5, 6, 7, 8, 9, (x)] # <-- here
""", '(x)] # <-- here', [None]) """, '(x)] # <-- here', [])
def test_generator(self): def test_generator(self):
# Did have some problems with the usage of generator completions this # Did have some problems with the usage of generator completions this