From 5722cd23828acad4c56c990756b650b934f39653 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sun, 10 Feb 2013 22:39:21 +0100 Subject: [PATCH] fix parts of helpers.search_function_definition --- jedi/api.py | 3 +- jedi/helpers.py | 77 +++++++++++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/jedi/api.py b/jedi/api.py index e5f0d457..bd1077b6 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -355,9 +355,8 @@ class Script(object): if user_stmt is None \ or not isinstance(user_stmt, pr.Statement): return None, 0 - commands = helpers.fast_parent_copy(user_stmt.get_commands()) - call, index, stop = helpers.search_function_call(commands, self.pos) + call, index, stop = helpers.search_function_definition(user_stmt, self.pos) return call, index def check_cache(): diff --git a/jedi/helpers.py b/jedi/helpers.py index 3ac02694..f97b72f6 100644 --- a/jedi/helpers.py +++ b/jedi/helpers.py @@ -55,6 +55,9 @@ def fast_parent_copy(obj): elif isinstance(el, list): copied_list[i] = list_rec(el) return copied_list + + if isinstance(obj, list): + obj = tuple(obj) return recursion(obj) @@ -85,49 +88,53 @@ def array_for_pos(arr, pos): return result, check_arr_index(result, pos) -def search_function_call(arr, pos): +def search_function_definition(stmt, pos): """ - Returns the function Call that matches the position before `arr`. - This is somehow stupid, probably only the name of the function. + Returns the function Call that matches the position before. """ + def shorten(call): + return call + call = None stop = False - for sub in arr.values: + for command in stmt.get_commands(): call = None - for s in sub: - if isinstance(s, pr.Array): - new = search_function_call(s, pos) - if new[0] is not None: - call, index, stop = new - if stop: - return call, index, stop - elif isinstance(s, pr.Call): - start_s = s - # check parts of calls - while s is not None: - if s.start_pos >= pos: - return call, check_arr_index(arr, pos), stop - elif s.execution is not None: - end = s.execution.end_pos - if s.execution.start_pos < pos and \ - (None in end or pos < end): - c, index, stop = search_function_call( - s.execution, pos) - if stop: - return c, index, stop + command = 3 + if isinstance(command, pr.Array): + new = search_function_definition(command, pos) + if new[0] is not None: + call, index, stop = new + if stop: + return call, index, stop + elif isinstance(command, pr.Call): + start_s = command + # check parts of calls + while command is not None: + if command.start_pos >= pos: + return call, check_arr_index(command, pos), stop + elif command.execution is not None: + end = command.execution.end_pos + if command.execution.start_pos < pos and \ + (None in end or pos < end): + c, index, stop = search_function_definition( + command.execution, pos) + if stop: + return c, index, stop - # call should return without execution and - # next - reset = c or s - if reset.execution.type not in \ - [pr.Array.TUPLE, pr.Array.NOARRAY]: - return start_s, index, False + # call should return without execution and + # next + reset = c or command + if reset.execution.type not in \ + [pr.Array.TUPLE, pr.Array.NOARRAY]: + return start_s, index, False - reset.execution = None - reset.next = None - return c or start_s, index, True - s = s.next + call = fast_parent_copy(c or start_s) + reset.execution = None + reset.next = None + return call, index, True + command = command.next # The third return is just necessary for recursion inside, because # it needs to know when to stop iterating. + return None, 0, True # TODO remove return call, check_arr_index(arr, pos), stop