diff --git a/functions.py b/functions.py index 484010fb..5c992ece 100644 --- a/functions.py +++ b/functions.py @@ -138,7 +138,7 @@ def complete(source, row, column, source_path): :rtype: list """ try: - scopes, path, dot, like = prepare_goto(source, row, column, + scopes, path, dot, like = prepare_goto(source, (row, column), source_path, True) except NotFoundError: # normally this would be used like this: `NotFoundError as exc`, but @@ -171,15 +171,16 @@ def complete(source, row, column, source_path): return [Completion(c, needs_dot, len(like)) for c in set(completions)] -def prepare_goto(source, row, column, source_path, is_like_search): - f = modules.ModuleWithCursor(source_path, source=source, row=row) +def prepare_goto(source, position, source_path, is_like_search): + f = modules.ModuleWithCursor(source_path, source=source, position=position) scope = f.parser.user_scope + print scope if is_like_search: - path = f.get_path_until_cursor(column) + path = f.get_path_until_cursor() path, dot, like = get_completion_parts(path) else: - path = f.get_path_under_cursor(column) + path = f.get_path_under_cursor() debug.dbg('start: %s in %s' % (path, scope)) @@ -194,8 +195,8 @@ def prepare_goto(source, row, column, source_path, is_like_search): path_tuple = () raise NotFoundError(scope, path_tuple) else: - stmt.line_nr = row - stmt.indent = column + stmt.line_nr = position[0] + stmt.indent = position[1] stmt.parent = scope scopes = evaluate.follow_statement(stmt) @@ -223,7 +224,7 @@ def get_definitions(source, row, column, source_path): :return: list of Definition objects, which are basically scopes. :rtype: list """ - scopes = prepare_goto(source, row, column, source_path, False) + scopes = prepare_goto(source, (row, column), source_path, False) _clear_caches() return [Definition(s) for s in set(scopes)] diff --git a/modules.py b/modules.py index 57258d28..a52e1477 100644 --- a/modules.py +++ b/modules.py @@ -53,9 +53,9 @@ class ModuleWithCursor(Module): :param row: The row, the user is currently in. Only important for the \ main file. """ - def __init__(self, path, source, row): + def __init__(self, path, source, position): super(ModuleWithCursor, self).__init__(path, source) - self.row = row + self.position = position # this two are only used, because there is no nonlocal in Python 2 self._row_temp = None @@ -64,9 +64,9 @@ class ModuleWithCursor(Module): # Call the parser already here, because it will be used anyways. # Also, the position is here important (which will not be used by # default), therefore fill the cache here. - self._parser = parsing.PyFuzzyParser(source, path, row) + self._parser = parsing.PyFuzzyParser(source, path, position) - def get_path_until_cursor(self, column): + def get_path_until_cursor(self): """ Get the path under the cursor. """ self._is_first = True @@ -74,7 +74,7 @@ class ModuleWithCursor(Module): line = self.get_line(self._row_temp) if self._is_first: self._is_first = False - line = line[:column] + line = line[:self.position[1]] else: line = line + '\n' # add lines with a backslash at the end @@ -87,7 +87,7 @@ class ModuleWithCursor(Module): break return line[::-1] - self._row_temp = self.row + self._row_temp = self.position[0] force_point = False open_brackets = ['(', '[', '{'] @@ -127,14 +127,14 @@ class ModuleWithCursor(Module): return string[::-1] - def get_path_under_cursor(self, column): + def get_path_under_cursor(self): """ Return the path under the cursor. If there is a rest of the path left, it will be added to the stuff before it. """ - line = self.get_line(self.row) - after = re.search("[\w\d]*", line[column:]).group(0) - return self.get_path_until_cursor(column) + after + line = self.get_line(self.position[0]) + after = re.search("[\w\d]*", line[self.position[1]:]).group(0) + return self.get_path_until_cursor() + after def get_line(self, line): if not self._line_cache: diff --git a/parsing.py b/parsing.py index 62c40971..2382834e 100644 --- a/parsing.py +++ b/parsing.py @@ -937,11 +937,11 @@ class PyFuzzyParser(object): :param code: The codebase for the parser. :type code: str - :param user_line: The line, the user is currently on. - :type user_line: int + :param user_position: The line/column, the user is currently on. + :type user_position: tuple(line, column) """ - def __init__(self, code, module_path=None, user_line=None): - self.user_line = user_line + def __init__(self, code, module_path=None, user_position=(None,None)): + self.user_position = user_position self.code = code + '\n' # end with \n, because the parser needs it # initialize global Scope @@ -1252,7 +1252,7 @@ class PyFuzzyParser(object): """ Generate the next tokenize pattern. """ type, tok, position, dummy, self.parserline = next(self.gen) (self._tokenize_line_nr, indent) = position - if self.line_nr == self.user_line: + if self.line_nr == self.user_position[0]: debug.dbg('user scope found [%s] =%s' % \ (self.parserline.replace('\n', ''), repr(self.scope))) self.user_scope = self.scope