1
0
forked from VimPlug/jedi

Start to use NameParts only in Definition contexts.

This commit is contained in:
Dave Halter
2014-09-09 14:13:01 +02:00
parent ff7680c15f
commit 1199defabb
5 changed files with 32 additions and 15 deletions

View File

@@ -263,6 +263,7 @@ class Script(object):
if user_stmt is not None:
eval_stmt.start_pos = user_stmt.end_pos
scopes = self._evaluator.eval_statement(eval_stmt)
return scopes
def _get_under_cursor_stmt(self, cursor_txt):
@@ -387,10 +388,11 @@ class Script(object):
if goto_path:
definitions = set(self._prepare_goto(goto_path))
definitions = resolve_import_paths(definitions)
d = set([classes.Definition(self._evaluator, s) for s in definitions
if s is not imports.ImportWrapper.GlobalNamespace])
return helpers.sorted_definitions(d)
names = [s if isinstance(s, pr.Name) else s.name for s in definitions
if s is not imports.ImportWrapper.GlobalNamespace]
defs = [classes.Definition(self._evaluator, name.names[-1])
for name in names]
return helpers.sorted_definitions(set(defs))
def goto_assignments(self):
"""
@@ -563,7 +565,7 @@ class Script(object):
key_name = unicode(detail[0][0].name)
except (IndexError, AttributeError):
pass
return [classes.CallSignature(self._evaluator, o, call, index, key_name)
return [classes.CallSignature(self._evaluator, o.name.names[-1], call, index, key_name)
for o in origins if hasattr(o, 'py__call__')]
def _analysis(self):

View File

@@ -330,7 +330,7 @@ class BaseDefinition(object):
# Functions, classes and modules are already fixed definitions, we
# cannot follow them anymore.
return [self]
stmt_or_imp = self._definition.get_parent_until((pr.ExprStmt, pr.Import))
stmt_or_imp = self._definition.get_parent_until((pr.Statement, pr.Import))
call_path = call_path_for_name_part(stmt_or_imp, self._definition)
names = self._evaluator.goto(stmt_or_imp, call_path)
return [Definition(self._evaluator, n) for n in names]
@@ -708,9 +708,13 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
# Currently only handle NameParts. Once we have a proper API, this
# will be the standard anyway.
raise NotImplementedError
stmt_or_imp = self._definition.get_parent_until((pr.ExprStmt, pr.Import))
exp_list = stmt_or_imp.expression_list()
return not exp_list or self._definition.start_pos < exp_list[0].start_pos
_def = self._definition.get_parent_until((pr.ExprStmt,
pr.Import, pr.Function, pr.Class, pr.Module))
if isinstance(_def, pr.ExprStmt):
exp_list = _def.expression_list()
return not exp_list or self._definition.start_pos < exp_list[0].start_pos
else:
return True
def __eq__(self, other):
return self._start_pos == other._start_pos \