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