forked from VimPlug/jedi
rename working again with different goto function. now change the goto function itself
This commit is contained in:
32
jedi/api.py
32
jedi/api.py
@@ -227,8 +227,7 @@ class Script(object):
|
||||
return c
|
||||
|
||||
def _prepare_goto(self, goto_path, is_like_search=False):
|
||||
scope = self.parser.user_scope
|
||||
debug.dbg('start: %s in %s' % (goto_path, scope))
|
||||
debug.dbg('start: %s in %s' % (goto_path, self.parser.scope))
|
||||
|
||||
user_stmt = self.parser.user_stmt
|
||||
if not user_stmt and len(goto_path.split('\n')) > 1:
|
||||
@@ -250,17 +249,19 @@ class Script(object):
|
||||
kill_count=kill_count, direct_resolve=True)]
|
||||
else:
|
||||
# just parse one statement, take it and evaluate it
|
||||
r = parsing.PyFuzzyParser(goto_path, self.source_path,
|
||||
no_docstr=True)
|
||||
stmt = self._get_under_cursor_stmt(goto_path)
|
||||
scopes = evaluate.follow_statement(stmt)
|
||||
return scopes
|
||||
|
||||
def _get_under_cursor_stmt(self, cursor_txt):
|
||||
r = parsing.PyFuzzyParser(cursor_txt, self.source_path, no_docstr=True)
|
||||
try:
|
||||
stmt = r.module.statements[0]
|
||||
except IndexError:
|
||||
raise NotFoundError()
|
||||
|
||||
stmt.start_pos = self.pos
|
||||
stmt.parent = weakref.ref(scope)
|
||||
scopes = evaluate.follow_statement(stmt)
|
||||
return scopes
|
||||
stmt.parent = weakref.ref(self.parser.user_scope)
|
||||
return stmt
|
||||
|
||||
def get_definition(self):
|
||||
"""
|
||||
@@ -346,13 +347,22 @@ class Script(object):
|
||||
#(parsing.Param, parsing.Import)):
|
||||
#definitions = [self.module.parser.user_stmt]
|
||||
else:
|
||||
evaluate.goto_names = []
|
||||
scopes = self._prepare_goto(goto_path)
|
||||
definitions = evaluate.goto2(scopes, search_name_new)
|
||||
goto_path = self.module.get_path_under_cursor()
|
||||
stmt = self._get_under_cursor_stmt(goto_path)
|
||||
arr = stmt.get_assignment_calls()
|
||||
call = arr.get_only_subelement()
|
||||
definitions, search_name = evaluate.goto3(call)
|
||||
#print 'd', definitions, call, call.parent_stmt().parent().start_pos
|
||||
#evaluate.goto_names = []
|
||||
#scopes = self._prepare_goto(goto_path)
|
||||
#definitions = evaluate.goto2(scopes, search_name_new)
|
||||
|
||||
module = set([d.get_parent_until() for d in definitions])
|
||||
module.add(self.module.parser.module)
|
||||
if definitions:
|
||||
names = dynamic.related_names(definitions, search_name, module)
|
||||
else:
|
||||
names = []
|
||||
|
||||
for d in definitions:
|
||||
if isinstance(d, parsing.Statement):
|
||||
|
||||
@@ -350,7 +350,7 @@ def related_names(definitions, search_name, mods):
|
||||
#follow_res = evaluate.goto(scopes, search, statement_path_offset=0,
|
||||
# follow_import=True)
|
||||
#follow_res = evaluate.goto2(scopes, search)
|
||||
follow_res, search = evaluate.goto3(f, call)
|
||||
follow_res, search = evaluate.goto3(call, f)
|
||||
|
||||
# compare to see if they match
|
||||
if True in [r in definitions for r in follow_res]:
|
||||
|
||||
@@ -1513,23 +1513,24 @@ def follow_path(path, scope, position=None):
|
||||
return follow_paths(path, set(result), position=position)
|
||||
|
||||
|
||||
def goto3(call_path, call):
|
||||
def goto3(call, call_path=None):
|
||||
if call_path is None:
|
||||
call_path = list(call.generate_call_path())
|
||||
scope = call.parent_stmt().parent()
|
||||
position = call.parent_stmt().start_pos
|
||||
pos = call.parent_stmt().start_pos
|
||||
call_path, search = call_path[:-1], call_path[-1]
|
||||
if call_path:
|
||||
scopes = follow_call_path(iter(call_path), scope, position)
|
||||
scopes = follow_call_path(iter(call_path), scope, pos)
|
||||
search_global = False
|
||||
pos = None
|
||||
else:
|
||||
scopes = [scope]
|
||||
pos = search.start_pos
|
||||
search_global = True
|
||||
follow_res = []
|
||||
for s in scopes:
|
||||
follow_res += get_scopes_for_name(s, search, pos,
|
||||
search_global=search_global, is_goto=True)
|
||||
print 'c', call, scope, follow_res
|
||||
#print 'c', call, scope, follow_res
|
||||
return follow_res, search
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
""" used for renaming tests """
|
||||
|
||||
|
||||
from rename1 import abc
|
||||
|
||||
abc
|
||||
|
||||
@@ -67,12 +67,12 @@ import colorama
|
||||
#< (65,7) (68,0)
|
||||
colorama
|
||||
|
||||
#< 3
|
||||
import abc
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
from import_tree import rename1
|
||||
|
||||
##< (78,8) (3,0)
|
||||
#< (78,8) (3,0) (4,20) (6,0)
|
||||
rename1.abc
|
||||
|
||||
Reference in New Issue
Block a user