mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
goto follows now also import statements
This commit is contained in:
11
functions.py
11
functions.py
@@ -180,7 +180,7 @@ def prepare_goto(source, position, source_path, module, goto_path,
|
|||||||
|
|
||||||
user_stmt = module.parser.user_stmt
|
user_stmt = module.parser.user_stmt
|
||||||
if isinstance(user_stmt, parsing.Import):
|
if isinstance(user_stmt, parsing.Import):
|
||||||
scopes = [imports.ImportPath2(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(goto_path, source_path)
|
r = parsing.PyFuzzyParser(goto_path, source_path)
|
||||||
@@ -239,13 +239,18 @@ def goto(source, line, column, source_path):
|
|||||||
try:
|
try:
|
||||||
definitions = [evaluate.statement_path[1]]
|
definitions = [evaluate.statement_path[1]]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
definitions = scopes
|
definitions = []
|
||||||
|
for s in scopes:
|
||||||
|
if isinstance(s, imports.ImportPath):
|
||||||
|
definitions += s.follow()
|
||||||
|
else:
|
||||||
|
definitions.append(s)
|
||||||
else:
|
else:
|
||||||
names = []
|
names = []
|
||||||
#print 's', scopes
|
#print 's', scopes
|
||||||
for s in scopes:
|
for s in scopes:
|
||||||
names += s.get_defined_names()
|
names += s.get_defined_names()
|
||||||
definitions = [n.parent for n in names if n.names[-1] == search_name]
|
definitions = [n for n in names if n.names[-1] == search_name]
|
||||||
#print evaluate.statement_path
|
#print evaluate.statement_path
|
||||||
#print scopes, definitions
|
#print scopes, definitions
|
||||||
_clear_caches()
|
_clear_caches()
|
||||||
|
|||||||
@@ -132,7 +132,6 @@ class ImportPath(object):
|
|||||||
f = builtin.Parser(name=path)
|
f = builtin.Parser(name=path)
|
||||||
|
|
||||||
return f.parser.top, rest
|
return f.parser.top, rest
|
||||||
ImportPath2 = ImportPath
|
|
||||||
|
|
||||||
|
|
||||||
def strip_imports(scopes):
|
def strip_imports(scopes):
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ class Module(Scope):
|
|||||||
The top scope, which is always a module.
|
The top scope, which is always a module.
|
||||||
"""
|
"""
|
||||||
def __init__(self, path, docstr=''):
|
def __init__(self, path, docstr=''):
|
||||||
super(Module, self).__init__((0, 0), docstr)
|
super(Module, self).__init__((1, 0), docstr)
|
||||||
self.path = path
|
self.path = path
|
||||||
self.global_vars = []
|
self.global_vars = []
|
||||||
|
|
||||||
@@ -1253,6 +1253,7 @@ class PyFuzzyParser(object):
|
|||||||
else:
|
else:
|
||||||
stmt = stmt_class(string, set_vars, used_funcs, used_vars, \
|
stmt = stmt_class(string, set_vars, used_funcs, used_vars, \
|
||||||
tok_list, first_pos, self.end_pos)
|
tok_list, first_pos, self.end_pos)
|
||||||
|
self.check_user_stmt(stmt)
|
||||||
if is_return:
|
if is_return:
|
||||||
# add returns to the scope
|
# add returns to the scope
|
||||||
func = self.scope.get_parent_until(Function)
|
func = self.scope.get_parent_until(Function)
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ function! jedi#complete(findstart, base)
|
|||||||
python << PYTHONEOF
|
python << PYTHONEOF
|
||||||
if 1:
|
if 1:
|
||||||
row, column = vim.current.window.cursor
|
row, column = vim.current.window.cursor
|
||||||
print
|
|
||||||
if vim.eval('a:findstart') == '1':
|
if vim.eval('a:findstart') == '1':
|
||||||
count = 0
|
count = 0
|
||||||
for char in reversed(vim.current.line[:column]):
|
for char in reversed(vim.current.line[:column]):
|
||||||
|
|||||||
@@ -113,10 +113,15 @@ def run_goto_test(correct, source, line_nr, line, path):
|
|||||||
r = r.definition
|
r = r.definition
|
||||||
if isinstance(r, evaluate.InstanceElement):
|
if isinstance(r, evaluate.InstanceElement):
|
||||||
r = r.var
|
r = r.var
|
||||||
|
if isinstance(r, evaluate.parsing.Name):
|
||||||
|
r = r.parent
|
||||||
|
|
||||||
if isinstance(r, (evaluate.Class, evaluate.Instance)):
|
if isinstance(r, (evaluate.Class, evaluate.Instance)):
|
||||||
r = 'class ' + str(r.name)
|
r = 'class ' + str(r.name)
|
||||||
elif isinstance(r, (evaluate.Function, evaluate.parsing.Function)):
|
elif isinstance(r, (evaluate.Function, evaluate.parsing.Function)):
|
||||||
r = 'def ' + str(r.name)
|
r = 'def ' + str(r.name)
|
||||||
|
elif isinstance(r, evaluate.parsing.Module):
|
||||||
|
r = 'module ' + str(r.path)
|
||||||
else:
|
else:
|
||||||
r = r.get_code().replace('\n', '')
|
r = r.get_code().replace('\n', '')
|
||||||
lst.append(r)
|
lst.append(r)
|
||||||
@@ -124,7 +129,6 @@ def run_goto_test(correct, source, line_nr, line, path):
|
|||||||
if comp_str != correct:
|
if comp_str != correct:
|
||||||
print('Solution @%s not right, received %s, wanted %s'\
|
print('Solution @%s not right, received %s, wanted %s'\
|
||||||
% (line_nr - 1, comp_str, correct))
|
% (line_nr - 1, comp_str, correct))
|
||||||
print result
|
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user