mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 18:17:07 +08:00
rename working again with different goto function. now change the goto function itself
This commit is contained in:
40
jedi/api.py
40
jedi/api.py
@@ -227,8 +227,7 @@ class Script(object):
|
|||||||
return c
|
return c
|
||||||
|
|
||||||
def _prepare_goto(self, goto_path, is_like_search=False):
|
def _prepare_goto(self, goto_path, is_like_search=False):
|
||||||
scope = self.parser.user_scope
|
debug.dbg('start: %s in %s' % (goto_path, self.parser.scope))
|
||||||
debug.dbg('start: %s in %s' % (goto_path, scope))
|
|
||||||
|
|
||||||
user_stmt = self.parser.user_stmt
|
user_stmt = self.parser.user_stmt
|
||||||
if not user_stmt and len(goto_path.split('\n')) > 1:
|
if not user_stmt and len(goto_path.split('\n')) > 1:
|
||||||
@@ -250,18 +249,20 @@ class Script(object):
|
|||||||
kill_count=kill_count, direct_resolve=True)]
|
kill_count=kill_count, direct_resolve=True)]
|
||||||
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, self.source_path,
|
stmt = self._get_under_cursor_stmt(goto_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)
|
scopes = evaluate.follow_statement(stmt)
|
||||||
return scopes
|
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(self.parser.user_scope)
|
||||||
|
return stmt
|
||||||
|
|
||||||
def get_definition(self):
|
def get_definition(self):
|
||||||
"""
|
"""
|
||||||
Returns the definitions of a the path under the cursor. This is
|
Returns the definitions of a the path under the cursor. This is
|
||||||
@@ -346,13 +347,22 @@ class Script(object):
|
|||||||
#(parsing.Param, parsing.Import)):
|
#(parsing.Param, parsing.Import)):
|
||||||
#definitions = [self.module.parser.user_stmt]
|
#definitions = [self.module.parser.user_stmt]
|
||||||
else:
|
else:
|
||||||
evaluate.goto_names = []
|
goto_path = self.module.get_path_under_cursor()
|
||||||
scopes = self._prepare_goto(goto_path)
|
stmt = self._get_under_cursor_stmt(goto_path)
|
||||||
definitions = evaluate.goto2(scopes, search_name_new)
|
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 = set([d.get_parent_until() for d in definitions])
|
||||||
module.add(self.module.parser.module)
|
module.add(self.module.parser.module)
|
||||||
names = dynamic.related_names(definitions, search_name, module)
|
if definitions:
|
||||||
|
names = dynamic.related_names(definitions, search_name, module)
|
||||||
|
else:
|
||||||
|
names = []
|
||||||
|
|
||||||
for d in definitions:
|
for d in definitions:
|
||||||
if isinstance(d, parsing.Statement):
|
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_res = evaluate.goto(scopes, search, statement_path_offset=0,
|
||||||
# follow_import=True)
|
# follow_import=True)
|
||||||
#follow_res = evaluate.goto2(scopes, search)
|
#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
|
# compare to see if they match
|
||||||
if True in [r in definitions for r in follow_res]:
|
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)
|
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()
|
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]
|
call_path, search = call_path[:-1], call_path[-1]
|
||||||
if call_path:
|
if call_path:
|
||||||
scopes = follow_call_path(iter(call_path), scope, position)
|
scopes = follow_call_path(iter(call_path), scope, pos)
|
||||||
search_global = False
|
search_global = False
|
||||||
pos = None
|
pos = None
|
||||||
else:
|
else:
|
||||||
scopes = [scope]
|
scopes = [scope]
|
||||||
pos = search.start_pos
|
|
||||||
search_global = True
|
search_global = True
|
||||||
follow_res = []
|
follow_res = []
|
||||||
for s in scopes:
|
for s in scopes:
|
||||||
follow_res += get_scopes_for_name(s, search, pos,
|
follow_res += get_scopes_for_name(s, search, pos,
|
||||||
search_global=search_global, is_goto=True)
|
search_global=search_global, is_goto=True)
|
||||||
print 'c', call, scope, follow_res
|
#print 'c', call, scope, follow_res
|
||||||
return follow_res, search
|
return follow_res, search
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
""" used for renaming tests """
|
""" used for renaming tests """
|
||||||
|
|
||||||
|
|
||||||
from rename1 import abc
|
from rename1 import abc
|
||||||
|
|
||||||
abc
|
abc
|
||||||
|
|||||||
@@ -67,12 +67,12 @@ import colorama
|
|||||||
#< (65,7) (68,0)
|
#< (65,7) (68,0)
|
||||||
colorama
|
colorama
|
||||||
|
|
||||||
#< 3
|
|
||||||
import abc
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from import_tree import rename1
|
from import_tree import rename1
|
||||||
|
|
||||||
##< (78,8) (3,0)
|
#< (78,8) (3,0) (4,20) (6,0)
|
||||||
rename1.abc
|
rename1.abc
|
||||||
|
|||||||
Reference in New Issue
Block a user