From d6e973206444f338e5b5028edf725ffc87d73ee0 Mon Sep 17 00:00:00 2001 From: David Halter Date: Thu, 15 Aug 2013 13:56:43 +0430 Subject: [PATCH] added a method 'api_classes.Completion.name_with_signs', because this is important for #280 --- jedi/api_classes.py | 43 +++++++++++++++++++++++++++++++------------ jedi/utils.py | 3 ++- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/jedi/api_classes.py b/jedi/api_classes.py index 4e7181ed..e2e019c4 100644 --- a/jedi/api_classes.py +++ b/jedi/api_classes.py @@ -321,16 +321,7 @@ class Completion(BaseDefinition): self._followed_definitions = None - @property - def complete(self): - """ - Return the rest of the word, e.g. completing ``isinstance``:: - - isinstan# <-- Cursor is here - - would return the string 'ce'. It also adds additional stuff, depending - on your `settings.py`. - """ + def _complete(self, like_name): dot = '.' if self._needs_dot else '' append = '' if settings.add_bracket_after_function \ @@ -342,7 +333,23 @@ class Completion(BaseDefinition): append += '.' if isinstance(self._base, pr.Param): append += '=' - return dot + self._name.names[-1][self._like_name_length:] + append + + name = self._name.names[-1] + if like_name: + name = name[self._like_name_length:] + return dot + name + append + + @property + def complete(self): + """ + Return the rest of the word, e.g. completing ``isinstance``:: + + isinstan# <-- Cursor is here + + would return the string 'ce'. It also adds additional stuff, depending + on your `settings.py`. + """ + return self._complete(True) @property def name(self): @@ -352,10 +359,22 @@ class Completion(BaseDefinition): isinstan - would return 'isinstance'. + would return `isinstance`. """ return unicode(self._name.names[-1]) + @property + def name_with_signs(self): + """ + Similar to :meth:`Completion.name`, but like :meth:`Completion.name` + returns also the signs, for example:: + + list() + + would return ``.append`` and others. + """ + return self._complete(False) + @property def word(self): """ diff --git a/jedi/utils.py b/jedi/utils.py index 74ba7ebd..8f939501 100644 --- a/jedi/utils.py +++ b/jedi/utils.py @@ -93,7 +93,8 @@ def setup_readline(namespace=__main__.__dict__): self.matches.append(path + dot + name) else: completions = interpreter.completions() - self.matches = [text + c.complete for c in completions] + self.matches = [path + dot + c.name_with_signs + for c in completions] try: return self.matches[state] except IndexError: