mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
get_related_names testing
This commit is contained in:
@@ -324,12 +324,16 @@ def get_related_names(definitions, search_name, modules):
|
||||
names = []
|
||||
for d in definitions:
|
||||
if isinstance(d, parsing.Statement):
|
||||
for op, arr in d.assignment_details:
|
||||
def add_array(arr):
|
||||
calls = _scan_array(arr, search_name)
|
||||
for call in calls:
|
||||
for n in call.name.names:
|
||||
if n == search_name:
|
||||
names.append(RelatedName(n, d.parent()))
|
||||
for op, arr in d.assignment_details:
|
||||
add_array(arr)
|
||||
if not d.assignment_details:
|
||||
add_array(d.get_assignment_calls())
|
||||
else:
|
||||
names.append(RelatedName(d.name.names[0], d))
|
||||
|
||||
|
||||
@@ -987,6 +987,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
||||
and r.position_nr > 0: # 0 would be self
|
||||
r = func.var.params[r.position_nr]
|
||||
if not r.is_generated:
|
||||
statement_path.append(r)
|
||||
res_new += dynamic.search_params(r)
|
||||
if not r.assignment_details:
|
||||
# this means that there are no default params,
|
||||
@@ -1052,6 +1053,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
||||
# place, if the var_args are clear. But sometimes the class is
|
||||
# not known. Therefore add a new instance for self. Otherwise
|
||||
# take the existing.
|
||||
statement_path.append(par)
|
||||
if isinstance(scope, InstanceElement):
|
||||
inst = scope.instance
|
||||
else:
|
||||
|
||||
24
functions.py
24
functions.py
@@ -278,8 +278,13 @@ def goto(source, line, column, source_path):
|
||||
else:
|
||||
search_name_new = search_name
|
||||
|
||||
scopes = _prepare_goto(source, pos, source_path, f, goto_path)
|
||||
definitions = evaluate.goto(scopes, search_name_new)
|
||||
context = f.get_context()
|
||||
if next(context) in ('class', 'def'):
|
||||
definitions = set([f.parser.user_scope])
|
||||
else:
|
||||
scopes = _prepare_goto(source, pos, source_path, f, goto_path)
|
||||
definitions = evaluate.goto(scopes, search_name_new)
|
||||
|
||||
d = [Definition(d) for d in set(definitions)]
|
||||
_clear_caches()
|
||||
return d
|
||||
@@ -299,8 +304,19 @@ def get_related_names(source, line, column, source_path):
|
||||
else:
|
||||
search_name_new = search_name
|
||||
|
||||
scopes = _prepare_goto(source, pos, source_path, f, goto_path)
|
||||
definitions = evaluate.goto(scopes, search_name_new)
|
||||
context = f.get_context()
|
||||
if next(context) in ('class', 'def'):
|
||||
if isinstance(f.parser.user_scope, parsing.Function):
|
||||
e = evaluate.Function(f.parser.user_scope)
|
||||
else:
|
||||
e = evaluate.Class(f.parser.user_scope)
|
||||
definitions = [e]
|
||||
elif isinstance(f.parser.user_stmt, parsing.Param):
|
||||
definitions = [f.parser.user_stmt]
|
||||
else:
|
||||
scopes = _prepare_goto(source, pos, source_path, f, goto_path)
|
||||
definitions = evaluate.goto(scopes, search_name_new)
|
||||
|
||||
module = set([d.get_parent_until() for d in definitions])
|
||||
module.add(f.parser.module)
|
||||
names = dynamic.get_related_names(definitions, search_name, module)
|
||||
|
||||
@@ -1093,7 +1093,7 @@ class PyFuzzyParser(object):
|
||||
if not self.user_position:
|
||||
return
|
||||
# the position is right
|
||||
if simple.start_pos < self.user_position <= simple.end_pos:
|
||||
if simple.start_pos <= self.user_position <= simple.end_pos:
|
||||
if self.user_stmt is not None:
|
||||
# if there is already a user position (another import, because
|
||||
# imports are splitted) the names are checked.
|
||||
|
||||
@@ -3,10 +3,10 @@ Renaming tests. This means search for related names.
|
||||
I always leave a little bit of space to add room for additions, because the
|
||||
results always contain position informations.
|
||||
"""
|
||||
|
||||
#< 4 (7,4) (10,0) (12,0)
|
||||
def abc(): pass
|
||||
|
||||
#< 0 abc@7,4 abc@10,0 abc@12,0
|
||||
#< 0 (7,4) (10,0) (12,0)
|
||||
abc.d.a.abc.d
|
||||
|
||||
abc
|
||||
@@ -19,5 +19,42 @@ abc
|
||||
|
||||
abc =
|
||||
|
||||
#< abc@20,0 abc@23,0
|
||||
#< (20,0) (23,0)
|
||||
abc
|
||||
|
||||
|
||||
|
||||
Abc = 3
|
||||
|
||||
#< 6 (30,6) (32,4) (35,8) (47,0)
|
||||
class Abc():
|
||||
#< (30,6) (32,4) (35,8) (47,0)
|
||||
Abc
|
||||
|
||||
def Abc(self):
|
||||
Abc; self.c = 3
|
||||
|
||||
#< 17 (38,16) (40,8)
|
||||
def a(self, Abc):
|
||||
#< 10 (38,16) (40,8)
|
||||
Abc
|
||||
|
||||
#< 19 (43,18) (45,8)
|
||||
def self_test(self):
|
||||
#< 12 (43,18) (45,8)
|
||||
self.b
|
||||
|
||||
Abc.d.Abc
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#< 4 (55,4) (59,1)
|
||||
def blub():
|
||||
|
||||
|
||||
#< (55,4) (59,1)
|
||||
@blub
|
||||
def a(): pass
|
||||
|
||||
@@ -135,7 +135,7 @@ def run_related_name_test(correct, source, line_nr, index, line, path):
|
||||
print('test @%s: %s' % (line_nr - 1, line))
|
||||
return 1
|
||||
else:
|
||||
comp_str = set(r.description for r in result)
|
||||
comp_str = set('(%s,%s)' % r.start_pos for r in result)
|
||||
correct = set(correct.strip().split(' '))
|
||||
if comp_str != correct:
|
||||
print('Solution @%s not right, received %s, wanted %s'\
|
||||
|
||||
Reference in New Issue
Block a user