aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src/completion.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-28 19:14:13 +0100
committerAleksey Kladov <[email protected]>2018-08-28 19:14:13 +0100
commitd351ae67a97f15e7cf95787fc853d2f775416108 (patch)
tree7ff7f09c826626dcc277dc702c0dcbd8ca0dda8b /crates/libeditor/src/completion.rs
parent2257c08cb159a30492bf2aec172539b1dd504700 (diff)
Smart return completion
Diffstat (limited to 'crates/libeditor/src/completion.rs')
-rw-r--r--crates/libeditor/src/completion.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/crates/libeditor/src/completion.rs b/crates/libeditor/src/completion.rs
index 65527db62..cfb1c0d1b 100644
--- a/crates/libeditor/src/completion.rs
+++ b/crates/libeditor/src/completion.rs
@@ -75,9 +75,13 @@ fn complete_keywords(file: &File, fn_def: Option<ast::FnDef>, name_ref: ast::Nam
75 } 75 }
76 } 76 }
77 77
78 // if let Some(fn_def) = fn_def { 78 if let Some(fn_def) = fn_def {
79 // acc.push(keyword("return", "")) 79 if fn_def.ret_type().is_some() {
80 // } 80 acc.push(keyword("return", "return $0;"))
81 } else {
82 acc.push(keyword("return", "return;"))
83 }
84 }
81 85
82 fn keyword(kw: &str, snip: &str) -> CompletionItem { 86 fn keyword(kw: &str, snip: &str) -> CompletionItem {
83 CompletionItem { 87 CompletionItem {
@@ -189,7 +193,8 @@ mod tests {
189 ", r#"[CompletionItem { name: "if", snippet: Some("if $0 { }") }, 193 ", r#"[CompletionItem { name: "if", snippet: Some("if $0 { }") },
190 CompletionItem { name: "match", snippet: Some("match $0 { }") }, 194 CompletionItem { name: "match", snippet: Some("match $0 { }") },
191 CompletionItem { name: "while", snippet: Some("while $0 { }") }, 195 CompletionItem { name: "while", snippet: Some("while $0 { }") },
192 CompletionItem { name: "loop", snippet: Some("loop {$0}") }]"#); 196 CompletionItem { name: "loop", snippet: Some("loop {$0}") },
197 CompletionItem { name: "return", snippet: Some("return;") }]"#);
193 } 198 }
194 199
195 #[test] 200 #[test]
@@ -205,6 +210,20 @@ mod tests {
205 CompletionItem { name: "while", snippet: Some("while $0 { }") }, 210 CompletionItem { name: "while", snippet: Some("while $0 { }") },
206 CompletionItem { name: "loop", snippet: Some("loop {$0}") }, 211 CompletionItem { name: "loop", snippet: Some("loop {$0}") },
207 CompletionItem { name: "else", snippet: Some("else {$0}") }, 212 CompletionItem { name: "else", snippet: Some("else {$0}") },
208 CompletionItem { name: "else if", snippet: Some("else if $0 { }") }]"#); 213 CompletionItem { name: "else if", snippet: Some("else if $0 { }") },
214 CompletionItem { name: "return", snippet: Some("return;") }]"#);
215 }
216
217 #[test]
218 fn test_completion_return_value() {
219 check_snippet_completion(r"
220 fn quux() -> i32{
221 <|>
222 }
223 ", r#"[CompletionItem { name: "if", snippet: Some("if $0 { }") },
224 CompletionItem { name: "match", snippet: Some("match $0 { }") },
225 CompletionItem { name: "while", snippet: Some("while $0 { }") },
226 CompletionItem { name: "loop", snippet: Some("loop {$0}") },
227 CompletionItem { name: "return", snippet: Some("return $0;") }]"#);
209 } 228 }
210} 229}