forked from VimPlug/jedi
also add scope_names_generator to the iterable module classes, as well as cleaning up some old scope_names_generator stuff
This commit is contained in:
@@ -218,26 +218,20 @@ class Script(object):
|
||||
for s in scopes:
|
||||
if s.isinstance(er.Function):
|
||||
names = s.get_magic_function_names()
|
||||
else:
|
||||
if isinstance(s, imports.ImportWrapper):
|
||||
under = like + self._user_context.get_path_after_cursor()
|
||||
if under == 'import':
|
||||
current_line = self._user_context.get_position_line()
|
||||
if not current_line.endswith('import import'):
|
||||
continue
|
||||
a = s.import_stmt.alias
|
||||
if a and a.start_pos <= self._pos <= a.end_pos:
|
||||
elif isinstance(s, imports.ImportWrapper):
|
||||
under = like + self._user_context.get_path_after_cursor()
|
||||
if under == 'import':
|
||||
current_line = self._user_context.get_position_line()
|
||||
if not current_line.endswith('import import'):
|
||||
continue
|
||||
names = s.get_defined_names(on_import_stmt=True)
|
||||
else:
|
||||
try:
|
||||
sng = s.scope_names_generator
|
||||
except AttributeError:
|
||||
names = s.get_defined_names()
|
||||
else:
|
||||
names = []
|
||||
for _, new_names in sng():
|
||||
names += new_names
|
||||
a = s.import_stmt.alias
|
||||
if a and a.start_pos <= self._pos <= a.end_pos:
|
||||
continue
|
||||
names = s.get_defined_names(on_import_stmt=True)
|
||||
else:
|
||||
names = []
|
||||
for _, new_names in s.scope_names_generator():
|
||||
names += new_names
|
||||
|
||||
for c in names:
|
||||
completions.append((c, s))
|
||||
|
||||
@@ -11,10 +11,9 @@ would check whether a flow has the form of ``if isinstance(a, type_or_tuple)``.
|
||||
Unfortunately every other thing is being ignored (e.g. a == '' would be easy to
|
||||
check for -> a is a string). There's big potential in these checks.
|
||||
"""
|
||||
import sys
|
||||
from itertools import chain
|
||||
|
||||
from jedi._compatibility import hasattr, unicode, u, reraise
|
||||
from jedi._compatibility import hasattr, unicode, u
|
||||
from jedi.parser import representation as pr, tokenize
|
||||
from jedi.parser import fast
|
||||
from jedi import debug
|
||||
@@ -513,23 +512,12 @@ def get_names_of_scope(evaluator, scope, position=None, star_search=True, includ
|
||||
and non_flow.isinstance(er.Function)
|
||||
or isinstance(scope, compiled.CompiledObject)
|
||||
and scope.type() == 'class' and in_func_scope != scope):
|
||||
try:
|
||||
if isinstance(scope, (pr.SubModule, fast.Module)):
|
||||
scope = er.ModuleWrapper(evaluator, scope)
|
||||
|
||||
for g in scope.scope_names_generator(position):
|
||||
yield g
|
||||
"""
|
||||
try:
|
||||
sng = scope.scope_names_generator
|
||||
except AttributeError:
|
||||
yield scope, _get_defined_names_for_position(scope, position, in_func_scope)
|
||||
else:
|
||||
for g in sng(position):
|
||||
yield g
|
||||
"""
|
||||
except StopIteration:
|
||||
reraise(common.MultiLevelStopIteration, sys.exc_info()[2])
|
||||
if isinstance(scope, (pr.SubModule, fast.Module)):
|
||||
scope = er.ModuleWrapper(evaluator, scope)
|
||||
|
||||
for g in scope.scope_names_generator(position):
|
||||
yield g
|
||||
if scope.isinstance(pr.ListComprehension):
|
||||
# is a list comprehension
|
||||
yield scope, scope.get_defined_names(is_internal_call=True)
|
||||
|
||||
@@ -44,7 +44,7 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
self.var_args = var_args
|
||||
|
||||
@underscore_memoization
|
||||
def get_defined_names(self):
|
||||
def _get_defined_names(self):
|
||||
"""
|
||||
Returns a list of names that define a generator, which can return the
|
||||
content of a generator.
|
||||
@@ -57,6 +57,9 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
else:
|
||||
yield name
|
||||
|
||||
def scope_names_generator(self):
|
||||
yield self, self._get_defined_names()
|
||||
|
||||
def iter_content(self):
|
||||
""" returns the content of __iter__ """
|
||||
return self._evaluator.execute(self.func, self.var_args, True)
|
||||
@@ -172,7 +175,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
values = [self._array.values[index]]
|
||||
return _follow_values(self._evaluator, values)
|
||||
|
||||
def get_defined_names(self):
|
||||
def scope_names_generator(self):
|
||||
"""
|
||||
This method generates all `ArrayMethod` for one pr.Array.
|
||||
It returns e.g. for a list: append, pop, ...
|
||||
@@ -181,7 +184,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
scope = self._evaluator.find_types(compiled.builtin, self._array.type)[0]
|
||||
scope = self._evaluator.execute(scope)[0] # builtins only have one class
|
||||
names = scope.get_defined_names()
|
||||
return [ArrayMethod(n) for n in names]
|
||||
yield self, [ArrayMethod(n) for n in names]
|
||||
|
||||
@common.safe_property
|
||||
def parent(self):
|
||||
|
||||
Reference in New Issue
Block a user