1
0
forked from VimPlug/jedi

Suites don't have to contain statements anymore, this makes autocompletion better in certain cases.

This commit is contained in:
Dave Halter
2015-01-12 01:11:46 +01:00
parent f8570b1f03
commit 5c98f6cf04
2 changed files with 13 additions and 24 deletions
+1
View File
@@ -431,6 +431,7 @@ class Class(use_metaclass(CachedMetaClass, Wrapper)):
yield self.names_dict yield self.names_dict
else: else:
for scope in self.py__mro__(self._evaluator): for scope in self.py__mro__(self._evaluator):
print(scope.names_dict)
if isinstance(scope, compiled.CompiledObject): if isinstance(scope, compiled.CompiledObject):
yield scope.names_dicts(False, is_instance)[0] yield scope.names_dicts(False, is_instance)[0]
else: else:
+12 -24
View File
@@ -107,6 +107,7 @@ class Parser(object):
self.global_names = [] self.global_names = []
print('start')
# TODO do print absolute import detection here. # TODO do print absolute import detection here.
#try: #try:
# del python_grammar_no_print_statement.keywords["print"] # del python_grammar_no_print_statement.keywords["print"]
@@ -233,19 +234,17 @@ class Parser(object):
if value in ('import', 'from', 'class', 'def', 'try', 'while', 'return'): if value in ('import', 'from', 'class', 'def', 'try', 'while', 'return'):
# Those can always be new statements. # Those can always be new statements.
add_token_callback(typ, value, prefix, start_pos) add_token_callback(typ, value, prefix, start_pos)
elif typ == token.DEDENT: elif typ == token.DEDENT and symbol == 'suite':
if symbol == 'suite': # Close the current suite, with DEDENT.
# If a function or anything else contains a suite that is # Note that this may cause some suites to not contain any
# "empty" (just NEWLINE/INDENT), we remove it. If it's not # statements at all. This is contrary to valid Python syntax. We
# empty, we can close it. # keep incomplete suites in Jedi to be able to complete param names
if len(nodes) > 2: # or `with ... as foo` names. If we want to use this parser for
# Finish the suite. # syntax checks, we have to check in a separate turn if suites
add_token_callback(typ, value, prefix, start_pos) # contain statements or not. However, a second check is necessary
else: # anyway (compile.c does that for Python), because Python's grammar
# Remove the current suite from the stack to look deeper in # doesn't stop you from defining `continue` in a module, etc.
# the stack for a suite/file_input. add_token_callback(typ, value, prefix, start_pos)
index, symbol, nodes = current_suite(stack[:-1])
self._stack_removal(grammar, stack, index + 1, value, start_pos)
def _stack_removal(self, grammar, stack, start_index, value, start_pos): def _stack_removal(self, grammar, stack, start_index, value, start_pos):
def clear_names(children): def clear_names(children):
@@ -280,17 +279,6 @@ class Parser(object):
stack[start_index:] = [] stack[start_index:] = []
def _tokenize(self, tokenizer): def _tokenize(self, tokenizer):
"""
while first_pos[1] <= self._scope.start_pos[1] \
and (token_type == token.NAME or tok_str in ('(', '['))\
and self._scope != self.module:
self._scope.end_pos = first_pos
self._scope = self._scope.parent
if isinstance(self._scope, pr.Module) \
and not isinstance(self._scope, pr.SubModule):
self._scope = self.module
"""
for typ, value, start_pos, prefix in tokenizer: for typ, value, start_pos, prefix in tokenizer:
if typ == token.OP: if typ == token.OP:
typ = token.opmap[value] typ = token.opmap[value]