From a5531f2a817b86058d74f059c20d3d8595b3cc21 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sun, 22 Apr 2012 17:01:15 +0200 Subject: [PATCH] functions don't return values anymore, if they are not executed --- evaluate.py | 57 ++++++++++++++++++------------------ functions.py | 16 ++++++---- test/completion/functions.py | 5 ++++ 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/evaluate.py b/evaluate.py index e5cc719a..e3c37bda 100644 --- a/evaluate.py +++ b/evaluate.py @@ -324,7 +324,7 @@ def follow_statement(stmt, scope=None): parsing.Class, Instance) call_list = stmt.get_assignment_calls() debug.dbg('calls', call_list, call_list.values) - return follow_call_list(scope, call_list) + return set(follow_call_list(scope, call_list)) def follow_call_list(scope, call_list): @@ -382,40 +382,39 @@ def follow_paths(path, results): return results_new -def follow_path(path, input): +def follow_path(path, scope): """ Takes a generator and tries to complete the path. """ # current is either an Array or a Scope current = next(path) - debug.dbg('follow', current, input) + debug.dbg('follow', current, scope) - def filter_result(scope): - result = [] - if isinstance(current, parsing.Array): - # this must be an execution, either () or [] - if current.type == parsing.Array.LIST: - result = scope.get_index_types(current) - elif current.type not in [parsing.Array.DICT]: - # scope must be a class or func - make an instance or execution - debug.dbg('befexec', scope) - exe = Execution(scope, current) - result = strip_imports(exe.get_return_types()) - debug.dbg('exec', result) - #except AttributeError: - # debug.dbg('cannot execute:', scope) - else: - # curly braces are not allowed, because they make no sense - debug.warning('strange function call with {}', current, scope) + result = [] + if isinstance(current, parsing.Array): + # this must be an execution, either () or [] + if current.type == parsing.Array.LIST: + result = scope.get_index_types(current) + elif current.type not in [parsing.Array.DICT]: + # scope must be a class or func - make an instance or execution + debug.dbg('befexec', scope) + exe = Execution(scope, current) + result = strip_imports(exe.get_return_types()) + debug.dbg('exec', result) + #except AttributeError: + # debug.dbg('cannot execute:', scope) else: - if isinstance(scope, parsing.Function): - # TODO check default function methods and return them - result = [] - else: - # TODO check magic class methods and return them also - result = strip_imports(get_scopes_for_name(scope, current)) - return result - return follow_paths(path, filter_result(input)) + # curly braces are not allowed, because they make no sense + debug.warning('strange function call with {}', current, scope) + else: + if isinstance(scope, parsing.Function): + # TODO this is never reached, just remove it? + # TODO check default function methods and return them + result = [] + else: + # TODO check magic class methods and return them also + result = strip_imports(get_scopes_for_name(scope, current)) + return follow_paths(path, result) def follow_import(_import): @@ -456,4 +455,4 @@ def remove_star_imports(scope): modules += new # filter duplicate modules - return list(set(modules)) + return set(modules) diff --git a/functions.py b/functions.py index 8896014b..f63cb318 100644 --- a/functions.py +++ b/functions.py @@ -188,6 +188,9 @@ def complete(source, row, column, source_path): stmt = r.top.statements[0] except IndexError: completions = evaluate.get_names_for_scope(scope) + #for c in completions: + # if isinstance(, parsing.Function): + # print c.parent else: stmt.parent = scope scopes = evaluate.follow_statement(stmt, scope=scope) @@ -195,16 +198,17 @@ def complete(source, row, column, source_path): completions = [] debug.dbg('possible scopes', scopes) for s in scopes: - completions += s.get_defined_names() + # TODO is this reall the right way, just ignore the functions? + if not isinstance(s, parsing.Function): + completions += s.get_defined_names() - completions = list(set(completions)) - - needs_dot = not dot and path - completions = [Completion(c, needs_dot, len(like)) for c in completions + completions = [c for c in completions if c.names[-1].lower().startswith(like.lower())] _clear_caches() - return completions + + needs_dot = not dot and path + return [Completion(c, needs_dot, len(like)) for c in set(completions)] def set_debug_function(func_cb): diff --git a/test/completion/functions.py b/test/completion/functions.py index 357bf1b8..8177cd6d 100644 --- a/test/completion/functions.py +++ b/test/completion/functions.py @@ -6,6 +6,11 @@ def array(first_param): #? [] array.first_param +#? [] +array.first_param. +func = array +#? [] +func.first_param #? ['append'] array().append