forked from VimPlug/jedi
added much nicer descriptions for the completion. fixes #49
This commit is contained in:
+22
-17
@@ -15,7 +15,22 @@ class BaseOutput(object):
|
|||||||
self.definition = definition
|
self.definition = definition
|
||||||
self.is_keyword = isinstance(definition, keywords.Keyword)
|
self.is_keyword = isinstance(definition, keywords.Keyword)
|
||||||
|
|
||||||
|
# generate the type
|
||||||
|
self.stripped_definition = self.definition
|
||||||
|
if isinstance(self.definition, evaluate.InstanceElement):
|
||||||
|
self.stripped_definition = self.definition.var
|
||||||
|
self.type = type(self.stripped_definition).__name__
|
||||||
|
|
||||||
|
# generate a path to the definition
|
||||||
self.module_path = str(definition.get_parent_until().path)
|
self.module_path = str(definition.get_parent_until().path)
|
||||||
|
self.path = []
|
||||||
|
par = definition
|
||||||
|
while par is not None:
|
||||||
|
if not isinstance(self.stripped_definition,
|
||||||
|
(parsing.Flow, parsing.Statement, parsing.Import,
|
||||||
|
evaluate.Array, parsing.Name)):
|
||||||
|
self.path.insert(0, par.name)
|
||||||
|
par = par.parent()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def module_name(self):
|
def module_name(self):
|
||||||
@@ -51,16 +66,6 @@ class BaseOutput(object):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
@property
|
|
||||||
def type(self):
|
|
||||||
""" Returns the type of a completion object (e.g. 'Module'/'Class') """
|
|
||||||
if self.name.parent is None:
|
|
||||||
return ''
|
|
||||||
name_type = self.definition
|
|
||||||
if isinstance(name_type, evaluate.InstanceElement):
|
|
||||||
name_type = name_type.var
|
|
||||||
return type(name_type).__name__
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def description(self):
|
def description(self):
|
||||||
raise NotImplementedError('Base Class')
|
raise NotImplementedError('Base Class')
|
||||||
@@ -90,9 +95,8 @@ class Completion(BaseOutput):
|
|||||||
"""
|
"""
|
||||||
dot = '.' if self.needs_dot else ''
|
dot = '.' if self.needs_dot else ''
|
||||||
append = ''
|
append = ''
|
||||||
funcs = (parsing.Function, evaluate.Function)
|
|
||||||
if settings.add_bracket_after_function \
|
if settings.add_bracket_after_function \
|
||||||
and self.definition.isinstance(funcs):
|
and self.type == 'Function':
|
||||||
append = '('
|
append = '('
|
||||||
|
|
||||||
if settings.add_dot_after_module:
|
if settings.add_dot_after_module:
|
||||||
@@ -119,12 +123,13 @@ class Completion(BaseOutput):
|
|||||||
if parent is None:
|
if parent is None:
|
||||||
return ''
|
return ''
|
||||||
t = self.type
|
t = self.type
|
||||||
desc = self.definition.get_code(False) if t == 'Statement' \
|
if t == 'Statement':
|
||||||
else str(self.name.names[-1])
|
desc = self.definition.get_code(False)
|
||||||
|
else:
|
||||||
|
desc = '.'.join(str(p) for p in self.path)
|
||||||
|
|
||||||
line_nr = '' if self.in_builtin_module else '@%s' % self.line_nr
|
line_nr = '' if self.in_builtin_module else '@%s' % self.line_nr
|
||||||
temp = '%s: %s%s' % (t, desc, line_nr)
|
return '%s: %s%s' % (t, desc, line_nr)
|
||||||
print temp
|
|
||||||
return temp
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (type(self).__name__, self.name)
|
return '<%s: %s>' % (type(self).__name__, self.name)
|
||||||
|
|||||||
+15
-9
@@ -249,12 +249,12 @@ class Scope(Simple):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
try:
|
try:
|
||||||
name = self.name
|
name = self.path
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
try:
|
try:
|
||||||
name = self.command
|
name = self.name
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
name = self.path
|
name = self.command
|
||||||
|
|
||||||
return "<%s: %s@%s-%s>" % (type(self).__name__, name,
|
return "<%s: %s@%s-%s>" % (type(self).__name__, name,
|
||||||
self.start_pos[0], self.end_pos[0])
|
self.start_pos[0], self.end_pos[0])
|
||||||
@@ -289,16 +289,22 @@ class Module(Scope):
|
|||||||
n += self.global_vars
|
n += self.global_vars
|
||||||
return n
|
return n
|
||||||
|
|
||||||
def get_name(self):
|
@property
|
||||||
|
def name(self):
|
||||||
""" This is used for the goto function. """
|
""" This is used for the goto function. """
|
||||||
sep = (os.path.sep,) * 2
|
if self._name is not None:
|
||||||
r = re.search(r'([^%s]+?)(%s__init__)?(\.py)?$' % sep, self.path)
|
return self._name
|
||||||
string = r.group(1)
|
if self.path is None:
|
||||||
|
string = '' # no path -> empty name
|
||||||
|
else:
|
||||||
|
sep = (os.path.sep,) * 2
|
||||||
|
r = re.search(r'([^%s]+?)(%s__init__)?(\.py)?$' % sep, self.path)
|
||||||
|
string = r.group(1)
|
||||||
names = [(string, (0, 0))]
|
names = [(string, (0, 0))]
|
||||||
if not self._name:
|
self._name = Name(names, self.start_pos, self.end_pos, self)
|
||||||
self._name = Name(names, self.start_pos, self.end_pos, self)
|
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
|
|
||||||
def is_builtin(self):
|
def is_builtin(self):
|
||||||
return not (self.path is None or self.path.endswith('.py'))
|
return not (self.path is None or self.path.endswith('.py'))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user