mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
NamePart migration of Definition is complete. Now Completion.
This commit is contained in:
@@ -391,9 +391,9 @@ class BaseDefinition(object):
|
|||||||
if isinstance(self._definition, compiled.CompiledObject):
|
if isinstance(self._definition, compiled.CompiledObject):
|
||||||
non_flow = self._definition.parent
|
non_flow = self._definition.parent
|
||||||
else:
|
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)
|
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):
|
def __repr__(self):
|
||||||
return "<%s %s>" % (type(self).__name__, self.description)
|
return "<%s %s>" % (type(self).__name__, self.description)
|
||||||
@@ -565,7 +565,7 @@ class Completion(BaseDefinition):
|
|||||||
it's just PITA-slow.
|
it's just PITA-slow.
|
||||||
"""
|
"""
|
||||||
defs = self._follow_statements_imports()
|
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)):
|
class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
||||||
@@ -760,7 +760,7 @@ class CallSignature(Definition):
|
|||||||
for i, param in enumerate(self.params):
|
for i, param in enumerate(self.params):
|
||||||
if self._key_name == param.name:
|
if self._key_name == param.name:
|
||||||
return i
|
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
|
return i
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
@@ -769,7 +769,7 @@ class CallSignature(Definition):
|
|||||||
|
|
||||||
for i, param in enumerate(self.params):
|
for i, param in enumerate(self.params):
|
||||||
# *args case
|
# *args case
|
||||||
if param._definition.stars == 1:
|
if param._definition.get_definition().stars == 1:
|
||||||
return i
|
return i
|
||||||
return None
|
return None
|
||||||
return self._index
|
return self._index
|
||||||
|
|||||||
@@ -267,12 +267,16 @@ class NameFinder(object):
|
|||||||
# check for `except X as y` usages, because y needs to be instantiated.
|
# check for `except X as y` usages, because y needs to be instantiated.
|
||||||
p = stmt.parent
|
p = stmt.parent
|
||||||
# TODO this looks really hacky, improve parser representation!
|
# TODO this looks really hacky, improve parser representation!
|
||||||
if isinstance(p, pr.Flow) and p.command == 'except' \
|
if isinstance(p, pr.Flow) and p.command == 'except' and p.inputs:
|
||||||
and p.inputs and p.inputs[0].as_names[0].names[-1] == name:
|
as_names = p.inputs[0].as_names
|
||||||
# TODO check for types that are not classes and add it to the
|
try:
|
||||||
# static analysis report.
|
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(
|
types = list(chain.from_iterable(
|
||||||
evaluator.execute(t) for t in types))
|
evaluator.execute(t) for t in types))
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
|
||||||
if check_instance is not None:
|
if check_instance is not None:
|
||||||
# class renames
|
# class renames
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ class ImportWrapper(pr.Base):
|
|||||||
|
|
||||||
# goto only accepts Names or NameParts
|
# goto only accepts Names or NameParts
|
||||||
if is_goto and not rest:
|
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)
|
# follow the rest of the import (not FS -> classes, functions)
|
||||||
if len(rest) > 1 or rest and self.is_like_search:
|
if len(rest) > 1 or rest and self.is_like_search:
|
||||||
|
|||||||
@@ -170,8 +170,8 @@ class TestParent(TestCase):
|
|||||||
parent = self._parent('''\
|
parent = self._parent('''\
|
||||||
def spam():
|
def spam():
|
||||||
pass''', 1, len('def spam'))
|
pass''', 1, len('def spam'))
|
||||||
assert parent.name == 'spam'
|
assert parent.name == ''
|
||||||
assert parent.parent().type == 'module'
|
assert parent.type == 'module'
|
||||||
|
|
||||||
def test_parent_on_completion(self):
|
def test_parent_on_completion(self):
|
||||||
parent = Script(dedent('''\
|
parent = Script(dedent('''\
|
||||||
|
|||||||
Reference in New Issue
Block a user