1
0
forked from VimPlug/jedi

NamePart migration of Definition is complete. Now Completion.

This commit is contained in:
Dave Halter
2014-09-10 18:29:10 +02:00
parent 2aa538999e
commit 0eea30f227
4 changed files with 18 additions and 14 deletions

View File

@@ -391,9 +391,9 @@ class BaseDefinition(object):
if isinstance(self._definition, compiled.CompiledObject):
non_flow = self._definition.parent
else:
scope = self._definition.get_parent_scope()
scope = self._definition.get_definition().get_parent_scope()
non_flow = scope.get_parent_until(pr.Flow, reverse=True)
return Definition(self._evaluator, non_flow)
return Definition(self._evaluator, non_flow.name.names[-1])
def __repr__(self):
return "<%s %s>" % (type(self).__name__, self.description)
@@ -565,7 +565,7 @@ class Completion(BaseDefinition):
it's just PITA-slow.
"""
defs = self._follow_statements_imports()
return [Definition(self._evaluator, d) for d in defs]
return [Definition(self._evaluator, d.name.names[-1]) for d in defs]
class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
@@ -760,7 +760,7 @@ class CallSignature(Definition):
for i, param in enumerate(self.params):
if self._key_name == param.name:
return i
if self.params and self.params[-1]._definition.stars == 2:
if self.params and self.params[-1]._definition.get_definition().stars == 2:
return i
else:
return None
@@ -769,7 +769,7 @@ class CallSignature(Definition):
for i, param in enumerate(self.params):
# *args case
if param._definition.stars == 1:
if param._definition.get_definition().stars == 1:
return i
return None
return self._index

View File

@@ -267,12 +267,16 @@ class NameFinder(object):
# check for `except X as y` usages, because y needs to be instantiated.
p = stmt.parent
# TODO this looks really hacky, improve parser representation!
if isinstance(p, pr.Flow) and p.command == 'except' \
and p.inputs and p.inputs[0].as_names[0].names[-1] == name:
# TODO check for types that are not classes and add it to the
# static analysis report.
types = list(chain.from_iterable(
evaluator.execute(t) for t in types))
if isinstance(p, pr.Flow) and p.command == 'except' and p.inputs:
as_names = p.inputs[0].as_names
try:
if as_names[0].names[-1] == name:
# TODO check for types that are not classes and add it to
# the static analysis report.
types = list(chain.from_iterable(
evaluator.execute(t) for t in types))
except IndexError:
pass
if check_instance is not None:
# class renames

View File

@@ -196,7 +196,7 @@ class ImportWrapper(pr.Base):
# goto only accepts Names or NameParts
if is_goto and not rest:
scopes = [s.name for s in scopes]
scopes = [s.name.names[-1] for s in scopes]
# follow the rest of the import (not FS -> classes, functions)
if len(rest) > 1 or rest and self.is_like_search:

View File

@@ -170,8 +170,8 @@ class TestParent(TestCase):
parent = self._parent('''\
def spam():
pass''', 1, len('def spam'))
assert parent.name == 'spam'
assert parent.parent().type == 'module'
assert parent.name == ''
assert parent.type == 'module'
def test_parent_on_completion(self):
parent = Script(dedent('''\