aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-02-14 17:18:49 +0000
committerAleksey Kladov <[email protected]>2019-02-14 17:38:26 +0000
commit5f8ec8aa10d2c012b321d9779037b6320c1f2efb (patch)
tree4650e24ec64a870f96b2227bf6eb74f54a9fb501 /crates
parent434f1520df2965240809e37ea144c61f564c1c39 (diff)
tweak postfix completions
* better label * add refm for &mut
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/completion/complete_postfix.rs22
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__postfix_completion_works_for_trivial_path_expression.snap51
2 files changed, 60 insertions, 13 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_postfix.rs b/crates/ra_ide_api/src/completion/complete_postfix.rs
index b7dc50c34..d1f6b9433 100644
--- a/crates/ra_ide_api/src/completion/complete_postfix.rs
+++ b/crates/ra_ide_api/src/completion/complete_postfix.rs
@@ -15,7 +15,7 @@ use ra_syntax::{
15}; 15};
16use ra_text_edit::TextEditBuilder; 16use ra_text_edit::TextEditBuilder;
17 17
18fn postfix_snippet(ctx: &CompletionContext, label: &str, snippet: &str) -> Builder { 18fn postfix_snippet(ctx: &CompletionContext, label: &str, detail: &str, snippet: &str) -> Builder {
19 let replace_range = ctx.source_range(); 19 let replace_range = ctx.source_range();
20 let receiver_range = ctx.dot_receiver.expect("no receiver available").syntax().range(); 20 let receiver_range = ctx.dot_receiver.expect("no receiver available").syntax().range();
21 let delete_range = TextRange::from_to(receiver_range.start(), replace_range.start()); 21 let delete_range = TextRange::from_to(receiver_range.start(), replace_range.start());
@@ -23,23 +23,33 @@ fn postfix_snippet(ctx: &CompletionContext, label: &str, snippet: &str) -> Build
23 builder.delete(delete_range); 23 builder.delete(delete_range);
24 CompletionItem::new(CompletionKind::Postfix, replace_range, label) 24 CompletionItem::new(CompletionKind::Postfix, replace_range, label)
25 .snippet(snippet) 25 .snippet(snippet)
26 .detail(detail)
26 .text_edit(builder.finish()) 27 .text_edit(builder.finish())
27} 28}
28 29
29pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { 30pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
30 if let Some(dot_receiver) = ctx.dot_receiver { 31 if let Some(dot_receiver) = ctx.dot_receiver {
31 let receiver_text = dot_receiver.syntax().text().to_string(); 32 let receiver_text = dot_receiver.syntax().text().to_string();
32 postfix_snippet(ctx, "not", &format!("!{}", receiver_text)).add_to(acc); 33 postfix_snippet(ctx, "not", "!expr", &format!("!{}", receiver_text)).add_to(acc);
33 postfix_snippet(ctx, "ref", &format!("&{}", receiver_text)).add_to(acc); 34 postfix_snippet(ctx, "ref", "&expr", &format!("&{}", receiver_text)).add_to(acc);
34 postfix_snippet(ctx, "if", &format!("if {} {{$0}}", receiver_text)).add_to(acc); 35 postfix_snippet(ctx, "mref", "&mut expr", &format!("&mut {}", receiver_text)).add_to(acc);
36 postfix_snippet(ctx, "if", "if expr {}", &format!("if {} {{$0}}", receiver_text))
37 .add_to(acc);
35 postfix_snippet( 38 postfix_snippet(
36 ctx, 39 ctx,
37 "match", 40 "match",
41 "match expr {}",
38 &format!("match {} {{\n${{1:_}} => {{$0\\}},\n}}", receiver_text), 42 &format!("match {} {{\n${{1:_}} => {{$0\\}},\n}}", receiver_text),
39 ) 43 )
40 .add_to(acc); 44 .add_to(acc);
41 postfix_snippet(ctx, "while", &format!("while {} {{\n$0\n}}", receiver_text)).add_to(acc); 45 postfix_snippet(
42 postfix_snippet(ctx, "dbg", &format!("dbg!({})", receiver_text)).add_to(acc); 46 ctx,
47 "while",
48 "while expr {}",
49 &format!("while {} {{\n$0\n}}", receiver_text),
50 )
51 .add_to(acc);
52 postfix_snippet(ctx, "dbg", "dbg!(expr)", &format!("dbg!({})", receiver_text)).add_to(acc);
43 } 53 }
44} 54}
45 55
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__postfix_completion_works_for_trivial_path_expression.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__postfix_completion_works_for_trivial_path_expression.snap
index 3e16c8e79..6f4351445 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__postfix_completion_works_for_trivial_path_expression.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__postfix_completion_works_for_trivial_path_expression.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-02-14T17:12:57.412523988Z" 2created: "2019-02-14T17:38:20.322102467Z"
3creator: [email protected] 3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs 4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions 5expression: kind_completions
@@ -9,7 +9,9 @@ expression: kind_completions
9 completion_kind: Postfix, 9 completion_kind: Postfix,
10 label: "dbg", 10 label: "dbg",
11 kind: None, 11 kind: None,
12 detail: None, 12 detail: Some(
13 "dbg!(expr)"
14 ),
13 documentation: None, 15 documentation: None,
14 lookup: None, 16 lookup: None,
15 insert_text: Some( 17 insert_text: Some(
@@ -32,7 +34,9 @@ expression: kind_completions
32 completion_kind: Postfix, 34 completion_kind: Postfix,
33 label: "if", 35 label: "if",
34 kind: None, 36 kind: None,
35 detail: None, 37 detail: Some(
38 "if expr {}"
39 ),
36 documentation: None, 40 documentation: None,
37 lookup: None, 41 lookup: None,
38 insert_text: Some( 42 insert_text: Some(
@@ -55,7 +59,9 @@ expression: kind_completions
55 completion_kind: Postfix, 59 completion_kind: Postfix,
56 label: "match", 60 label: "match",
57 kind: None, 61 kind: None,
58 detail: None, 62 detail: Some(
63 "match expr {}"
64 ),
59 documentation: None, 65 documentation: None,
60 lookup: None, 66 lookup: None,
61 insert_text: Some( 67 insert_text: Some(
@@ -76,9 +82,36 @@ expression: kind_completions
76 }, 82 },
77 CompletionItem { 83 CompletionItem {
78 completion_kind: Postfix, 84 completion_kind: Postfix,
85 label: "mref",
86 kind: None,
87 detail: Some(
88 "&mut expr"
89 ),
90 documentation: None,
91 lookup: None,
92 insert_text: Some(
93 "&mut bar"
94 ),
95 insert_text_format: Snippet,
96 source_range: [76; 76),
97 text_edit: Some(
98 TextEdit {
99 atoms: [
100 AtomTextEdit {
101 delete: [72; 76),
102 insert: ""
103 }
104 ]
105 }
106 )
107 },
108 CompletionItem {
109 completion_kind: Postfix,
79 label: "not", 110 label: "not",
80 kind: None, 111 kind: None,
81 detail: None, 112 detail: Some(
113 "!expr"
114 ),
82 documentation: None, 115 documentation: None,
83 lookup: None, 116 lookup: None,
84 insert_text: Some( 117 insert_text: Some(
@@ -101,7 +134,9 @@ expression: kind_completions
101 completion_kind: Postfix, 134 completion_kind: Postfix,
102 label: "ref", 135 label: "ref",
103 kind: None, 136 kind: None,
104 detail: None, 137 detail: Some(
138 "&expr"
139 ),
105 documentation: None, 140 documentation: None,
106 lookup: None, 141 lookup: None,
107 insert_text: Some( 142 insert_text: Some(
@@ -124,7 +159,9 @@ expression: kind_completions
124 completion_kind: Postfix, 159 completion_kind: Postfix,
125 label: "while", 160 label: "while",
126 kind: None, 161 kind: None,
127 detail: None, 162 detail: Some(
163 "while expr {}"
164 ),
128 documentation: None, 165 documentation: None,
129 lookup: None, 166 lookup: None,
130 insert_text: Some( 167 insert_text: Some(