1
0
forked from VimPlug/jedi

Apply evaluate.representation wrappers already before they go out into the goto world.

This commit is contained in:
Dave Halter
2014-09-11 02:20:54 +02:00
parent 1624fa0872
commit 085c8034b3
3 changed files with 30 additions and 23 deletions

View File

@@ -186,6 +186,10 @@ class Script(object):
and n.lower().startswith(like.lower()) \ and n.lower().startswith(like.lower()) \
or n.startswith(like): or n.startswith(like):
if not filter_private_variable(s, user_stmt or self._parser.user_scope(), n): if not filter_private_variable(s, user_stmt or self._parser.user_scope(), n):
if isinstance(c.parent.parent, (pr.Function, pr.Class)):
# TODO I think this is a hack. It should be an
# er.Function/er.Class before that.
c = er.wrap(self._evaluator, c.parent.parent).name.names[-1]
new = classes.Completion(self._evaluator, c, needs_dot, len(like), s) new = classes.Completion(self._evaluator, c, needs_dot, len(like), s)
k = (new.name, new.complete) # key k = (new.name, new.complete) # key
if k in comp_dct and settings.no_completion_duplicates: if k in comp_dct and settings.no_completion_duplicates:
@@ -378,7 +382,7 @@ class Script(object):
context = self._user_context.get_context() context = self._user_context.get_context()
definitions = set() definitions = set()
if next(context) in ('class', 'def'): if next(context) in ('class', 'def'):
definitions = set([self._parser.user_scope()]) definitions = set([er.wrap(self._evaluator, self._parser.user_scope())])
else: else:
# Fetch definition of callee, if there's no path otherwise. # Fetch definition of callee, if there's no path otherwise.
if not goto_path: if not goto_path:

View File

@@ -344,20 +344,12 @@ class BaseDefinition(object):
""" """
Follow both statements and imports, as far as possible. Follow both statements and imports, as far as possible.
""" """
stripped = self._definition if self._definition.isinstance(pr.ExprStmt):
return self._evaluator.eval_statement(self._definition)
# We should probably work in `Finder._names_to_types` here. elif self._definition.isinstance(pr.Import):
if isinstance(stripped, pr.Function): return imports.follow_imports(self._evaluator, [self._definition])
stripped = er.Function(self._evaluator, stripped)
elif isinstance(stripped, pr.Class):
stripped = er.Class(self._evaluator, stripped)
if stripped.isinstance(pr.ExprStmt):
return self._evaluator.eval_statement(stripped)
elif stripped.isinstance(pr.Import):
return imports.follow_imports(self._evaluator, [stripped])
else: else:
return [stripped] return [self._definition]
@property @property
@memoize_default() @memoize_default()

View File

@@ -71,7 +71,7 @@ class NameFinder(object):
# TODO Now this import is really ugly. Try to remove it. # TODO Now this import is really ugly. Try to remove it.
# It's possibly the only api dependency. # It's possibly the only api dependency.
from jedi.api.interpreter import InterpreterNamespace from jedi.api.interpreter import InterpreterNamespace
result = [] names = []
self.maybe_descriptor = isinstance(self.scope, er.Class) self.maybe_descriptor = isinstance(self.scope, er.Class)
for name_list_scope, name_list in scope_names_generator: for name_list_scope, name_list in scope_names_generator:
break_scopes = [] break_scopes = []
@@ -102,23 +102,23 @@ class NameFinder(object):
or isinstance(scope, compiled.CompiledObject) \ or isinstance(scope, compiled.CompiledObject) \
or isinstance(stmt, pr.ExprStmt) and stmt.is_global(): or isinstance(stmt, pr.ExprStmt) and stmt.is_global():
# Always reachable. # Always reachable.
result.append(name.names[-1]) names.append(name.names[-1])
else: else:
check = flow_analysis.break_check(self._evaluator, check = flow_analysis.break_check(self._evaluator,
name_list_scope, name_list_scope,
er.wrap(self._evaluator, scope), er.wrap(self._evaluator, scope),
self.scope) self.scope)
if check is not flow_analysis.UNREACHABLE: if check is not flow_analysis.UNREACHABLE:
result.append(name.names[-1]) names.append(name.names[-1])
if check is flow_analysis.REACHABLE: if check is flow_analysis.REACHABLE:
break break
if result and self._is_name_break_scope(name, stmt): if names and self._is_name_break_scope(name, stmt):
if self._does_scope_break_immediately(scope, name_list_scope): if self._does_scope_break_immediately(scope, name_list_scope):
break break
else: else:
break_scopes.append(scope) break_scopes.append(scope)
if result: if names:
break break
if isinstance(self.scope, er.Instance): if isinstance(self.scope, er.Instance):
@@ -129,8 +129,21 @@ class NameFinder(object):
scope_txt = (self.scope if self.scope == name_list_scope scope_txt = (self.scope if self.scope == name_list_scope
else '%s-%s' % (self.scope, name_list_scope)) else '%s-%s' % (self.scope, name_list_scope))
debug.dbg('finder.filter_name "%s" in (%s): %s@%s', self.name_str, debug.dbg('finder.filter_name "%s" in (%s): %s@%s', self.name_str,
scope_txt, u(result), self.position) scope_txt, u(names), self.position)
return result return list(self._clean_names(names))
def _clean_names(self, names):
"""
``NameFinder.filter_name`` should only output names with correct
wrapper parents. We don't want to see AST classes out in the
evaluation, so remove them already here!
"""
for n in names:
definition = n.parent.parent
if isinstance(definition, (pr.Function, pr.Class, pr.Module)):
yield er.wrap(self._evaluator, definition).name.names[-1]
else:
yield n
def _check_getattr(self, inst): def _check_getattr(self, inst):
"""Checks for both __getattr__ and __getattribute__ methods""" """Checks for both __getattr__ and __getattribute__ methods"""
@@ -231,8 +244,6 @@ class NameFinder(object):
else: else:
types += self._remove_statements(typ, name) types += self._remove_statements(typ, name)
else: else:
typ = er.wrap(evaluator, typ)
if typ.isinstance(er.Function) and resolve_decorator: if typ.isinstance(er.Function) and resolve_decorator:
typ = typ.get_decorated_func() typ = typ.get_decorated_func()
types.append(typ) types.append(typ)