1
0
forked from VimPlug/jedi

Modules also use a NamePart as a name, now.

This commit is contained in:
Dave Halter
2014-09-22 12:52:48 +02:00
parent 779618c08b
commit c4e45916c6
6 changed files with 22 additions and 16 deletions

View File

@@ -180,6 +180,7 @@ class Script(object):
comp_dct = {} comp_dct = {}
for c, s in set(completions): for c, s in set(completions):
# TODO Remove this line. c should be a namepart even before that. # TODO Remove this line. c should be a namepart even before that.
if isinstance(c, pr.Name):
c = c.names[-1] c = c.names[-1]
n = str(c) n = str(c)
if settings.case_insensitive_completion \ if settings.case_insensitive_completion \
@@ -189,7 +190,7 @@ class Script(object):
if isinstance(c.parent.parent, (pr.Function, pr.Class)): if isinstance(c.parent.parent, (pr.Function, pr.Class)):
# TODO I think this is a hack. It should be an # TODO I think this is a hack. It should be an
# er.Function/er.Class before that. # 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) 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:
@@ -455,7 +456,7 @@ class Script(object):
if next(context) in ('class', 'def'): if next(context) in ('class', 'def'):
# The cursor is on a class/function name. # The cursor is on a class/function name.
user_scope = self._parser.user_scope() user_scope = self._parser.user_scope()
definitions = set([user_scope.name.names[-1]]) definitions = set([user_scope.name])
elif isinstance(user_stmt, pr.Import): elif isinstance(user_stmt, pr.Import):
s, name_part = helpers.get_on_import_stmt(self._evaluator, s, name_part = helpers.get_on_import_stmt(self._evaluator,
self._user_context, user_stmt) self._user_context, user_stmt)

View File

@@ -240,7 +240,6 @@ class CompiledName(FakeName):
super(CompiledName, self).__init__(name) super(CompiledName, self).__init__(name)
self._obj = obj self._obj = obj
self.name = name self.name = name
self.start_pos = 0, 0 # an illegal start_pos, to make sorting easy.
def __repr__(self): def __repr__(self):
try: try:

View File

@@ -102,14 +102,20 @@ 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.
if isinstance(name, pr.Name):
names.append(name.names[-1]) names.append(name.names[-1])
else:
names.append(name)
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:
if isinstance(name, pr.Name):
names.append(name.names[-1]) names.append(name.names[-1])
else:
names.append(name)
if check is flow_analysis.REACHABLE: if check is flow_analysis.REACHABLE:
break break
@@ -141,7 +147,7 @@ class NameFinder(object):
for n in names: for n in names:
definition = n.parent.parent definition = n.parent.parent
if isinstance(definition, (pr.Function, pr.Class, pr.Module)): 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: else:
yield n yield n

View File

@@ -303,13 +303,9 @@ class FakeImport(pr.Import):
self.parent = parent self.parent = parent
class FakeName(pr.Name): class FakeName(pr.NamePart):
def __init__(self, name_or_names, parent=None, start_pos=(0, 0)): def __init__(self, name_str, parent=None, start_pos=(0, 0)):
if isinstance(name_or_names, list): super(FakeName, self).__init__(FakeSubModule, name_str, parent, start_pos)
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)
def get_definition(self): def get_definition(self):
return self.parent return self.parent

View File

@@ -670,6 +670,11 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
# All the additional module attributes are strings. # All the additional module attributes are strings.
return [helpers.LazyName(n, parent_callback) for n in names] 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() @memoize_default()
def _sub_modules(self): def _sub_modules(self):
""" """

View File

@@ -468,8 +468,7 @@ class SubModule(Scope, Module):
string = re.sub('\.[a-z]+-\d{2}[mud]{0,3}$', '', r.group(1)) string = re.sub('\.[a-z]+-\d{2}[mud]{0,3}$', '', r.group(1))
# Positions are not real, but a module starts at (1, 0) # Positions are not real, but a module starts at (1, 0)
p = (1, 0) p = (1, 0)
names = [(string, p)] return NamePart(self, string, self.use_as_parent, p)
return Name(self, names, p, p, self.use_as_parent)
@property @property
def has_explicit_absolute_import(self): def has_explicit_absolute_import(self):