def check_user_stmt(user_stmt): if user_stmt is None \ or not isinstance(user_stmt, parsing.Statement): return None, 0 ass = helpers.fast_parent_copy(user_stmt.get_assignment_calls()) call, index, stop = helpers.scan_array_for_pos(ass, self.pos) return call, index
def get_in_function_call(self): """ Return the function, that the cursor is in, e.g.: >>> isinstance(| # | <-- cursor is here This would return the `isinstance` function. In contrary: >>> isinstance()| # | <-- cursor is here This would return `None`. """ def scan_array_for_pos(arr, pos): """ Returns the function Call that match search_name in an Array. """ index = 0 call = None stop = False for index, sub in enumerate(arr.values): call = None for s in sub: if isinstance(s, parsing.Array): new = scan_array_for_pos(s, pos) if new[0] is not None: call, index, stop = new if stop: return call, index, stop elif isinstance(s, parsing.Call): start_s = s while s is not None: if s.start_pos >= pos: return call, index, stop elif s.execution is not None: end = s.execution.end_pos if s.execution.start_pos < pos and \ (end is None or pos < end): c, index, stop = scan_array_for_pos( s.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 \ [parsing.Array.TUPLE, parsing.Array.NOARRAY]: return start_s, index, False reset.execution = None reset.next = None return c or start_s, index, True s = s.next # The third return is just necessary for recursion inside, because # it needs to know when to stop iterating. return call, index, stop user_stmt = self.parser.user_stmt if user_stmt is None or not isinstance(user_stmt, parsing.Statement): return None ass = helpers.fast_parent_copy(user_stmt.get_assignment_calls()) call, index, stop = scan_array_for_pos(ass, self.pos) if call is None: return None origins = evaluate.follow_call(call) if len(origins) == 0: return None # just take entry zero, because we need just one. executable = origins[0] after = self.module.get_line(self.pos[0])[self.pos[1]:] index -= re.search('^[ ,]*', after).group(0).count(',') return CallDef(executable, index, call)