From 74406ca8ea45df8b44cb38ecba4a5b561038c4a0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 21 Dec 2018 14:02:14 +0300 Subject: introduce completion_item module --- crates/ra_analysis/src/completion.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'crates/ra_analysis/src/completion.rs') diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index f480af611..ed1b6dd0c 100644 --- a/crates/ra_analysis/src/completion.rs +++ b/crates/ra_analysis/src/completion.rs @@ -1,3 +1,4 @@ +mod completion_item; mod reference_completion; use ra_editor::find_node_at_offset; @@ -17,15 +18,7 @@ use crate::{ Cancelable, FilePosition }; -#[derive(Debug)] -pub struct CompletionItem { - /// What user sees in pop-up - pub label: String, - /// What string is used for filtering, defaults to label - pub lookup: Option, - /// What is inserted, defaults to label - pub snippet: Option, -} +pub use crate::completion::completion_item::CompletionItem; pub(crate) fn completions( db: &db::RootDatabase, @@ -63,6 +56,10 @@ pub(crate) fn completions( Ok(res) } +/// Complete repeated parametes, both name and type. For example, if all +/// functions in a file have a `spam: &mut Spam` parameter, a completion with +/// `spam: &mut Spam` insert text/label and `spam` lookup string will be +/// suggested. fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec) { let mut params = FxHashMap::default(); for node in ctx.ancestors() { @@ -81,13 +78,7 @@ fn param_completions(ctx: SyntaxNodeRef, acc: &mut Vec) { Some((label, lookup)) } }) - .for_each(|(label, lookup)| { - acc.push(CompletionItem { - label, - lookup: Some(lookup), - snippet: None, - }) - }); + .for_each(|(label, lookup)| CompletionItem::new(label).lookup_by(lookup).add_to(acc)); fn process<'a, N: ast::FnDefOwner<'a>>( node: N, -- cgit v1.2.3