From 5f25f244ca777628a8de03f0ccad004b95b9453d Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 3 Nov 2012 23:41:31 +0100 Subject: [PATCH 1/3] Add Function.get_call_signature --- jedi/parsing.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/jedi/parsing.py b/jedi/parsing.py index 94140fbe..dfb6212e 100644 --- a/jedi/parsing.py +++ b/jedi/parsing.py @@ -385,6 +385,31 @@ class Function(Scope): debug.warning("multiple names in param %s" % n) return n + def get_call_signature(self, width=72): + """ + Generate call signature of this function. + + :param width: Fold lines if a line is longer than this value. + :type width: int + + :rtype: str + """ + l = self.name.names[-1] + '(' + lines = [] + for (i, p) in enumerate(self.params): + code = p.get_code(False) + if i != len(self.params) - 1: + code += ', ' + if len(l + code) > width: + lines.append(l[:-1] if l[-1] == ' ' else l) + l = code + else: + l += code + if l: + lines.append(l) + lines[-1] += ')' + return '\n'.join(lines) + class Flow(Scope): """ From 5c76b2043497960be42cd8218ad33b15461396e9 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 3 Nov 2012 23:52:37 +0100 Subject: [PATCH 2/3] Add call signature to Completion.doc --- jedi/api.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jedi/api.py b/jedi/api.py index 0734b28a..977ad601 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -72,9 +72,13 @@ class Completion(object): @property def doc(self): - """ Returns the docstring `__doc__` for any object """ + """ Return a document string for this completion object. """ try: - return str(self.name.parent().docstr) + parent = self.name.parent() + docstr = str(parent.docstr) + if hasattr(parent, 'get_call_signature'): + docstr = parent.get_call_signature() + '\n\n' + docstr + return docstr except AttributeError: return '' From 5a20cd166585e91e9db4a425ab4a4ea23e8905ac Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 4 Nov 2012 11:26:06 +0100 Subject: [PATCH 3/3] Use AttributeError instead of hasattr --- jedi/api.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jedi/api.py b/jedi/api.py index 977ad601..169b4afe 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -75,10 +75,11 @@ class Completion(object): """ Return a document string for this completion object. """ try: parent = self.name.parent() - docstr = str(parent.docstr) - if hasattr(parent, 'get_call_signature'): - docstr = parent.get_call_signature() + '\n\n' + docstr - return docstr + try: + return '%s\n\n%s' % (parent.get_call_signature(), + parent.docstr) + except AttributeError: + return str(parent.docstr) except AttributeError: return ''