diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-14 17:38:51 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-14 17:38:51 +0000 |
commit | 10bf61b83b2600ed3cb7e7825f1cd0ee83e9b7e7 (patch) | |
tree | 189f987eb5b2925448bb39c27cb31a78fef53fa4 /crates/ra_ide_api/src | |
parent | 9d22704064e60b0670ee0274b54be968b86f92d6 (diff) | |
parent | 5f8ec8aa10d2c012b321d9779037b6320c1f2efb (diff) |
Merge #831
831: tweak postfix completions r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_postfix.rs | 21 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/snapshots/completion_item__postfix_completion_works_for_trivial_path_expression.snap | 76 |
2 files changed, 84 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 10a3c8db7..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 | }; |
16 | use ra_text_edit::TextEditBuilder; | 16 | use ra_text_edit::TextEditBuilder; |
17 | 17 | ||
18 | fn postfix_snippet(ctx: &CompletionContext, label: &str, snippet: &str) -> Builder { | 18 | fn 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,22 +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 | ||
29 | pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | 30 | pub(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, "if", &format!("if {} {{$0}}", receiver_text)).add_to(acc); | 34 | postfix_snippet(ctx, "ref", "&expr", &format!("&{}", 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); | ||
34 | postfix_snippet( | 38 | postfix_snippet( |
35 | ctx, | 39 | ctx, |
36 | "match", | 40 | "match", |
41 | "match expr {}", | ||
37 | &format!("match {} {{\n${{1:_}} => {{$0\\}},\n}}", receiver_text), | 42 | &format!("match {} {{\n${{1:_}} => {{$0\\}},\n}}", receiver_text), |
38 | ) | 43 | ) |
39 | .add_to(acc); | 44 | .add_to(acc); |
40 | postfix_snippet(ctx, "while", &format!("while {} {{\n$0\n}}", receiver_text)).add_to(acc); | 45 | postfix_snippet( |
41 | 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); | ||
42 | } | 53 | } |
43 | } | 54 | } |
44 | 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 bc886ef0b..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,15 +1,17 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-02-03T11:38:42.897384636+00:00" | 2 | created: "2019-02-14T17:38:20.322102467Z" |
3 | creator: [email protected] | 3 | creator: [email protected] |
4 | expression: kind_completions | ||
5 | source: crates/ra_ide_api/src/completion/completion_item.rs | 4 | source: crates/ra_ide_api/src/completion/completion_item.rs |
5 | expression: kind_completions | ||
6 | --- | 6 | --- |
7 | [ | 7 | [ |
8 | CompletionItem { | 8 | CompletionItem { |
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 @@ source: crates/ra_ide_api/src/completion/completion_item.rs | |||
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 @@ source: crates/ra_ide_api/src/completion/completion_item.rs | |||
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 @@ source: crates/ra_ide_api/src/completion/completion_item.rs | |||
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( |
@@ -99,9 +132,36 @@ source: crates/ra_ide_api/src/completion/completion_item.rs | |||
99 | }, | 132 | }, |
100 | CompletionItem { | 133 | CompletionItem { |
101 | completion_kind: Postfix, | 134 | completion_kind: Postfix, |
135 | label: "ref", | ||
136 | kind: None, | ||
137 | detail: Some( | ||
138 | "&expr" | ||
139 | ), | ||
140 | documentation: None, | ||
141 | lookup: None, | ||
142 | insert_text: Some( | ||
143 | "&bar" | ||
144 | ), | ||
145 | insert_text_format: Snippet, | ||
146 | source_range: [76; 76), | ||
147 | text_edit: Some( | ||
148 | TextEdit { | ||
149 | atoms: [ | ||
150 | AtomTextEdit { | ||
151 | delete: [72; 76), | ||
152 | insert: "" | ||
153 | } | ||
154 | ] | ||
155 | } | ||
156 | ) | ||
157 | }, | ||
158 | CompletionItem { | ||
159 | completion_kind: Postfix, | ||
102 | label: "while", | 160 | label: "while", |
103 | kind: None, | 161 | kind: None, |
104 | detail: None, | 162 | detail: Some( |
163 | "while expr {}" | ||
164 | ), | ||
105 | documentation: None, | 165 | documentation: None, |
106 | lookup: None, | 166 | lookup: None, |
107 | insert_text: Some( | 167 | insert_text: Some( |