aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_editor/src/completion.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/crates/ra_editor/src/completion.rs b/crates/ra_editor/src/completion.rs
index 62a63fb04..570d72d66 100644
--- a/crates/ra_editor/src/completion.rs
+++ b/crates/ra_editor/src/completion.rs
@@ -39,6 +39,12 @@ pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionI
39 if is_node::<ast::Param>(name_ref.syntax()) { 39 if is_node::<ast::Param>(name_ref.syntax()) {
40 param_completions(name_ref.syntax(), &mut res); 40 param_completions(name_ref.syntax(), &mut res);
41 } 41 }
42 let name_range = name_ref.syntax().range();
43 let top_node = name_ref.syntax().ancestors().take_while(|it| it.range() == name_range).last().unwrap();
44 match top_node.parent().map(|it| it.kind()) {
45 Some(ROOT) | Some(ITEM_LIST) => complete_mod_item_snippets(&mut res),
46 _ => (),
47 }
42 } 48 }
43 if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), offset) { 49 if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), offset) {
44 if is_node::<ast::Param>(name.syntax()) { 50 if is_node::<ast::Param>(name.syntax()) {
@@ -216,6 +222,15 @@ fn complete_expr_snippets(acc: &mut Vec<CompletionItem>) {
216 ); 222 );
217} 223}
218 224
225fn complete_mod_item_snippets(acc: &mut Vec<CompletionItem>) {
226 acc.push(CompletionItem {
227 label: "tfn".to_string(),
228 lookup: None,
229 snippet: Some("#[test]\nfn $1() {\n $0\n}".to_string()),
230 }
231 );
232}
233
219fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) { 234fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) {
220 let mut shadowed = HashSet::new(); 235 let mut shadowed = HashSet::new();
221 acc.extend( 236 acc.extend(
@@ -506,4 +521,21 @@ mod tests {
506 CompletionItem { label: "SourceRoot", lookup: None, snippet: None }, 521 CompletionItem { label: "SourceRoot", lookup: None, snippet: None },
507 CompletionItem { label: "file_id: FileId", lookup: Some("file_id"), snippet: None }]"#); 522 CompletionItem { label: "file_id: FileId", lookup: Some("file_id"), snippet: None }]"#);
508 } 523 }
524
525 #[test]
526 fn test_tfn_snippet() {
527 // check_snippet_completion(r"
528 // <|>
529 // ",
530 // r##"[CompletionItem { label: "tfn", lookup: None, snippet: Some("#[test]\nfn $1() {\n $0\n}") }]"##,
531 // );
532 check_snippet_completion(r"
533 #[cfg(test)]
534 mod tests {
535 <|>
536 }
537 ",
538 r##"[CompletionItem { label: "tfn", lookup: None, snippet: Some("#[test]\nfn $1() {\n $0\n}") }]"##,
539 );
540 }
509} 541}