From f77a9c896491780e31bf5ea356acfaf3787ed40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20F=C3=B6rster?= Date: Thu, 6 Jun 2019 15:20:21 +0200 Subject: [PATCH] Improve performance of completion --- src/completion/mod.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/completion/mod.rs b/src/completion/mod.rs index c3257cc4f..87f58999a 100644 --- a/src/completion/mod.rs +++ b/src/completion/mod.rs @@ -26,6 +26,7 @@ use crate::feature::{ConcatProvider, FeatureProvider, FeatureRequest}; use futures_boxed::boxed; use itertools::Itertools; use lsp_types::{CompletionItem, CompletionParams}; +use std::hash::{Hash, Hasher}; pub const COMPLETION_LIMIT: usize = 50; @@ -74,8 +75,27 @@ impl FeatureProvider for CompletionProvider { .execute(request) .await .into_iter() - .unique_by(|item| item.label.clone()) + .map(LabeledCompletionItem) + .unique() + .map(|item| item.0) .take(COMPLETION_LIMIT) .collect() } } + +#[derive(Debug, Clone)] +struct LabeledCompletionItem(CompletionItem); + +impl PartialEq for LabeledCompletionItem { + fn eq(&self, other: &Self) -> bool { + self.0.label == other.0.label + } +} + +impl Eq for LabeledCompletionItem {} + +impl Hash for LabeledCompletionItem { + fn hash(&self, state: &mut H) { + self.0.label.hash(state); + } +}