aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/lib.rs5
-rw-r--r--crates/ra_hir/src/marks.rs4
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs26
-rw-r--r--crates/ra_ide_api/src/completion/complete_scope.rs17
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs61
-rw-r--r--crates/ra_ide_api/src/lib.rs3
-rw-r--r--crates/ra_ide_api/src/marks.rs3
7 files changed, 72 insertions, 47 deletions
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 33a9ba605..a861ee88e 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -8,8 +8,6 @@
8pub mod db; 8pub mod db;
9#[cfg(test)] 9#[cfg(test)]
10mod mock; 10mod mock;
11#[cfg(test)]
12mod marks;
13mod query_definitions; 11mod query_definitions;
14mod path; 12mod path;
15pub mod source_binder; 13pub mod source_binder;
@@ -29,6 +27,9 @@ mod generics;
29mod code_model_api; 27mod code_model_api;
30mod code_model_impl; 28mod code_model_impl;
31 29
30#[cfg(test)]
31mod marks;
32
32use crate::{ 33use crate::{
33 db::HirDatabase, 34 db::HirDatabase,
34 name::{AsName, KnownName}, 35 name::{AsName, KnownName},
diff --git a/crates/ra_hir/src/marks.rs b/crates/ra_hir/src/marks.rs
index 6aff2c4e1..f4d0c3e59 100644
--- a/crates/ra_hir/src/marks.rs
+++ b/crates/ra_hir/src/marks.rs
@@ -1 +1,3 @@
1test_utils::mark!(name_res_works_for_broken_modules); 1use test_utils::mark;
2
3mark!(name_res_works_for_broken_modules);
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index 804954ee1..6bed299d2 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -121,30 +121,4 @@ mod tests {
121 ", 121 ",
122 ); 122 );
123 } 123 }
124
125 #[test]
126 fn dont_render_function_parens_in_use_item() {
127 check_reference_completion(
128 "dont_render_function_parens_in_use_item",
129 "
130 //- /lib.rs
131 mod m { pub fn foo() {} }
132 use crate::m::f<|>;
133 ",
134 )
135 }
136
137 #[test]
138 fn dont_render_function_parens_if_already_call() {
139 check_reference_completion(
140 "dont_render_function_parens_if_already_call",
141 "
142 //- /lib.rs
143 fn frobnicate() {}
144 fn main() {
145 frob<|>();
146 }
147 ",
148 )
149 }
150} 124}
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs
index 20fc77f06..f837bb1db 100644
--- a/crates/ra_ide_api/src/completion/complete_scope.rs
+++ b/crates/ra_ide_api/src/completion/complete_scope.rs
@@ -175,21 +175,4 @@ mod tests {
175 check_reference_completion("self_in_methods", r"impl S { fn foo(&self) { <|> } }") 175 check_reference_completion("self_in_methods", r"impl S { fn foo(&self) { <|> } }")
176 } 176 }
177 177
178 #[test]
179 fn inserts_parens_for_function_calls() {
180 check_reference_completion(
181 "inserts_parens_for_function_calls1",
182 r"
183 fn no_args() {}
184 fn main() { no_<|> }
185 ",
186 );
187 check_reference_completion(
188 "inserts_parens_for_function_calls2",
189 r"
190 fn with_args(x: i32, y: String) {}
191 fn main() { with_<|> }
192 ",
193 );
194 }
195} 178}
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}
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 3c53e75ac..3502bfd2e 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -26,6 +26,9 @@ mod syntax_highlighting;
26mod parent_module; 26mod parent_module;
27mod rename; 27mod rename;
28 28
29#[cfg(test)]
30mod marks;
31
29use std::{fmt, sync::Arc}; 32use std::{fmt, sync::Arc};
30 33
31use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit}; 34use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit};
diff --git a/crates/ra_ide_api/src/marks.rs b/crates/ra_ide_api/src/marks.rs
new file mode 100644
index 000000000..b4a726ef0
--- /dev/null
+++ b/crates/ra_ide_api/src/marks.rs
@@ -0,0 +1,3 @@
1use test_utils::mark;
2
3mark!(inserts_parens_for_function_calls);