From 406233b62df1ca37203425cbfe9547f48e530325 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sat, 29 Dec 2012 01:59:34 +0100 Subject: [PATCH] ignore duplicates of completion outputs, #97 --- jedi/api.py | 8 +++++++- jedi/api_classes.py | 4 ++++ jedi/settings.py | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/jedi/api.py b/jedi/api.py index 914859aa..dcb66e05 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -146,6 +146,7 @@ class Script(object): needs_dot = not dot and path comps = [] + comp_dct = {} for c, s in set(completions): n = c.names[-1] if settings.case_insensitive_completion \ @@ -155,7 +156,12 @@ class Script(object): self._parser.user_stmt, n): new = api_classes.Completion(c, needs_dot, len(like), s) - comps.append(new) + n = new.complete + if n in comp_dct and not settings.no_completion_duplicates: + comp_dct[n].same_name_completions.append(new) + else: + comp_dct[n] = new + comps.append(new) debug.speed('complete end') diff --git a/jedi/api_classes.py b/jedi/api_classes.py index 0ce100d7..a4fefffe 100644 --- a/jedi/api_classes.py +++ b/jedi/api_classes.py @@ -163,6 +163,10 @@ class Completion(BaseDefinition): self.like_name_length = like_name_length self.base = base + # Completion objects with the same Completion name (which means + # duplicate items in the completion) + self.same_name_completions = [] + self._followed_definitions = None @property diff --git a/jedi/settings.py b/jedi/settings.py index dc4bfa2e..d9ffa24b 100644 --- a/jedi/settings.py +++ b/jedi/settings.py @@ -14,6 +14,10 @@ add_dot_after_module = False # Removed it again, because in VIM that is not very practical. add_bracket_after_function = False +# If set, completions with the same name don't appear in the output anymore, +# but are in the `same_name_completions` attribute. +no_completion_duplicates = False + # ---------------- # parser # ----------------