forked from VimPlug/jedi
cleaned up prepare_goto, for the goto functions, which is coming
This commit is contained in:
54
functions.py
54
functions.py
@@ -138,21 +138,18 @@ def complete(source, line, column, source_path):
|
|||||||
:return: list of Completion objects.
|
:return: list of Completion objects.
|
||||||
:rtype: list
|
:rtype: list
|
||||||
"""
|
"""
|
||||||
|
pos = (line, column)
|
||||||
|
f = modules.ModuleWithCursor(source_path, source=source, position=pos)
|
||||||
|
path = f.get_path_until_cursor()
|
||||||
|
path, dot, like = get_completion_parts(path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
scopes, path, dot, like = prepare_goto(source, (line, column),
|
scopes = prepare_goto(source, pos, source_path, f, path, True)
|
||||||
source_path, True)
|
|
||||||
except NotFoundError:
|
except NotFoundError:
|
||||||
# normally this would be used like this: `NotFoundError as exc`, but
|
scope_generator = evaluate.get_names_for_scope(f.parser.user_scope)
|
||||||
# this guarantues backwards compatibility with Python2.5.
|
|
||||||
exc = sys.exc_info()[1]
|
|
||||||
path, dot, like = exc.path_tuple
|
|
||||||
scope_generator = evaluate.get_names_for_scope(exc.scope)
|
|
||||||
completions = []
|
completions = []
|
||||||
for dummy, name_list in scope_generator:
|
for dummy, name_list in scope_generator:
|
||||||
completions += name_list
|
completions += name_list
|
||||||
#for c in completions:
|
|
||||||
# if isinstance(, parsing.Function):
|
|
||||||
# print c.parent
|
|
||||||
else:
|
else:
|
||||||
completions = []
|
completions = []
|
||||||
debug.dbg('possible scopes', scopes)
|
debug.dbg('possible scopes', scopes)
|
||||||
@@ -171,41 +168,26 @@ def complete(source, line, 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, position, source_path, is_like_search):
|
def prepare_goto(source, position, source_path, module, goto_path,
|
||||||
f = modules.ModuleWithCursor(source_path, source=source, position=position)
|
is_like_search=False):
|
||||||
scope = f.parser.user_scope
|
scope = module.parser.user_scope
|
||||||
|
debug.dbg('start: %s in %s' % (goto_path, scope))
|
||||||
|
|
||||||
if is_like_search:
|
user_stmt = module.parser.user_stmt
|
||||||
path = f.get_path_until_cursor()
|
|
||||||
path, dot, like = get_completion_parts(path)
|
|
||||||
else:
|
|
||||||
path = f.get_path_under_cursor()
|
|
||||||
|
|
||||||
debug.dbg('start: %s in %s' % (path, scope))
|
|
||||||
|
|
||||||
user_stmt = f.parser.user_stmt
|
|
||||||
if isinstance(user_stmt, parsing.Import):
|
if isinstance(user_stmt, parsing.Import):
|
||||||
scopes = [imports.ImportPath(user_stmt, is_like_search)]
|
scopes = [imports.ImportPath(user_stmt, is_like_search)]
|
||||||
else:
|
else:
|
||||||
# just parse one statement, take it and evaluate it
|
# just parse one statement, take it and evaluate it
|
||||||
r = parsing.PyFuzzyParser(path, source_path)
|
r = parsing.PyFuzzyParser(goto_path, source_path)
|
||||||
try:
|
try:
|
||||||
stmt = r.top.statements[0]
|
stmt = r.top.statements[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
if is_like_search:
|
raise NotFoundError(scope, goto_path)
|
||||||
path_tuple = path, dot, like
|
|
||||||
else:
|
|
||||||
path_tuple = ()
|
|
||||||
raise NotFoundError(scope, path_tuple)
|
|
||||||
else:
|
else:
|
||||||
stmt.start_pos = position
|
stmt.start_pos = position
|
||||||
stmt.parent = scope
|
stmt.parent = scope
|
||||||
scopes = evaluate.follow_statement(stmt)
|
scopes = evaluate.follow_statement(stmt)
|
||||||
|
return scopes
|
||||||
if is_like_search:
|
|
||||||
return scopes, path, dot, like
|
|
||||||
else:
|
|
||||||
return scopes
|
|
||||||
|
|
||||||
|
|
||||||
def get_definitions(source, line, column, source_path):
|
def get_definitions(source, line, column, source_path):
|
||||||
@@ -226,7 +208,11 @@ def get_definitions(source, line, 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, (line, column), source_path, False)
|
pos = (line, column)
|
||||||
|
f = modules.ModuleWithCursor(source_path, source=source, position=pos)
|
||||||
|
goto_path = f.get_path_under_cursor()
|
||||||
|
|
||||||
|
scopes = prepare_goto(source, pos, source_path, f, goto_path)
|
||||||
_clear_caches()
|
_clear_caches()
|
||||||
return [Definition(s) for s in set(scopes)]
|
return [Definition(s) for s in set(scopes)]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user