From 284e89406906b97eec8e0f91bce2955a5e94b880 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 22 Dec 2018 01:34:22 +0300 Subject: cleanup --- .../ra_analysis/src/completion/complete_keyword.rs | 12 +++++---- crates/ra_analysis/src/completion/complete_path.rs | 8 +++--- .../ra_analysis/src/completion/complete_scope.rs | 12 ++++++--- .../ra_analysis/src/completion/complete_snippet.rs | 31 +++++++++++----------- 4 files changed, 34 insertions(+), 29 deletions(-) (limited to 'crates') diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs index 1e6d7008d..2c7891920 100644 --- a/crates/ra_analysis/src/completion/complete_keyword.rs +++ b/crates/ra_analysis/src/completion/complete_keyword.rs @@ -5,7 +5,13 @@ use ra_syntax::{ SyntaxKind::*, SyntaxNodeRef, }; -use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind::*}; +use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind}; + +fn keyword(kw: &str, snippet: &str) -> CompletionItem { + CompletionItem::new(CompletionKind::Keyword, kw) + .snippet(snippet) + .build() +} pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { if !ctx.is_trivial_path { @@ -60,10 +66,6 @@ fn complete_return(fn_def: ast::FnDef, is_stmt: bool) -> Option Some(keyword("return", snip)) } -fn keyword(kw: &str, snippet: &str) -> CompletionItem { - CompletionItem::new(Keyword, kw).snippet(snippet).build() -} - #[cfg(test)] mod tests { use crate::completion::{CompletionKind, check_completion}; diff --git a/crates/ra_analysis/src/completion/complete_path.rs b/crates/ra_analysis/src/completion/complete_path.rs index 692502bb2..802f4abe4 100644 --- a/crates/ra_analysis/src/completion/complete_path.rs +++ b/crates/ra_analysis/src/completion/complete_path.rs @@ -1,6 +1,6 @@ use crate::{ Cancelable, - completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext}, + completion::{CompletionItem, Completions, CompletionKind, CompletionContext}, }; pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { @@ -17,9 +17,9 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C _ => return Ok(()), }; let module_scope = target_module.scope(ctx.db)?; - module_scope - .entries() - .for_each(|(name, _res)| CompletionItem::new(Reference, name.to_string()).add_to(acc)); + module_scope.entries().for_each(|(name, _res)| { + CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc) + }); Ok(()) } diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs index f39b98d62..fb87be4b1 100644 --- a/crates/ra_analysis/src/completion/complete_scope.rs +++ b/crates/ra_analysis/src/completion/complete_scope.rs @@ -3,7 +3,7 @@ use ra_syntax::TextUnit; use crate::{ Cancelable, - completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext}, + completion::{CompletionItem, Completions, CompletionKind, CompletionContext}, }; pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { @@ -29,7 +29,9 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> } } }) - .for_each(|(name, _res)| CompletionItem::new(Reference, name.to_string()).add_to(acc)); + .for_each(|(name, _res)| { + CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc) + }); } Ok(()) @@ -41,9 +43,11 @@ fn complete_fn(acc: &mut Completions, scopes: &hir::FnScopes, offset: TextUnit) .scope_chain_for_offset(offset) .flat_map(|scope| scopes.entries(scope).iter()) .filter(|entry| shadowed.insert(entry.name())) - .for_each(|entry| CompletionItem::new(Reference, entry.name().to_string()).add_to(acc)); + .for_each(|entry| { + CompletionItem::new(CompletionKind::Reference, entry.name().to_string()).add_to(acc) + }); if scopes.self_param.is_some() { - CompletionItem::new(Reference, "self").add_to(acc); + CompletionItem::new(CompletionKind::Reference, "self").add_to(acc); } } diff --git a/crates/ra_analysis/src/completion/complete_snippet.rs b/crates/ra_analysis/src/completion/complete_snippet.rs index f0ad45fec..1feb332b9 100644 --- a/crates/ra_analysis/src/completion/complete_snippet.rs +++ b/crates/ra_analysis/src/completion/complete_snippet.rs @@ -1,34 +1,33 @@ -use crate::completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext}; +use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext, completion_item::Builder}; + +fn snippet(label: &str, snippet: &str) -> Builder { + CompletionItem::new(CompletionKind::Snippet, label).snippet(snippet) +} pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { if !(ctx.is_trivial_path && ctx.enclosing_fn.is_some()) { return; } - CompletionItem::new(Snippet, "pd") - .snippet("eprintln!(\"$0 = {:?}\", $0);") - .add_to(acc); - CompletionItem::new(Snippet, "ppd") - .snippet("eprintln!(\"$0 = {:#?}\", $0);") - .add_to(acc); + snippet("pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc); + snippet("ppd", "eprintln!(\"$0 = {:#?}\", $0);").add_to(acc); } pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { if !ctx.is_new_item { return; } - CompletionItem::new(Snippet, "Test function") - .lookup_by("tfn") - .snippet( - "\ + snippet( + "Test function", + "\ #[test] fn ${1:feature}() { $0 }", - ) - .add_to(acc); - CompletionItem::new(Snippet, "pub(crate)") - .snippet("pub(crate) $0") - .add_to(acc); + ) + .lookup_by("tfn") + .add_to(acc); + + snippet("pub(crate)", "pub(crate) $0").add_to(acc); } #[cfg(test)] -- cgit v1.2.3