forked from VimPlug/jedi
Modules also use a NamePart as a name, now.
This commit is contained in:
@@ -180,6 +180,7 @@ class Script(object):
|
||||
comp_dct = {}
|
||||
for c, s in set(completions):
|
||||
# TODO Remove this line. c should be a namepart even before that.
|
||||
if isinstance(c, pr.Name):
|
||||
c = c.names[-1]
|
||||
n = str(c)
|
||||
if settings.case_insensitive_completion \
|
||||
@@ -189,7 +190,7 @@ class Script(object):
|
||||
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]
|
||||
c = er.wrap(self._evaluator, c.parent.parent).name
|
||||
new = classes.Completion(self._evaluator, c, needs_dot, len(like), s)
|
||||
k = (new.name, new.complete) # key
|
||||
if k in comp_dct and settings.no_completion_duplicates:
|
||||
@@ -455,7 +456,7 @@ class Script(object):
|
||||
if next(context) in ('class', 'def'):
|
||||
# The cursor is on a class/function name.
|
||||
user_scope = self._parser.user_scope()
|
||||
definitions = set([user_scope.name.names[-1]])
|
||||
definitions = set([user_scope.name])
|
||||
elif isinstance(user_stmt, pr.Import):
|
||||
s, name_part = helpers.get_on_import_stmt(self._evaluator,
|
||||
self._user_context, user_stmt)
|
||||
|
||||
@@ -240,7 +240,6 @@ class CompiledName(FakeName):
|
||||
super(CompiledName, self).__init__(name)
|
||||
self._obj = obj
|
||||
self.name = name
|
||||
self.start_pos = 0, 0 # an illegal start_pos, to make sorting easy.
|
||||
|
||||
def __repr__(self):
|
||||
try:
|
||||
|
||||
@@ -102,14 +102,20 @@ class NameFinder(object):
|
||||
or isinstance(scope, compiled.CompiledObject) \
|
||||
or isinstance(stmt, pr.ExprStmt) and stmt.is_global():
|
||||
# Always reachable.
|
||||
if isinstance(name, pr.Name):
|
||||
names.append(name.names[-1])
|
||||
else:
|
||||
names.append(name)
|
||||
else:
|
||||
check = flow_analysis.break_check(self._evaluator,
|
||||
name_list_scope,
|
||||
er.wrap(self._evaluator, scope),
|
||||
self.scope)
|
||||
if check is not flow_analysis.UNREACHABLE:
|
||||
if isinstance(name, pr.Name):
|
||||
names.append(name.names[-1])
|
||||
else:
|
||||
names.append(name)
|
||||
if check is flow_analysis.REACHABLE:
|
||||
break
|
||||
|
||||
@@ -141,7 +147,7 @@ class NameFinder(object):
|
||||
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]
|
||||
yield er.wrap(self._evaluator, definition).name
|
||||
else:
|
||||
yield n
|
||||
|
||||
|
||||
@@ -303,13 +303,9 @@ class FakeImport(pr.Import):
|
||||
self.parent = parent
|
||||
|
||||
|
||||
class FakeName(pr.Name):
|
||||
def __init__(self, name_or_names, parent=None, start_pos=(0, 0)):
|
||||
if isinstance(name_or_names, list):
|
||||
names = [(n, start_pos) for n in name_or_names]
|
||||
else:
|
||||
names = [(name_or_names, start_pos)]
|
||||
super(FakeName, self).__init__(FakeSubModule, names, start_pos, start_pos, parent)
|
||||
class FakeName(pr.NamePart):
|
||||
def __init__(self, name_str, parent=None, start_pos=(0, 0)):
|
||||
super(FakeName, self).__init__(FakeSubModule, name_str, parent, start_pos)
|
||||
|
||||
def get_definition(self):
|
||||
return self.parent
|
||||
|
||||
@@ -670,6 +670,11 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
|
||||
# All the additional module attributes are strings.
|
||||
return [helpers.LazyName(n, parent_callback) for n in names]
|
||||
|
||||
@property
|
||||
@memoize_default()
|
||||
def name(self):
|
||||
return pr.NamePart(self, unicode(self.base.name), self, (1, 0))
|
||||
|
||||
@memoize_default()
|
||||
def _sub_modules(self):
|
||||
"""
|
||||
|
||||
@@ -468,8 +468,7 @@ class SubModule(Scope, Module):
|
||||
string = re.sub('\.[a-z]+-\d{2}[mud]{0,3}$', '', r.group(1))
|
||||
# Positions are not real, but a module starts at (1, 0)
|
||||
p = (1, 0)
|
||||
names = [(string, p)]
|
||||
return Name(self, names, p, p, self.use_as_parent)
|
||||
return NamePart(self, string, self.use_as_parent, p)
|
||||
|
||||
@property
|
||||
def has_explicit_absolute_import(self):
|
||||
|
||||
Reference in New Issue
Block a user