mirror of
https://github.com/davidhalter/jedi.git
synced 2026-02-27 23:32:19 +08:00
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:
|
for s in scopes:
|
||||||
if s.isinstance(er.Function):
|
if s.isinstance(er.Function):
|
||||||
names = s.get_magic_function_names()
|
names = s.get_magic_function_names()
|
||||||
else:
|
elif isinstance(s, imports.ImportWrapper):
|
||||||
if isinstance(s, imports.ImportWrapper):
|
under = like + self._user_context.get_path_after_cursor()
|
||||||
under = like + self._user_context.get_path_after_cursor()
|
if under == 'import':
|
||||||
if under == 'import':
|
current_line = self._user_context.get_position_line()
|
||||||
current_line = self._user_context.get_position_line()
|
if not current_line.endswith('import import'):
|
||||||
if not current_line.endswith('import import'):
|
|
||||||
continue
|
|
||||||
a = s.import_stmt.alias
|
|
||||||
if a and a.start_pos <= self._pos <= a.end_pos:
|
|
||||||
continue
|
continue
|
||||||
names = s.get_defined_names(on_import_stmt=True)
|
a = s.import_stmt.alias
|
||||||
else:
|
if a and a.start_pos <= self._pos <= a.end_pos:
|
||||||
try:
|
continue
|
||||||
sng = s.scope_names_generator
|
names = s.get_defined_names(on_import_stmt=True)
|
||||||
except AttributeError:
|
else:
|
||||||
names = s.get_defined_names()
|
names = []
|
||||||
else:
|
for _, new_names in s.scope_names_generator():
|
||||||
names = []
|
names += new_names
|
||||||
for _, new_names in sng():
|
|
||||||
names += new_names
|
|
||||||
|
|
||||||
for c in names:
|
for c in names:
|
||||||
completions.append((c, s))
|
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
|
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.
|
check for -> a is a string). There's big potential in these checks.
|
||||||
"""
|
"""
|
||||||
import sys
|
|
||||||
from itertools import chain
|
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 representation as pr, tokenize
|
||||||
from jedi.parser import fast
|
from jedi.parser import fast
|
||||||
from jedi import debug
|
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)
|
and non_flow.isinstance(er.Function)
|
||||||
or isinstance(scope, compiled.CompiledObject)
|
or isinstance(scope, compiled.CompiledObject)
|
||||||
and scope.type() == 'class' and in_func_scope != scope):
|
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):
|
if isinstance(scope, (pr.SubModule, fast.Module)):
|
||||||
yield g
|
scope = er.ModuleWrapper(evaluator, scope)
|
||||||
"""
|
|
||||||
try:
|
for g in scope.scope_names_generator(position):
|
||||||
sng = scope.scope_names_generator
|
yield g
|
||||||
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 scope.isinstance(pr.ListComprehension):
|
if scope.isinstance(pr.ListComprehension):
|
||||||
# is a list comprehension
|
# is a list comprehension
|
||||||
yield scope, scope.get_defined_names(is_internal_call=True)
|
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
|
self.var_args = var_args
|
||||||
|
|
||||||
@underscore_memoization
|
@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
|
Returns a list of names that define a generator, which can return the
|
||||||
content of a generator.
|
content of a generator.
|
||||||
@@ -57,6 +57,9 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
else:
|
else:
|
||||||
yield name
|
yield name
|
||||||
|
|
||||||
|
def scope_names_generator(self):
|
||||||
|
yield self, self._get_defined_names()
|
||||||
|
|
||||||
def iter_content(self):
|
def iter_content(self):
|
||||||
""" returns the content of __iter__ """
|
""" returns the content of __iter__ """
|
||||||
return self._evaluator.execute(self.func, self.var_args, True)
|
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]]
|
values = [self._array.values[index]]
|
||||||
return _follow_values(self._evaluator, values)
|
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.
|
This method generates all `ArrayMethod` for one pr.Array.
|
||||||
It returns e.g. for a list: append, pop, ...
|
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.find_types(compiled.builtin, self._array.type)[0]
|
||||||
scope = self._evaluator.execute(scope)[0] # builtins only have one class
|
scope = self._evaluator.execute(scope)[0] # builtins only have one class
|
||||||
names = scope.get_defined_names()
|
names = scope.get_defined_names()
|
||||||
return [ArrayMethod(n) for n in names]
|
yield self, [ArrayMethod(n) for n in names]
|
||||||
|
|
||||||
@common.safe_property
|
@common.safe_property
|
||||||
def parent(self):
|
def parent(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user