diff --git a/jedi/api.py b/jedi/api.py index aef2f764..bc0c1e23 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -389,9 +389,9 @@ class Script(object): defs, search_name = evaluate.goto(stmt) definitions = follow_inexistent_imports(defs) if isinstance(user_stmt, pr.Statement): - call = user_stmt.get_commands()[0] - if not isinstance(call, (str, unicode)) and \ - call.start_pos > self.pos: + c = user_stmt.get_commands() + if c and not isinstance(c[0], (str, unicode)) and \ + c[0].start_pos > self.pos: # The cursor must be after the start, otherwise the # statement is just an assignee. definitions = [user_stmt] diff --git a/jedi/evaluate.py b/jedi/evaluate.py index e958bd34..142852bc 100644 --- a/jedi/evaluate.py +++ b/jedi/evaluate.py @@ -795,6 +795,8 @@ def filter_private_variable(scope, call_scope, var_name): def goto(stmt, call_path=None): if call_path is None: commands = stmt.get_commands() + if len(commands) == 0: + return [], '' # Only the first command is important, the rest should basically not # happen except in broken code (e.g. docstrings that aren't code). call = commands[0] diff --git a/test/completion/invalid.py b/test/completion/invalid.py index cbcbb19c..f109e14c 100644 --- a/test/completion/invalid.py +++ b/test/completion/invalid.py @@ -119,4 +119,11 @@ def asdf(a or b): # multiple param names #? int() asdf(2) +# ----------------- +# goto +# ----------------- + +#! [] +as + import datetime as