mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
interface changes from row/colum to position
This commit is contained in:
17
functions.py
17
functions.py
@@ -138,7 +138,7 @@ def complete(source, row, column, source_path):
|
|||||||
:rtype: list
|
:rtype: list
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
scopes, path, dot, like = prepare_goto(source, row, column,
|
scopes, path, dot, like = prepare_goto(source, (row, column),
|
||||||
source_path, True)
|
source_path, True)
|
||||||
except NotFoundError:
|
except NotFoundError:
|
||||||
# normally this would be used like this: `NotFoundError as exc`, but
|
# 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)]
|
return [Completion(c, needs_dot, len(like)) for c in set(completions)]
|
||||||
|
|
||||||
|
|
||||||
def prepare_goto(source, row, column, source_path, is_like_search):
|
def prepare_goto(source, position, source_path, is_like_search):
|
||||||
f = modules.ModuleWithCursor(source_path, source=source, row=row)
|
f = modules.ModuleWithCursor(source_path, source=source, position=position)
|
||||||
scope = f.parser.user_scope
|
scope = f.parser.user_scope
|
||||||
|
print scope
|
||||||
|
|
||||||
if is_like_search:
|
if is_like_search:
|
||||||
path = f.get_path_until_cursor(column)
|
path = f.get_path_until_cursor()
|
||||||
path, dot, like = get_completion_parts(path)
|
path, dot, like = get_completion_parts(path)
|
||||||
else:
|
else:
|
||||||
path = f.get_path_under_cursor(column)
|
path = f.get_path_under_cursor()
|
||||||
|
|
||||||
debug.dbg('start: %s in %s' % (path, scope))
|
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 = ()
|
path_tuple = ()
|
||||||
raise NotFoundError(scope, path_tuple)
|
raise NotFoundError(scope, path_tuple)
|
||||||
else:
|
else:
|
||||||
stmt.line_nr = row
|
stmt.line_nr = position[0]
|
||||||
stmt.indent = column
|
stmt.indent = position[1]
|
||||||
stmt.parent = scope
|
stmt.parent = scope
|
||||||
scopes = evaluate.follow_statement(stmt)
|
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.
|
:return: list of Definition objects, which are basically scopes.
|
||||||
:rtype: list
|
:rtype: list
|
||||||
"""
|
"""
|
||||||
scopes = prepare_goto(source, row, column, source_path, False)
|
scopes = prepare_goto(source, (row, column), source_path, False)
|
||||||
_clear_caches()
|
_clear_caches()
|
||||||
return [Definition(s) for s in set(scopes)]
|
return [Definition(s) for s in set(scopes)]
|
||||||
|
|
||||||
|
|||||||
20
modules.py
20
modules.py
@@ -53,9 +53,9 @@ class ModuleWithCursor(Module):
|
|||||||
:param row: The row, the user is currently in. Only important for the \
|
:param row: The row, the user is currently in. Only important for the \
|
||||||
main file.
|
main file.
|
||||||
"""
|
"""
|
||||||
def __init__(self, path, source, row):
|
def __init__(self, path, source, position):
|
||||||
super(ModuleWithCursor, self).__init__(path, source)
|
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
|
# this two are only used, because there is no nonlocal in Python 2
|
||||||
self._row_temp = None
|
self._row_temp = None
|
||||||
@@ -64,9 +64,9 @@ class ModuleWithCursor(Module):
|
|||||||
# Call the parser already here, because it will be used anyways.
|
# Call the parser already here, because it will be used anyways.
|
||||||
# Also, the position is here important (which will not be used by
|
# Also, the position is here important (which will not be used by
|
||||||
# default), therefore fill the cache here.
|
# 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. """
|
""" Get the path under the cursor. """
|
||||||
self._is_first = True
|
self._is_first = True
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ class ModuleWithCursor(Module):
|
|||||||
line = self.get_line(self._row_temp)
|
line = self.get_line(self._row_temp)
|
||||||
if self._is_first:
|
if self._is_first:
|
||||||
self._is_first = False
|
self._is_first = False
|
||||||
line = line[:column]
|
line = line[:self.position[1]]
|
||||||
else:
|
else:
|
||||||
line = line + '\n'
|
line = line + '\n'
|
||||||
# add lines with a backslash at the end
|
# add lines with a backslash at the end
|
||||||
@@ -87,7 +87,7 @@ class ModuleWithCursor(Module):
|
|||||||
break
|
break
|
||||||
return line[::-1]
|
return line[::-1]
|
||||||
|
|
||||||
self._row_temp = self.row
|
self._row_temp = self.position[0]
|
||||||
|
|
||||||
force_point = False
|
force_point = False
|
||||||
open_brackets = ['(', '[', '{']
|
open_brackets = ['(', '[', '{']
|
||||||
@@ -127,14 +127,14 @@ class ModuleWithCursor(Module):
|
|||||||
|
|
||||||
return string[::-1]
|
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,
|
Return the path under the cursor. If there is a rest of the path left,
|
||||||
it will be added to the stuff before it.
|
it will be added to the stuff before it.
|
||||||
"""
|
"""
|
||||||
line = self.get_line(self.row)
|
line = self.get_line(self.position[0])
|
||||||
after = re.search("[\w\d]*", line[column:]).group(0)
|
after = re.search("[\w\d]*", line[self.position[1]:]).group(0)
|
||||||
return self.get_path_until_cursor(column) + after
|
return self.get_path_until_cursor() + after
|
||||||
|
|
||||||
def get_line(self, line):
|
def get_line(self, line):
|
||||||
if not self._line_cache:
|
if not self._line_cache:
|
||||||
|
|||||||
10
parsing.py
10
parsing.py
@@ -937,11 +937,11 @@ class PyFuzzyParser(object):
|
|||||||
|
|
||||||
:param code: The codebase for the parser.
|
:param code: The codebase for the parser.
|
||||||
:type code: str
|
:type code: str
|
||||||
:param user_line: The line, the user is currently on.
|
:param user_position: The line/column, the user is currently on.
|
||||||
:type user_line: int
|
:type user_position: tuple(line, column)
|
||||||
"""
|
"""
|
||||||
def __init__(self, code, module_path=None, user_line=None):
|
def __init__(self, code, module_path=None, user_position=(None,None)):
|
||||||
self.user_line = user_line
|
self.user_position = user_position
|
||||||
self.code = code + '\n' # end with \n, because the parser needs it
|
self.code = code + '\n' # end with \n, because the parser needs it
|
||||||
|
|
||||||
# initialize global Scope
|
# initialize global Scope
|
||||||
@@ -1252,7 +1252,7 @@ class PyFuzzyParser(object):
|
|||||||
""" Generate the next tokenize pattern. """
|
""" Generate the next tokenize pattern. """
|
||||||
type, tok, position, dummy, self.parserline = next(self.gen)
|
type, tok, position, dummy, self.parserline = next(self.gen)
|
||||||
(self._tokenize_line_nr, indent) = position
|
(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' % \
|
debug.dbg('user scope found [%s] =%s' % \
|
||||||
(self.parserline.replace('\n', ''), repr(self.scope)))
|
(self.parserline.replace('\n', ''), repr(self.scope)))
|
||||||
self.user_scope = self.scope
|
self.user_scope = self.scope
|
||||||
|
|||||||
Reference in New Issue
Block a user