From e72eaf7a59704337800b97696315c58bf584cfc3 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 25 Nov 2014 15:10:36 +0100 Subject: [PATCH] on import completion preparations. --- jedi/parser/__init__.py | 16 +++++++++++++--- test/completion/imports.py | 3 +-- test/completion/on_import.py | 5 +++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index 023c8f41..6d31505c 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -104,6 +104,7 @@ class Parser(object): # and only if the refactor method's write parameter was True. self.used_names = {} self.scope_names_stack = [{}] + self.failed_statement_stacks = [] logger = logging.getLogger("Jedi-Parser") d = pgen2.Driver(grammar, self.convert_node, self.convert_leaf, self.error_recovery, logger=logger) @@ -189,11 +190,10 @@ class Parser(object): if symbol in ('file_input', 'suite'): index = i break - self._stack_removal(stack, index + 1) # No success finding a transition - #raise ParseError("bad input", type, value, context) + self._stack_removal(grammar, stack, index + 1) - def _stack_removal(self, stack, start_index): + def _stack_removal(self, grammar, stack, start_index): def clear_names(children): for c in children: try: @@ -206,6 +206,16 @@ class Parser(object): except ValueError: pass # This may happen with CompFor. + failed_stack = [] + found = False + for dfa, state, (typ, nodes) in stack[start_index:]: + if nodes: + found = True + if found: + symbol = grammar.number2symbol[typ] + failed_stack.append((symbol, nodes)) + self.failed_statement_stacks.append(failed_stack) + for dfa, state, node in stack[start_index:]: clear_names(children=node[1]) diff --git a/test/completion/imports.py b/test/completion/imports.py index 4cf48d18..9e75c9d6 100644 --- a/test/completion/imports.py +++ b/test/completion/imports.py @@ -228,8 +228,7 @@ from import_tree import recurse_class1 #? ['a'] recurse_class1.C.a # github #239 RecursionError -# TODO UNCOMMENT!!!!!! -##? ['a'] +#? ['a'] recurse_class1.C().a # ----------------- diff --git a/test/completion/on_import.py b/test/completion/on_import.py index b5af97c5..a2ec198a 100644 --- a/test/completion/on_import.py +++ b/test/completion/on_import.py @@ -4,6 +4,11 @@ def from_names(): #? ['path'] from os. +def from_names_goto(): + from import_tree import pkg + #? pkg + from import_tree.pkg + def builtin_test(): #? ['math'] import math