aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion/completion_item.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/completion/completion_item.rs')
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs61
1 files changed, 60 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index 680fd8d1b..48be812a0 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -3,9 +3,10 @@ use hir::PerNs;
3use crate::completion::completion_context::CompletionContext; 3use crate::completion::completion_context::CompletionContext;
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{self, AstNode}, 5 ast::{self, AstNode},
6 TextRange 6 TextRange,
7}; 7};
8use ra_text_edit::TextEdit; 8use ra_text_edit::TextEdit;
9use test_utils::tested_by;
9 10
10/// `CompletionItem` describes a single completion variant in the editor pop-up. 11/// `CompletionItem` describes a single completion variant in the editor pop-up.
11/// It is basically a POD with various properties. To construct a 12/// It is basically a POD with various properties. To construct a
@@ -255,6 +256,7 @@ impl Builder {
255 ) -> Builder { 256 ) -> Builder {
256 // If not an import, add parenthesis automatically. 257 // If not an import, add parenthesis automatically.
257 if ctx.use_item_syntax.is_none() && !ctx.is_call { 258 if ctx.use_item_syntax.is_none() && !ctx.is_call {
259 tested_by!(inserts_parens_for_function_calls);
258 if function.signature(ctx.db).params().is_empty() { 260 if function.signature(ctx.db).params().is_empty() {
259 self.insert_text = Some(format!("{}()$0", self.label)); 261 self.insert_text = Some(format!("{}()$0", self.label));
260 } else { 262 } else {
@@ -344,3 +346,60 @@ pub(crate) fn check_completion(test_name: &str, code: &str, kind: CompletionKind
344 .collect(); 346 .collect();
345 assert_debug_snapshot_matches!(test_name, kind_completions); 347 assert_debug_snapshot_matches!(test_name, kind_completions);
346} 348}
349
350#[cfg(test)]
351mod tests {
352 use test_utils::covers;
353
354 use super::*;
355
356 fn check_reference_completion(code: &str, expected_completions: &str) {
357 check_completion(code, expected_completions, CompletionKind::Reference);
358 }
359
360 #[test]
361 fn inserts_parens_for_function_calls() {
362 covers!(inserts_parens_for_function_calls);
363 check_reference_completion(
364 "inserts_parens_for_function_calls1",
365 r"
366 fn no_args() {}
367 fn main() { no_<|> }
368 ",
369 );
370 check_reference_completion(
371 "inserts_parens_for_function_calls2",
372 r"
373 fn with_args(x: i32, y: String) {}
374 fn main() { with_<|> }
375 ",
376 );
377 }
378
379 #[test]
380 fn dont_render_function_parens_in_use_item() {
381 check_reference_completion(
382 "dont_render_function_parens_in_use_item",
383 "
384 //- /lib.rs
385 mod m { pub fn foo() {} }
386 use crate::m::f<|>;
387 ",
388 )
389 }
390
391 #[test]
392 fn dont_render_function_parens_if_already_call() {
393 check_reference_completion(
394 "dont_render_function_parens_if_already_call",
395 "
396 //- /lib.rs
397 fn frobnicate() {}
398 fn main() {
399 frob<|>();
400 }
401 ",
402 )
403 }
404
405}