@@ -38,12 +38,10 @@ def get_completions(
3838 m = self .compiled_grammar .match_prefix (document .text_before_cursor )
3939
4040 if m :
41- completions = self ._remove_duplicates (
41+ yield from self ._remove_duplicates (
4242 self ._get_completions_for_match (m , complete_event )
4343 )
4444
45- yield from completions
46-
4745 def _get_completions_for_match (
4846 self , match : Match , complete_event : CompleteEvent
4947 ) -> Iterable [Completion ]:
@@ -82,14 +80,21 @@ def _get_completions_for_match(
8280 display_meta = completion .display_meta ,
8381 )
8482
85- def _remove_duplicates (self , items : Iterable [Completion ]) -> list [Completion ]:
83+ def _remove_duplicates (self , items : Iterable [Completion ]) -> Iterable [Completion ]:
8684 """
8785 Remove duplicates, while keeping the order.
8886 (Sometimes we have duplicates, because the there several matches of the
8987 same grammar, each yielding similar completions.)
9088 """
91- result : list [Completion ] = []
92- for i in items :
93- if i not in result :
94- result .append (i )
95- return result
89+
90+ def hash_completion (completion : Completion ) -> tuple [str , int ]:
91+ return completion .text , completion .start_position
92+
93+ yielded_so_far : set [tuple [str , int ]] = set ()
94+
95+ for completion in items :
96+ hash_value = hash_completion (completion )
97+
98+ if hash_value not in yielded_so_far :
99+ yielded_so_far .add (hash_value )
100+ yield completion
0 commit comments