mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 10:07:06 +08:00
use defined_names also for modules, fixes symbol browsing issues - fixes #344
This commit is contained in:
@@ -4,6 +4,7 @@ These classes are the much bigger part of the whole API, because they contain
|
||||
the interesting information about completion and goto operations.
|
||||
"""
|
||||
import warnings
|
||||
from itertools import chain
|
||||
|
||||
from jedi._compatibility import next, unicode, use_metaclass
|
||||
from jedi import settings
|
||||
@@ -523,7 +524,7 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
||||
if isinstance(d, er.InstanceElement):
|
||||
d = d.var
|
||||
|
||||
if isinstance(d, compiled.CompiledObject):
|
||||
if isinstance(d, (compiled.CompiledObject, compiled.CompiledName)):
|
||||
name = d.name
|
||||
elif isinstance(d, pr.Name):
|
||||
name = d.names[-1]
|
||||
@@ -624,12 +625,12 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
||||
|
||||
:rtype: list of Definition
|
||||
"""
|
||||
d = self._definition
|
||||
if isinstance(d, er.InstanceElement):
|
||||
d = d.var
|
||||
if isinstance(d, pr.Name):
|
||||
d = d.parent
|
||||
return defined_names(self._evaluator, d)
|
||||
defs = self._follow_statements_imports()
|
||||
# For now we don't want base classes or evaluate decorators.
|
||||
defs = [d.base if isinstance(d, (er.Class, er.Function)) else d for d in defs]
|
||||
iterable = (defined_names(self._evaluator, d) for d in defs)
|
||||
iterable = list(iterable)
|
||||
return list(chain.from_iterable(iterable))
|
||||
|
||||
|
||||
class CallSignature(Definition):
|
||||
|
||||
@@ -143,18 +143,13 @@ class CompiledObject(Base):
|
||||
return hasattr(self.obj, '__call__')
|
||||
|
||||
|
||||
class CompiledName(object):
|
||||
class CompiledName(FakeName):
|
||||
def __init__(self, obj, name):
|
||||
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 get_parent_until(self):
|
||||
return self.parent.get_parent_until()
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s: (%s).%s>' % (type(self).__name__, self._obj.name, self.name)
|
||||
|
||||
@@ -164,12 +159,9 @@ class CompiledName(object):
|
||||
module = self._obj.get_parent_until()
|
||||
return _create_from_name(module, self._obj, self.name)
|
||||
|
||||
@property
|
||||
def names(self):
|
||||
return [self.name] # compatibility with parser.representation.Name
|
||||
|
||||
def get_code(self):
|
||||
return self.name
|
||||
@parent.setter
|
||||
def parent(self, value):
|
||||
pass # Just ignore this, FakeName tries to overwrite the parent attribute.
|
||||
|
||||
|
||||
def load_module(path, name):
|
||||
|
||||
Reference in New Issue
Block a user