1
0
forked from VimPlug/jedi

Start to rework dynamic params. However goto is now needed first.

This commit is contained in:
Dave Halter
2014-11-17 12:34:32 +01:00
parent 0567a886c4
commit 2dfbc2a0fd
2 changed files with 25 additions and 16 deletions

View File

@@ -177,7 +177,7 @@ class Evaluator(object):
for trailer in element.children[1:]:
if trailer == '**': # has a power operation.
raise NotImplementedError
types = self._eval_trailer(types, trailer)
types = self.eval_trailer(types, trailer)
return types
elif pr.is_node(element, 'testlist_star_expr', 'testlist'):
@@ -223,13 +223,13 @@ class Evaluator(object):
return [iterable.Comprehension.from_atom(self, atom)]
return [iterable.Array(self, atom)]
def _eval_trailer(self, types, trailer):
def eval_trailer(self, types, trailer):
trailer_op, node = trailer.children[:2]
if node == ')': # `arglist` is optional.
node = ()
new_types = []
for typ in types:
debug.dbg('_eval_trailer: %s in scope %s', trailer, typ)
debug.dbg('eval_trailer: %s in scope %s', trailer, typ)
if trailer_op == '.':
new_types += self.find_types(typ, node)
elif trailer_op == '(':

View File

@@ -56,6 +56,7 @@ def search_params(evaluator, param):
"""
if not settings.dynamic_params:
return []
from jedi.evaluate import representation as er
def get_params_for_module(module):
"""
@@ -64,13 +65,30 @@ def search_params(evaluator, param):
@memoize_default([], evaluator_is_first_arg=True)
def get_posibilities(evaluator, module, func_name):
try:
possible_stmts = module.used_names[func_name]
names = module.used_names[func_name]
except KeyError:
return []
for stmt in possible_stmts:
if isinstance(stmt, pr.Import):
for name in names:
stmt = name.get_definition()
if not isinstance(stmt, pr.ExprStmt):
continue
print(stmt, stmt.start_pos, name.parent)
try:
trailer = name.parent.children[1]
except IndexError:
continue
else:
types = evaluator.goto(name)
if compare in types:
# Only if we have the correct function we execute
# it, otherwise just ignore it.
evaluator.eval_trailer(types, trailer)
continue
calls = helpers.scan_statement_for_calls(stmt, func_name)
for c in calls:
# no execution means that params cannot be set
@@ -120,7 +138,7 @@ def search_params(evaluator, param):
result = []
for params in get_posibilities(evaluator, module, func_name):
for p in params:
if str(p) == param_name:
if str(p) == param.name:
result += evaluator.eval_statement(p.get_definition())
return result
@@ -132,15 +150,6 @@ def search_params(evaluator, param):
func_name = unicode(func.parent.name)
compare = func.parent
# get the param name
if param.assignment_details:
# first assignment details, others would be a syntax error
expression_list, op = param.assignment_details[0]
else:
expression_list = param.expression_list()
offset = 1 if expression_list[0] in ['*', '**'] else 0
param_name = str(expression_list[offset].name)
# add the listener
listener = ParamListener()
func.listeners.add(listener)