diff --git a/jedi/parser/tree.py b/jedi/parser/tree.py index 5cb44fa4..30d6ada7 100644 --- a/jedi/parser/tree.py +++ b/jedi/parser/tree.py @@ -69,9 +69,10 @@ class DocstringMixin(object): stmt = self.children[self.children.index(':') + 1] if is_node(stmt, 'suite'): # Normally a suite stmt = stmt.children[2] # -> NEWLINE INDENT stmt - else: - c = self.parent.children - index = c.index(self) - 1 + else: # ExprStmt + simple_stmt = self.parent + c = simple_stmt.parent.children + index = c.index(simple_stmt) if not index: return '' stmt = c[index - 1] diff --git a/test/test_api/test_api_classes.py b/test/test_api/test_api_classes.py index 11bf596f..a4c28f8f 100644 --- a/test/test_api/test_api_classes.py +++ b/test/test_api/test_api_classes.py @@ -129,6 +129,11 @@ def test_completion_docstring(): docstr('import jedi\njedi.Scr', cleandoc(Script.__doc__)) docstr('abcd=3;abcd', '') + docstr('"hello"\nabcd=3\nabcd', 'hello') + # It works with a ; as well. + docstr('"hello"\nabcd=3;abcd', 'hello') + # Shouldn't work with a tuple. + docstr('"hello",0\nabcd=3\nabcd', '') def test_completion_params():