Skip to content

Commit

Permalink
Improve performance of completion
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster committed Jun 6, 2019
1 parent 4807f19 commit f77a9c8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/completion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<H: Hasher>(&self, state: &mut H) {
self.0.label.hash(state);
}
}

0 comments on commit f77a9c8

Please sign in to comment.