aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion/reference_completion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/completion/reference_completion.rs')
-rw-r--r--crates/ra_analysis/src/completion/reference_completion.rs82
1 files changed, 1 insertions, 81 deletions
diff --git a/crates/ra_analysis/src/completion/reference_completion.rs b/crates/ra_analysis/src/completion/reference_completion.rs
index 15ff4c5dd..46d381927 100644
--- a/crates/ra_analysis/src/completion/reference_completion.rs
+++ b/crates/ra_analysis/src/completion/reference_completion.rs
@@ -32,8 +32,6 @@ pub(super) fn completions(
32 if let Some(fn_def) = enclosing_fn { 32 if let Some(fn_def) = enclosing_fn {
33 let scopes = FnScopes::new(fn_def); 33 let scopes = FnScopes::new(fn_def);
34 complete_fn(name_ref, &scopes, acc); 34 complete_fn(name_ref, &scopes, acc);
35 // complete_expr_keywords(&file, fn_def, name_ref, acc);
36 complete_expr_snippets(acc);
37 } 35 }
38 36
39 let module_scope = module.scope(db)?; 37 let module_scope = module.scope(db)?;
@@ -56,19 +54,7 @@ pub(super) fn completions(
56 }); 54 });
57 } 55 }
58 NameRefKind::Path(path) => complete_path(acc, db, module, path)?, 56 NameRefKind::Path(path) => complete_path(acc, db, module, path)?,
59 NameRefKind::BareIdentInMod => { 57 NameRefKind::BareIdentInMod => (),
60 let name_range = name_ref.syntax().range();
61 let top_node = name_ref
62 .syntax()
63 .ancestors()
64 .take_while(|it| it.range() == name_range)
65 .last()
66 .unwrap();
67 match top_node.parent().map(|it| it.kind()) {
68 Some(SOURCE_FILE) | Some(ITEM_LIST) => complete_mod_item_snippets(acc),
69 _ => (),
70 }
71 }
72 } 58 }
73 Ok(()) 59 Ok(())
74} 60}
@@ -162,35 +148,6 @@ fn complete_path(
162 Ok(()) 148 Ok(())
163} 149}
164 150
165fn complete_mod_item_snippets(acc: &mut Completions) {
166 CompletionItem::new("Test function")
167 .lookup_by("tfn")
168 .snippet(
169 "\
170#[test]
171fn ${1:feature}() {
172 $0
173}",
174 )
175 .kind(Snippet)
176 .add_to(acc);
177 CompletionItem::new("pub(crate)")
178 .snippet("pub(crate) $0")
179 .kind(Snippet)
180 .add_to(acc);
181}
182
183fn complete_expr_snippets(acc: &mut Completions) {
184 CompletionItem::new("pd")
185 .snippet("eprintln!(\"$0 = {:?}\", $0);")
186 .kind(Snippet)
187 .add_to(acc);
188 CompletionItem::new("ppd")
189 .snippet("eprintln!(\"$0 = {:#?}\", $0);")
190 .kind(Snippet)
191 .add_to(acc);
192}
193
194#[cfg(test)] 151#[cfg(test)]
195mod tests { 152mod tests {
196 use crate::completion::{CompletionKind, check_completion}; 153 use crate::completion::{CompletionKind, check_completion};
@@ -199,10 +156,6 @@ mod tests {
199 check_completion(code, expected_completions, CompletionKind::Reference); 156 check_completion(code, expected_completions, CompletionKind::Reference);
200 } 157 }
201 158
202 fn check_snippet_completion(code: &str, expected_completions: &str) {
203 check_completion(code, expected_completions, CompletionKind::Snippet);
204 }
205
206 #[test] 159 #[test]
207 fn test_completion_let_scope() { 160 fn test_completion_let_scope() {
208 check_reference_completion( 161 check_reference_completion(
@@ -378,37 +331,4 @@ mod tests {
378 "Spam", 331 "Spam",
379 ); 332 );
380 } 333 }
381
382 #[test]
383 fn completes_snippets_in_expressions() {
384 check_snippet_completion(
385 r"fn foo(x: i32) { <|> }",
386 r##"
387 pd "eprintln!(\"$0 = {:?}\", $0);"
388 ppd "eprintln!(\"$0 = {:#?}\", $0);"
389 "##,
390 );
391 }
392
393 #[test]
394 fn completes_snippets_in_items() {
395 // check_snippet_completion(r"
396 // <|>
397 // ",
398 // r##"[CompletionItem { label: "Test function", lookup: None, snippet: Some("#[test]\nfn test_${1:feature}() {\n$0\n}"##,
399 // );
400 check_snippet_completion(
401 r"
402 #[cfg(test)]
403 mod tests {
404 <|>
405 }
406 ",
407 r##"
408 tfn "Test function" "#[test]\nfn ${1:feature}() {\n $0\n}"
409 pub(crate) "pub(crate) $0"
410 "##,
411 );
412 }
413
414} 334}