aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-21 22:34:22 +0000
committerAleksey Kladov <[email protected]>2018-12-21 22:42:26 +0000
commit284e89406906b97eec8e0f91bce2955a5e94b880 (patch)
treea49f15f70dc20c4429afd62d2d5027d6a8efc607
parent25dda42f3773b1d002a5809c0182c2adc6c47027 (diff)
cleanup
-rw-r--r--crates/ra_analysis/src/completion/complete_keyword.rs12
-rw-r--r--crates/ra_analysis/src/completion/complete_path.rs8
-rw-r--r--crates/ra_analysis/src/completion/complete_scope.rs12
-rw-r--r--crates/ra_analysis/src/completion/complete_snippet.rs31
4 files changed, 34 insertions, 29 deletions
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::{
5 SyntaxKind::*, SyntaxNodeRef, 5 SyntaxKind::*, SyntaxNodeRef,
6}; 6};
7 7
8use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind::*}; 8use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind};
9
10fn keyword(kw: &str, snippet: &str) -> CompletionItem {
11 CompletionItem::new(CompletionKind::Keyword, kw)
12 .snippet(snippet)
13 .build()
14}
9 15
10pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { 16pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) {
11 if !ctx.is_trivial_path { 17 if !ctx.is_trivial_path {
@@ -60,10 +66,6 @@ fn complete_return(fn_def: ast::FnDef, is_stmt: bool) -> Option<CompletionItem>
60 Some(keyword("return", snip)) 66 Some(keyword("return", snip))
61} 67}
62 68
63fn keyword(kw: &str, snippet: &str) -> CompletionItem {
64 CompletionItem::new(Keyword, kw).snippet(snippet).build()
65}
66
67#[cfg(test)] 69#[cfg(test)]
68mod tests { 70mod tests {
69 use crate::completion::{CompletionKind, check_completion}; 71 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 @@
1use crate::{ 1use crate::{
2 Cancelable, 2 Cancelable,
3 completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext}, 3 completion::{CompletionItem, Completions, CompletionKind, CompletionContext},
4}; 4};
5 5
6pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { 6pub(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
17 _ => return Ok(()), 17 _ => return Ok(()),
18 }; 18 };
19 let module_scope = target_module.scope(ctx.db)?; 19 let module_scope = target_module.scope(ctx.db)?;
20 module_scope 20 module_scope.entries().for_each(|(name, _res)| {
21 .entries() 21 CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc)
22 .for_each(|(name, _res)| CompletionItem::new(Reference, name.to_string()).add_to(acc)); 22 });
23 Ok(()) 23 Ok(())
24} 24}
25 25
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;
3 3
4use crate::{ 4use crate::{
5 Cancelable, 5 Cancelable,
6 completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext}, 6 completion::{CompletionItem, Completions, CompletionKind, CompletionContext},
7}; 7};
8 8
9pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { 9pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> {
@@ -29,7 +29,9 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
29 } 29 }
30 } 30 }
31 }) 31 })
32 .for_each(|(name, _res)| CompletionItem::new(Reference, name.to_string()).add_to(acc)); 32 .for_each(|(name, _res)| {
33 CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc)
34 });
33 } 35 }
34 36
35 Ok(()) 37 Ok(())
@@ -41,9 +43,11 @@ fn complete_fn(acc: &mut Completions, scopes: &hir::FnScopes, offset: TextUnit)
41 .scope_chain_for_offset(offset) 43 .scope_chain_for_offset(offset)
42 .flat_map(|scope| scopes.entries(scope).iter()) 44 .flat_map(|scope| scopes.entries(scope).iter())
43 .filter(|entry| shadowed.insert(entry.name())) 45 .filter(|entry| shadowed.insert(entry.name()))
44 .for_each(|entry| CompletionItem::new(Reference, entry.name().to_string()).add_to(acc)); 46 .for_each(|entry| {
47 CompletionItem::new(CompletionKind::Reference, entry.name().to_string()).add_to(acc)
48 });
45 if scopes.self_param.is_some() { 49 if scopes.self_param.is_some() {
46 CompletionItem::new(Reference, "self").add_to(acc); 50 CompletionItem::new(CompletionKind::Reference, "self").add_to(acc);
47 } 51 }
48} 52}
49 53
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 @@
1use crate::completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext}; 1use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext, completion_item::Builder};
2
3fn snippet(label: &str, snippet: &str) -> Builder {
4 CompletionItem::new(CompletionKind::Snippet, label).snippet(snippet)
5}
2 6
3pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { 7pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) {
4 if !(ctx.is_trivial_path && ctx.enclosing_fn.is_some()) { 8 if !(ctx.is_trivial_path && ctx.enclosing_fn.is_some()) {
5 return; 9 return;
6 } 10 }
7 CompletionItem::new(Snippet, "pd") 11 snippet("pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc);
8 .snippet("eprintln!(\"$0 = {:?}\", $0);") 12 snippet("ppd", "eprintln!(\"$0 = {:#?}\", $0);").add_to(acc);
9 .add_to(acc);
10 CompletionItem::new(Snippet, "ppd")
11 .snippet("eprintln!(\"$0 = {:#?}\", $0);")
12 .add_to(acc);
13} 13}
14 14
15pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { 15pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) {
16 if !ctx.is_new_item { 16 if !ctx.is_new_item {
17 return; 17 return;
18 } 18 }
19 CompletionItem::new(Snippet, "Test function") 19 snippet(
20 .lookup_by("tfn") 20 "Test function",
21 .snippet( 21 "\
22 "\
23#[test] 22#[test]
24fn ${1:feature}() { 23fn ${1:feature}() {
25 $0 24 $0
26}", 25}",
27 ) 26 )
28 .add_to(acc); 27 .lookup_by("tfn")
29 CompletionItem::new(Snippet, "pub(crate)") 28 .add_to(acc);
30 .snippet("pub(crate) $0") 29
31 .add_to(acc); 30 snippet("pub(crate)", "pub(crate) $0").add_to(acc);
32} 31}
33 32
34#[cfg(test)] 33#[cfg(test)]