forked from VimPlug/jedi
implement a Completion.type version for #340, follow imports if they are in a from clause or if its a longer imnport
This commit is contained in:
@@ -87,7 +87,7 @@ class BaseDefinition(object):
|
|||||||
|
|
||||||
Here is an example of the value of this attribute. Let's consider
|
Here is an example of the value of this attribute. Let's consider
|
||||||
the following source. As what is in ``variable`` is unambiguous
|
the following source. As what is in ``variable`` is unambiguous
|
||||||
to Jedi, :meth:`api.Script.goto_definitions` should return a list of
|
to Jedi, :meth:`jedi.Script.goto_definitions` should return a list of
|
||||||
definition for ``sys``, ``f``, ``C`` and ``x``.
|
definition for ``sys``, ``f``, ``C`` and ``x``.
|
||||||
|
|
||||||
>>> from jedi import Script
|
>>> from jedi import Script
|
||||||
@@ -136,7 +136,7 @@ class BaseDefinition(object):
|
|||||||
if isinstance(stripped, er.InstanceElement):
|
if isinstance(stripped, er.InstanceElement):
|
||||||
stripped = stripped.var
|
stripped = stripped.var
|
||||||
if isinstance(stripped, pr.Name):
|
if isinstance(stripped, pr.Name):
|
||||||
stripped = stripped.parent
|
stripped = stripped.parent # remove, this shouldn't be here.
|
||||||
return type(stripped).__name__.lower()
|
return type(stripped).__name__.lower()
|
||||||
|
|
||||||
def _path(self):
|
def _path(self):
|
||||||
@@ -387,6 +387,28 @@ class Completion(BaseDefinition):
|
|||||||
line = '' if self.in_builtin_module else '@%s' % self.line
|
line = '' if self.in_builtin_module else '@%s' % self.line
|
||||||
return '%s: %s%s' % (t, desc, line)
|
return '%s: %s%s' % (t, desc, line)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<%s: %s>' % (type(self).__name__, self._name)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type(self):
|
||||||
|
"""
|
||||||
|
The type of the completion objects. Follows imports. For a further
|
||||||
|
description, look at :meth:`jedi.api.classes.BaseDefinition.type`.
|
||||||
|
"""
|
||||||
|
if isinstance(self._definition, pr.Import):
|
||||||
|
i = imports.ImportPath(self._evaluator, self._definition)
|
||||||
|
if len(i.import_path) <= 1:
|
||||||
|
return 'module'
|
||||||
|
|
||||||
|
followed = self.follow_definition()
|
||||||
|
if followed:
|
||||||
|
# Caveat: Only follows the first one, ignore the other ones.
|
||||||
|
# This is ok, since people are almost never interested in
|
||||||
|
# variations.
|
||||||
|
return followed[0].type
|
||||||
|
return super(Completion, self).type
|
||||||
|
|
||||||
@cache.underscore_memoization
|
@cache.underscore_memoization
|
||||||
def follow_definition(self):
|
def follow_definition(self):
|
||||||
"""
|
"""
|
||||||
@@ -413,9 +435,6 @@ class Completion(BaseDefinition):
|
|||||||
cache.clear_caches()
|
cache.clear_caches()
|
||||||
return defs
|
return defs
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return '<%s: %s>' % (type(self).__name__, self._name)
|
|
||||||
|
|
||||||
|
|
||||||
class Definition(BaseDefinition):
|
class Definition(BaseDefinition):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user