aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs80
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs80
2 files changed, 80 insertions, 80 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index 95bdd59b4..91e32b3c8 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -411,83 +411,3 @@ pub(crate) fn check_completion(test_name: &str, code: &str, kind: CompletionKind
411 let kind_completions = do_completion(code, kind); 411 let kind_completions = do_completion(code, kind);
412 assert_debug_snapshot_matches!(test_name, kind_completions); 412 assert_debug_snapshot_matches!(test_name, kind_completions);
413} 413}
414
415#[cfg(test)]
416mod tests {
417 use test_utils::covers;
418
419 use super::*;
420
421 fn check_reference_completion(code: &str, expected_completions: &str) {
422 check_completion(code, expected_completions, CompletionKind::Reference);
423 }
424
425 #[test]
426 fn inserts_parens_for_function_calls() {
427 covers!(inserts_parens_for_function_calls);
428 check_reference_completion(
429 "inserts_parens_for_function_calls1",
430 r"
431 fn no_args() {}
432 fn main() { no_<|> }
433 ",
434 );
435 check_reference_completion(
436 "inserts_parens_for_function_calls2",
437 r"
438 fn with_args(x: i32, y: String) {}
439 fn main() { with_<|> }
440 ",
441 );
442 check_reference_completion(
443 "inserts_parens_for_function_calls3",
444 r"
445 struct S {}
446 impl S {
447 fn foo(&self) {}
448 }
449 fn bar(s: &S) {
450 s.f<|>
451 }
452 ",
453 )
454 }
455
456 #[test]
457 fn dont_render_function_parens_in_use_item() {
458 check_reference_completion(
459 "dont_render_function_parens_in_use_item",
460 "
461 //- /lib.rs
462 mod m { pub fn foo() {} }
463 use crate::m::f<|>;
464 ",
465 )
466 }
467
468 #[test]
469 fn dont_render_function_parens_if_already_call() {
470 check_reference_completion(
471 "dont_render_function_parens_if_already_call",
472 "
473 //- /lib.rs
474 fn frobnicate() {}
475 fn main() {
476 frob<|>();
477 }
478 ",
479 );
480 check_reference_completion(
481 "dont_render_function_parens_if_already_call_assoc_fn",
482 "
483 //- /lib.rs
484 struct Foo {}
485 impl Foo { fn new() -> Foo {} }
486 fn main() {
487 Foo::ne<|>();
488 }
489 ",
490 )
491 }
492
493}
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index 9c31a3801..057dbc21a 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -70,3 +70,83 @@ fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Opti
70 let node = function.source(ctx.db).1; 70 let node = function.source(ctx.db).1;
71 function_label(&node) 71 function_label(&node)
72} 72}
73
74#[cfg(test)]
75mod tests {
76 use test_utils::covers;
77
78 use crate::completion::{CompletionKind, completion_item::check_completion};
79
80 fn check_reference_completion(code: &str, expected_completions: &str) {
81 check_completion(code, expected_completions, CompletionKind::Reference);
82 }
83
84 #[test]
85 fn inserts_parens_for_function_calls() {
86 covers!(inserts_parens_for_function_calls);
87 check_reference_completion(
88 "inserts_parens_for_function_calls1",
89 r"
90 fn no_args() {}
91 fn main() { no_<|> }
92 ",
93 );
94 check_reference_completion(
95 "inserts_parens_for_function_calls2",
96 r"
97 fn with_args(x: i32, y: String) {}
98 fn main() { with_<|> }
99 ",
100 );
101 check_reference_completion(
102 "inserts_parens_for_function_calls3",
103 r"
104 struct S {}
105 impl S {
106 fn foo(&self) {}
107 }
108 fn bar(s: &S) {
109 s.f<|>
110 }
111 ",
112 )
113 }
114
115 #[test]
116 fn dont_render_function_parens_in_use_item() {
117 check_reference_completion(
118 "dont_render_function_parens_in_use_item",
119 "
120 //- /lib.rs
121 mod m { pub fn foo() {} }
122 use crate::m::f<|>;
123 ",
124 )
125 }
126
127 #[test]
128 fn dont_render_function_parens_if_already_call() {
129 check_reference_completion(
130 "dont_render_function_parens_if_already_call",
131 "
132 //- /lib.rs
133 fn frobnicate() {}
134 fn main() {
135 frob<|>();
136 }
137 ",
138 );
139 check_reference_completion(
140 "dont_render_function_parens_if_already_call_assoc_fn",
141 "
142 //- /lib.rs
143 struct Foo {}
144 impl Foo { fn new() -> Foo {} }
145 fn main() {
146 Foo::ne<|>();
147 }
148 ",
149 )
150 }
151
152}