diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/call_info.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide/src/completion.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_qualified_path.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_unqualified_path.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 24 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/test_utils.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/diagnostics.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide/src/lib.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide/src/marks.rs | 16 | ||||
-rw-r--r-- | crates/ra_ide/src/parent_module.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide/src/references.rs | 3 | ||||
-rw-r--r-- | crates/ra_ide/src/references/rename.rs | 15 | ||||
-rw-r--r-- | crates/ra_ide/src/runnables.rs | 72 | ||||
-rw-r--r-- | crates/ra_ide/src/typing.rs | 19 |
15 files changed, 119 insertions, 90 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index 780a03c13..aa039e6fc 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs | |||
@@ -5,7 +5,7 @@ use ra_syntax::{ | |||
5 | ast::{self, ArgListOwner}, | 5 | ast::{self, ArgListOwner}, |
6 | match_ast, AstNode, SyntaxNode, SyntaxToken, | 6 | match_ast, AstNode, SyntaxNode, SyntaxToken, |
7 | }; | 7 | }; |
8 | use test_utils::tested_by; | 8 | use test_utils::mark; |
9 | 9 | ||
10 | use crate::{CallInfo, FilePosition, FunctionSignature}; | 10 | use crate::{CallInfo, FilePosition, FunctionSignature}; |
11 | 11 | ||
@@ -84,7 +84,7 @@ fn call_info_for_token(sema: &Semantics<RootDatabase>, token: SyntaxToken) -> Op | |||
84 | 84 | ||
85 | let arg_list_range = arg_list.syntax().text_range(); | 85 | let arg_list_range = arg_list.syntax().text_range(); |
86 | if !arg_list_range.contains_inclusive(token.text_range().start()) { | 86 | if !arg_list_range.contains_inclusive(token.text_range().start()) { |
87 | tested_by!(call_info_bad_offset); | 87 | mark::hit!(call_info_bad_offset); |
88 | return None; | 88 | return None; |
89 | } | 89 | } |
90 | 90 | ||
@@ -213,7 +213,7 @@ impl CallInfo { | |||
213 | 213 | ||
214 | #[cfg(test)] | 214 | #[cfg(test)] |
215 | mod tests { | 215 | mod tests { |
216 | use test_utils::covers; | 216 | use test_utils::mark; |
217 | 217 | ||
218 | use crate::mock_analysis::single_file_with_position; | 218 | use crate::mock_analysis::single_file_with_position; |
219 | 219 | ||
@@ -529,7 +529,7 @@ By default this method stops actor's `Context`."# | |||
529 | 529 | ||
530 | #[test] | 530 | #[test] |
531 | fn call_info_bad_offset() { | 531 | fn call_info_bad_offset() { |
532 | covers!(call_info_bad_offset); | 532 | mark::check!(call_info_bad_offset); |
533 | let (analysis, position) = single_file_with_position( | 533 | let (analysis, position) = single_file_with_position( |
534 | r#"fn foo(x: u32, y: u32) -> u32 {x + y} | 534 | r#"fn foo(x: u32, y: u32) -> u32 {x + y} |
535 | fn bar() { foo <|> (3, ); }"#, | 535 | fn bar() { foo <|> (3, ); }"#, |
diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs index 8bdc43b1a..191300704 100644 --- a/crates/ra_ide/src/completion.rs +++ b/crates/ra_ide/src/completion.rs | |||
@@ -59,8 +59,8 @@ pub use crate::completion::{ | |||
59 | /// with ordering of completions (currently this is done by the client). | 59 | /// with ordering of completions (currently this is done by the client). |
60 | pub(crate) fn completions( | 60 | pub(crate) fn completions( |
61 | db: &RootDatabase, | 61 | db: &RootDatabase, |
62 | position: FilePosition, | ||
63 | config: &CompletionConfig, | 62 | config: &CompletionConfig, |
63 | position: FilePosition, | ||
64 | ) -> Option<Completions> { | 64 | ) -> Option<Completions> { |
65 | let ctx = CompletionContext::new(db, position, config)?; | 65 | let ctx = CompletionContext::new(db, position, config)?; |
66 | 66 | ||
diff --git a/crates/ra_ide/src/completion/complete_qualified_path.rs b/crates/ra_ide/src/completion/complete_qualified_path.rs index db7430454..02ac0166b 100644 --- a/crates/ra_ide/src/completion/complete_qualified_path.rs +++ b/crates/ra_ide/src/completion/complete_qualified_path.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | use hir::{Adt, HasVisibility, PathResolution, ScopeDef}; | 3 | use hir::{Adt, HasVisibility, PathResolution, ScopeDef}; |
4 | use ra_syntax::AstNode; | 4 | use ra_syntax::AstNode; |
5 | use rustc_hash::FxHashSet; | 5 | use rustc_hash::FxHashSet; |
6 | use test_utils::tested_by; | 6 | use test_utils::mark; |
7 | 7 | ||
8 | use crate::completion::{CompletionContext, Completions}; | 8 | use crate::completion::{CompletionContext, Completions}; |
9 | 9 | ||
@@ -40,7 +40,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon | |||
40 | if let Some(name_ref) = ctx.name_ref_syntax.as_ref() { | 40 | if let Some(name_ref) = ctx.name_ref_syntax.as_ref() { |
41 | if name_ref.syntax().text() == name.to_string().as_str() { | 41 | if name_ref.syntax().text() == name.to_string().as_str() { |
42 | // for `use self::foo<|>`, don't suggest `foo` as a completion | 42 | // for `use self::foo<|>`, don't suggest `foo` as a completion |
43 | tested_by!(dont_complete_current_use); | 43 | mark::hit!(dont_complete_current_use); |
44 | continue; | 44 | continue; |
45 | } | 45 | } |
46 | } | 46 | } |
@@ -147,7 +147,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon | |||
147 | 147 | ||
148 | #[cfg(test)] | 148 | #[cfg(test)] |
149 | mod tests { | 149 | mod tests { |
150 | use test_utils::covers; | 150 | use test_utils::mark; |
151 | 151 | ||
152 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | 152 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
153 | use insta::assert_debug_snapshot; | 153 | use insta::assert_debug_snapshot; |
@@ -158,7 +158,7 @@ mod tests { | |||
158 | 158 | ||
159 | #[test] | 159 | #[test] |
160 | fn dont_complete_current_use() { | 160 | fn dont_complete_current_use() { |
161 | covers!(dont_complete_current_use); | 161 | mark::check!(dont_complete_current_use); |
162 | let completions = do_completion(r"use self::foo<|>;", CompletionKind::Reference); | 162 | let completions = do_completion(r"use self::foo<|>;", CompletionKind::Reference); |
163 | assert!(completions.is_empty()); | 163 | assert!(completions.is_empty()); |
164 | } | 164 | } |
diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index bd40af1cb..db791660a 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Completion of names from the current scope, e.g. locals and imported items. | 1 | //! Completion of names from the current scope, e.g. locals and imported items. |
2 | 2 | ||
3 | use hir::ScopeDef; | 3 | use hir::ScopeDef; |
4 | use test_utils::tested_by; | 4 | use test_utils::mark; |
5 | 5 | ||
6 | use crate::completion::{CompletionContext, Completions}; | 6 | use crate::completion::{CompletionContext, Completions}; |
7 | use hir::{Adt, ModuleDef, Type}; | 7 | use hir::{Adt, ModuleDef, Type}; |
@@ -30,7 +30,7 @@ pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
30 | if ctx.use_item_syntax.is_some() { | 30 | if ctx.use_item_syntax.is_some() { |
31 | if let (ScopeDef::Unknown, Some(name_ref)) = (&res, &ctx.name_ref_syntax) { | 31 | if let (ScopeDef::Unknown, Some(name_ref)) = (&res, &ctx.name_ref_syntax) { |
32 | if name_ref.syntax().text() == name.to_string().as_str() { | 32 | if name_ref.syntax().text() == name.to_string().as_str() { |
33 | tested_by!(self_fulfilling_completion); | 33 | mark::hit!(self_fulfilling_completion); |
34 | return; | 34 | return; |
35 | } | 35 | } |
36 | } | 36 | } |
@@ -66,7 +66,7 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T | |||
66 | #[cfg(test)] | 66 | #[cfg(test)] |
67 | mod tests { | 67 | mod tests { |
68 | use insta::assert_debug_snapshot; | 68 | use insta::assert_debug_snapshot; |
69 | use test_utils::covers; | 69 | use test_utils::mark; |
70 | 70 | ||
71 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | 71 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
72 | 72 | ||
@@ -76,7 +76,7 @@ mod tests { | |||
76 | 76 | ||
77 | #[test] | 77 | #[test] |
78 | fn self_fulfilling_completion() { | 78 | fn self_fulfilling_completion() { |
79 | covers!(self_fulfilling_completion); | 79 | mark::check!(self_fulfilling_completion); |
80 | assert_debug_snapshot!( | 80 | assert_debug_snapshot!( |
81 | do_reference_completion( | 81 | do_reference_completion( |
82 | r#" | 82 | r#" |
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 077cf9647..440ffa31d 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | use hir::{Docs, HasAttrs, HasSource, HirDisplay, ModPath, ScopeDef, StructKind, Type}; | 3 | use hir::{Docs, HasAttrs, HasSource, HirDisplay, ModPath, ScopeDef, StructKind, Type}; |
4 | use ra_syntax::ast::NameOwner; | 4 | use ra_syntax::ast::NameOwner; |
5 | use stdx::SepBy; | 5 | use stdx::SepBy; |
6 | use test_utils::tested_by; | 6 | use test_utils::mark; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | completion::{ | 9 | completion::{ |
@@ -121,7 +121,7 @@ impl Completions { | |||
121 | _ => false, | 121 | _ => false, |
122 | }; | 122 | }; |
123 | if has_non_default_type_params { | 123 | if has_non_default_type_params { |
124 | tested_by!(inserts_angle_brackets_for_generics); | 124 | mark::hit!(inserts_angle_brackets_for_generics); |
125 | completion_item = completion_item | 125 | completion_item = completion_item |
126 | .lookup_by(local_name.clone()) | 126 | .lookup_by(local_name.clone()) |
127 | .label(format!("{}<…>", local_name)) | 127 | .label(format!("{}<…>", local_name)) |
@@ -176,7 +176,7 @@ impl Completions { | |||
176 | } | 176 | } |
177 | None if needs_bang => builder.insert_text(format!("{}!", name)), | 177 | None if needs_bang => builder.insert_text(format!("{}!", name)), |
178 | _ => { | 178 | _ => { |
179 | tested_by!(dont_insert_macro_call_parens_unncessary); | 179 | mark::hit!(dont_insert_macro_call_parens_unncessary); |
180 | builder.insert_text(name) | 180 | builder.insert_text(name) |
181 | } | 181 | } |
182 | }; | 182 | }; |
@@ -330,14 +330,14 @@ pub(crate) fn compute_score( | |||
330 | // FIXME: this should not fall back to string equality. | 330 | // FIXME: this should not fall back to string equality. |
331 | let ty = &ty.display(ctx.db).to_string(); | 331 | let ty = &ty.display(ctx.db).to_string(); |
332 | let (active_name, active_type) = if let Some(record_field) = &ctx.record_field_syntax { | 332 | let (active_name, active_type) = if let Some(record_field) = &ctx.record_field_syntax { |
333 | tested_by!(test_struct_field_completion_in_record_lit); | 333 | mark::hit!(test_struct_field_completion_in_record_lit); |
334 | let (struct_field, _local) = ctx.sema.resolve_record_field(record_field)?; | 334 | let (struct_field, _local) = ctx.sema.resolve_record_field(record_field)?; |
335 | ( | 335 | ( |
336 | struct_field.name(ctx.db).to_string(), | 336 | struct_field.name(ctx.db).to_string(), |
337 | struct_field.signature_ty(ctx.db).display(ctx.db).to_string(), | 337 | struct_field.signature_ty(ctx.db).display(ctx.db).to_string(), |
338 | ) | 338 | ) |
339 | } else if let Some(active_parameter) = &ctx.active_parameter { | 339 | } else if let Some(active_parameter) = &ctx.active_parameter { |
340 | tested_by!(test_struct_field_completion_in_func_call); | 340 | mark::hit!(test_struct_field_completion_in_func_call); |
341 | (active_parameter.name.clone(), active_parameter.ty.clone()) | 341 | (active_parameter.name.clone(), active_parameter.ty.clone()) |
342 | } else { | 342 | } else { |
343 | return None; | 343 | return None; |
@@ -398,7 +398,7 @@ impl Builder { | |||
398 | None => return self, | 398 | None => return self, |
399 | }; | 399 | }; |
400 | // If not an import, add parenthesis automatically. | 400 | // If not an import, add parenthesis automatically. |
401 | tested_by!(inserts_parens_for_function_calls); | 401 | mark::hit!(inserts_parens_for_function_calls); |
402 | 402 | ||
403 | let (snippet, label) = if params.is_empty() { | 403 | let (snippet, label) = if params.is_empty() { |
404 | (format!("{}()$0", name), format!("{}()", name)) | 404 | (format!("{}()$0", name), format!("{}()", name)) |
@@ -457,7 +457,7 @@ fn guess_macro_braces(macro_name: &str, docs: &str) -> (&'static str, &'static s | |||
457 | #[cfg(test)] | 457 | #[cfg(test)] |
458 | mod tests { | 458 | mod tests { |
459 | use insta::assert_debug_snapshot; | 459 | use insta::assert_debug_snapshot; |
460 | use test_utils::covers; | 460 | use test_utils::mark; |
461 | 461 | ||
462 | use crate::completion::{ | 462 | use crate::completion::{ |
463 | test_utils::{do_completion, do_completion_with_options}, | 463 | test_utils::{do_completion, do_completion_with_options}, |
@@ -607,7 +607,7 @@ mod tests { | |||
607 | 607 | ||
608 | #[test] | 608 | #[test] |
609 | fn inserts_parens_for_function_calls() { | 609 | fn inserts_parens_for_function_calls() { |
610 | covers!(inserts_parens_for_function_calls); | 610 | mark::check!(inserts_parens_for_function_calls); |
611 | assert_debug_snapshot!( | 611 | assert_debug_snapshot!( |
612 | do_reference_completion( | 612 | do_reference_completion( |
613 | r" | 613 | r" |
@@ -992,7 +992,7 @@ mod tests { | |||
992 | 992 | ||
993 | #[test] | 993 | #[test] |
994 | fn inserts_angle_brackets_for_generics() { | 994 | fn inserts_angle_brackets_for_generics() { |
995 | covers!(inserts_angle_brackets_for_generics); | 995 | mark::check!(inserts_angle_brackets_for_generics); |
996 | assert_debug_snapshot!( | 996 | assert_debug_snapshot!( |
997 | do_reference_completion( | 997 | do_reference_completion( |
998 | r" | 998 | r" |
@@ -1115,7 +1115,7 @@ mod tests { | |||
1115 | 1115 | ||
1116 | #[test] | 1116 | #[test] |
1117 | fn dont_insert_macro_call_parens_unncessary() { | 1117 | fn dont_insert_macro_call_parens_unncessary() { |
1118 | covers!(dont_insert_macro_call_parens_unncessary); | 1118 | mark::check!(dont_insert_macro_call_parens_unncessary); |
1119 | assert_debug_snapshot!( | 1119 | assert_debug_snapshot!( |
1120 | do_reference_completion( | 1120 | do_reference_completion( |
1121 | r" | 1121 | r" |
@@ -1181,7 +1181,7 @@ mod tests { | |||
1181 | 1181 | ||
1182 | #[test] | 1182 | #[test] |
1183 | fn test_struct_field_completion_in_func_call() { | 1183 | fn test_struct_field_completion_in_func_call() { |
1184 | covers!(test_struct_field_completion_in_func_call); | 1184 | mark::check!(test_struct_field_completion_in_func_call); |
1185 | assert_debug_snapshot!( | 1185 | assert_debug_snapshot!( |
1186 | do_reference_completion( | 1186 | do_reference_completion( |
1187 | r" | 1187 | r" |
@@ -1271,7 +1271,7 @@ mod tests { | |||
1271 | 1271 | ||
1272 | #[test] | 1272 | #[test] |
1273 | fn test_struct_field_completion_in_record_lit() { | 1273 | fn test_struct_field_completion_in_record_lit() { |
1274 | covers!(test_struct_field_completion_in_record_lit); | 1274 | mark::check!(test_struct_field_completion_in_record_lit); |
1275 | assert_debug_snapshot!( | 1275 | assert_debug_snapshot!( |
1276 | do_reference_completion( | 1276 | do_reference_completion( |
1277 | r" | 1277 | r" |
diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs index eb90b5279..bf22452a2 100644 --- a/crates/ra_ide/src/completion/test_utils.rs +++ b/crates/ra_ide/src/completion/test_utils.rs | |||
@@ -20,7 +20,7 @@ pub(crate) fn do_completion_with_options( | |||
20 | } else { | 20 | } else { |
21 | single_file_with_position(code) | 21 | single_file_with_position(code) |
22 | }; | 22 | }; |
23 | let completions = analysis.completions(position, options).unwrap().unwrap(); | 23 | let completions = analysis.completions(options, position).unwrap().unwrap(); |
24 | let completion_items: Vec<CompletionItem> = completions.into(); | 24 | let completion_items: Vec<CompletionItem> = completions.into(); |
25 | let mut kind_completions: Vec<CompletionItem> = | 25 | let mut kind_completions: Vec<CompletionItem> = |
26 | completion_items.into_iter().filter(|c| c.completion_kind == kind).collect(); | 26 | completion_items.into_iter().filter(|c| c.completion_kind == kind).collect(); |
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index 87a0b80f1..54c2bcc09 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs | |||
@@ -629,6 +629,7 @@ mod tests { | |||
629 | }, | 629 | }, |
630 | ], | 630 | ], |
631 | cursor_position: None, | 631 | cursor_position: None, |
632 | is_snippet: false, | ||
632 | }, | 633 | }, |
633 | ), | 634 | ), |
634 | severity: Error, | 635 | severity: Error, |
@@ -685,6 +686,7 @@ mod tests { | |||
685 | ], | 686 | ], |
686 | file_system_edits: [], | 687 | file_system_edits: [], |
687 | cursor_position: None, | 688 | cursor_position: None, |
689 | is_snippet: false, | ||
688 | }, | 690 | }, |
689 | ), | 691 | ), |
690 | severity: Error, | 692 | severity: Error, |
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 150895abb..90e85d419 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -93,7 +93,7 @@ pub(crate) fn reference_definition( | |||
93 | 93 | ||
94 | #[cfg(test)] | 94 | #[cfg(test)] |
95 | mod tests { | 95 | mod tests { |
96 | use test_utils::{assert_eq_text, covers}; | 96 | use test_utils::assert_eq_text; |
97 | 97 | ||
98 | use crate::mock_analysis::analysis_and_position; | 98 | use crate::mock_analysis::analysis_and_position; |
99 | 99 | ||
@@ -208,7 +208,6 @@ mod tests { | |||
208 | 208 | ||
209 | #[test] | 209 | #[test] |
210 | fn goto_def_for_macros() { | 210 | fn goto_def_for_macros() { |
211 | covers!(ra_ide_db::goto_def_for_macros); | ||
212 | check_goto( | 211 | check_goto( |
213 | " | 212 | " |
214 | //- /lib.rs | 213 | //- /lib.rs |
@@ -225,7 +224,6 @@ mod tests { | |||
225 | 224 | ||
226 | #[test] | 225 | #[test] |
227 | fn goto_def_for_macros_from_other_crates() { | 226 | fn goto_def_for_macros_from_other_crates() { |
228 | covers!(ra_ide_db::goto_def_for_macros); | ||
229 | check_goto( | 227 | check_goto( |
230 | " | 228 | " |
231 | //- /lib.rs | 229 | //- /lib.rs |
@@ -245,7 +243,6 @@ mod tests { | |||
245 | 243 | ||
246 | #[test] | 244 | #[test] |
247 | fn goto_def_for_use_alias() { | 245 | fn goto_def_for_use_alias() { |
248 | covers!(ra_ide_db::goto_def_for_use_alias); | ||
249 | check_goto( | 246 | check_goto( |
250 | " | 247 | " |
251 | //- /lib.rs | 248 | //- /lib.rs |
@@ -370,7 +367,6 @@ mod tests { | |||
370 | 367 | ||
371 | #[test] | 368 | #[test] |
372 | fn goto_def_for_methods() { | 369 | fn goto_def_for_methods() { |
373 | covers!(ra_ide_db::goto_def_for_methods); | ||
374 | check_goto( | 370 | check_goto( |
375 | " | 371 | " |
376 | //- /lib.rs | 372 | //- /lib.rs |
@@ -390,7 +386,6 @@ mod tests { | |||
390 | 386 | ||
391 | #[test] | 387 | #[test] |
392 | fn goto_def_for_fields() { | 388 | fn goto_def_for_fields() { |
393 | covers!(ra_ide_db::goto_def_for_fields); | ||
394 | check_goto( | 389 | check_goto( |
395 | r" | 390 | r" |
396 | //- /lib.rs | 391 | //- /lib.rs |
@@ -409,7 +404,6 @@ mod tests { | |||
409 | 404 | ||
410 | #[test] | 405 | #[test] |
411 | fn goto_def_for_record_fields() { | 406 | fn goto_def_for_record_fields() { |
412 | covers!(ra_ide_db::goto_def_for_record_fields); | ||
413 | check_goto( | 407 | check_goto( |
414 | r" | 408 | r" |
415 | //- /lib.rs | 409 | //- /lib.rs |
@@ -430,7 +424,6 @@ mod tests { | |||
430 | 424 | ||
431 | #[test] | 425 | #[test] |
432 | fn goto_def_for_record_pat_fields() { | 426 | fn goto_def_for_record_pat_fields() { |
433 | covers!(ra_ide_db::goto_def_for_record_field_pats); | ||
434 | check_goto( | 427 | check_goto( |
435 | r" | 428 | r" |
436 | //- /lib.rs | 429 | //- /lib.rs |
@@ -873,7 +866,6 @@ mod tests { | |||
873 | 866 | ||
874 | #[test] | 867 | #[test] |
875 | fn goto_def_for_field_init_shorthand() { | 868 | fn goto_def_for_field_init_shorthand() { |
876 | covers!(ra_ide_db::goto_def_for_field_init_shorthand); | ||
877 | check_goto( | 869 | check_goto( |
878 | " | 870 | " |
879 | //- /lib.rs | 871 | //- /lib.rs |
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 78149ddfc..83cb498f7 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -43,8 +43,6 @@ mod expand_macro; | |||
43 | mod ssr; | 43 | mod ssr; |
44 | 44 | ||
45 | #[cfg(test)] | 45 | #[cfg(test)] |
46 | mod marks; | ||
47 | #[cfg(test)] | ||
48 | mod test_utils; | 46 | mod test_utils; |
49 | 47 | ||
50 | use std::sync::Arc; | 48 | use std::sync::Arc; |
@@ -82,7 +80,7 @@ pub use crate::{ | |||
82 | }; | 80 | }; |
83 | 81 | ||
84 | pub use hir::Documentation; | 82 | pub use hir::Documentation; |
85 | pub use ra_assists::AssistId; | 83 | pub use ra_assists::{AssistConfig, AssistId}; |
86 | pub use ra_db::{ | 84 | pub use ra_db::{ |
87 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, | 85 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, |
88 | }; | 86 | }; |
@@ -458,17 +456,17 @@ impl Analysis { | |||
458 | /// Computes completions at the given position. | 456 | /// Computes completions at the given position. |
459 | pub fn completions( | 457 | pub fn completions( |
460 | &self, | 458 | &self, |
461 | position: FilePosition, | ||
462 | config: &CompletionConfig, | 459 | config: &CompletionConfig, |
460 | position: FilePosition, | ||
463 | ) -> Cancelable<Option<Vec<CompletionItem>>> { | 461 | ) -> Cancelable<Option<Vec<CompletionItem>>> { |
464 | self.with_db(|db| completion::completions(db, position, config).map(Into::into)) | 462 | self.with_db(|db| completion::completions(db, config, position).map(Into::into)) |
465 | } | 463 | } |
466 | 464 | ||
467 | /// Computes assists (aka code actions aka intentions) for the given | 465 | /// Computes assists (aka code actions aka intentions) for the given |
468 | /// position. | 466 | /// position. |
469 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<Assist>> { | 467 | pub fn assists(&self, config: &AssistConfig, frange: FileRange) -> Cancelable<Vec<Assist>> { |
470 | self.with_db(|db| { | 468 | self.with_db(|db| { |
471 | ra_assists::Assist::resolved(db, frange) | 469 | ra_assists::Assist::resolved(db, config, frange) |
472 | .into_iter() | 470 | .into_iter() |
473 | .map(|assist| Assist { | 471 | .map(|assist| Assist { |
474 | id: assist.assist.id, | 472 | id: assist.assist.id, |
diff --git a/crates/ra_ide/src/marks.rs b/crates/ra_ide/src/marks.rs deleted file mode 100644 index 51ca4dde3..000000000 --- a/crates/ra_ide/src/marks.rs +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | //! See test_utils/src/marks.rs | ||
2 | |||
3 | test_utils::marks!( | ||
4 | inserts_angle_brackets_for_generics | ||
5 | inserts_parens_for_function_calls | ||
6 | call_info_bad_offset | ||
7 | dont_complete_current_use | ||
8 | test_resolve_parent_module_on_module_decl | ||
9 | search_filters_by_range | ||
10 | dont_insert_macro_call_parens_unncessary | ||
11 | self_fulfilling_completion | ||
12 | test_struct_field_completion_in_func_call | ||
13 | test_struct_field_completion_in_record_lit | ||
14 | test_rename_struct_field_for_shorthand | ||
15 | test_rename_local_for_field_shorthand | ||
16 | ); | ||
diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs index aaf4460df..a083fb1eb 100644 --- a/crates/ra_ide/src/parent_module.rs +++ b/crates/ra_ide/src/parent_module.rs | |||
@@ -7,7 +7,7 @@ use ra_syntax::{ | |||
7 | algo::find_node_at_offset, | 7 | algo::find_node_at_offset, |
8 | ast::{self, AstNode}, | 8 | ast::{self, AstNode}, |
9 | }; | 9 | }; |
10 | use test_utils::tested_by; | 10 | use test_utils::mark; |
11 | 11 | ||
12 | use crate::NavigationTarget; | 12 | use crate::NavigationTarget; |
13 | 13 | ||
@@ -25,7 +25,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na | |||
25 | .item_list() | 25 | .item_list() |
26 | .map_or(false, |it| it.syntax().text_range().contains_inclusive(position.offset)) | 26 | .map_or(false, |it| it.syntax().text_range().contains_inclusive(position.offset)) |
27 | { | 27 | { |
28 | tested_by!(test_resolve_parent_module_on_module_decl); | 28 | mark::hit!(test_resolve_parent_module_on_module_decl); |
29 | module = m.syntax().ancestors().skip(1).find_map(ast::Module::cast); | 29 | module = m.syntax().ancestors().skip(1).find_map(ast::Module::cast); |
30 | } | 30 | } |
31 | } | 31 | } |
@@ -57,7 +57,7 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> { | |||
57 | mod tests { | 57 | mod tests { |
58 | use ra_cfg::CfgOptions; | 58 | use ra_cfg::CfgOptions; |
59 | use ra_db::Env; | 59 | use ra_db::Env; |
60 | use test_utils::covers; | 60 | use test_utils::mark; |
61 | 61 | ||
62 | use crate::{ | 62 | use crate::{ |
63 | mock_analysis::{analysis_and_position, MockAnalysis}, | 63 | mock_analysis::{analysis_and_position, MockAnalysis}, |
@@ -81,7 +81,7 @@ mod tests { | |||
81 | 81 | ||
82 | #[test] | 82 | #[test] |
83 | fn test_resolve_parent_module_on_module_decl() { | 83 | fn test_resolve_parent_module_on_module_decl() { |
84 | covers!(test_resolve_parent_module_on_module_decl); | 84 | mark::check!(test_resolve_parent_module_on_module_decl); |
85 | let (analysis, pos) = analysis_and_position( | 85 | let (analysis, pos) = analysis_and_position( |
86 | " | 86 | " |
87 | //- /lib.rs | 87 | //- /lib.rs |
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 074284b42..96444bf6a 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs | |||
@@ -190,8 +190,6 @@ fn get_struct_def_name_for_struct_literal_search( | |||
190 | 190 | ||
191 | #[cfg(test)] | 191 | #[cfg(test)] |
192 | mod tests { | 192 | mod tests { |
193 | use test_utils::covers; | ||
194 | |||
195 | use crate::{ | 193 | use crate::{ |
196 | mock_analysis::{analysis_and_position, single_file_with_position, MockAnalysis}, | 194 | mock_analysis::{analysis_and_position, single_file_with_position, MockAnalysis}, |
197 | Declaration, Reference, ReferenceSearchResult, SearchScope, | 195 | Declaration, Reference, ReferenceSearchResult, SearchScope, |
@@ -301,7 +299,6 @@ mod tests { | |||
301 | 299 | ||
302 | #[test] | 300 | #[test] |
303 | fn search_filters_by_range() { | 301 | fn search_filters_by_range() { |
304 | covers!(ra_ide_db::search_filters_by_range); | ||
305 | let code = r#" | 302 | let code = r#" |
306 | fn foo() { | 303 | fn foo() { |
307 | let spam<|> = 92; | 304 | let spam<|> = 92; |
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 410dae75c..62ec8d85d 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs | |||
@@ -9,7 +9,7 @@ use ra_syntax::{ | |||
9 | }; | 9 | }; |
10 | use ra_text_edit::TextEdit; | 10 | use ra_text_edit::TextEdit; |
11 | use std::convert::TryInto; | 11 | use std::convert::TryInto; |
12 | use test_utils::tested_by; | 12 | use test_utils::mark; |
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
15 | references::find_all_refs, FilePosition, FileSystemEdit, RangeInfo, Reference, ReferenceKind, | 15 | references::find_all_refs, FilePosition, FileSystemEdit, RangeInfo, Reference, ReferenceKind, |
@@ -57,13 +57,13 @@ fn source_edit_from_reference(reference: Reference, new_name: &str) -> SourceFil | |||
57 | let file_id = reference.file_range.file_id; | 57 | let file_id = reference.file_range.file_id; |
58 | let range = match reference.kind { | 58 | let range = match reference.kind { |
59 | ReferenceKind::FieldShorthandForField => { | 59 | ReferenceKind::FieldShorthandForField => { |
60 | tested_by!(test_rename_struct_field_for_shorthand); | 60 | mark::hit!(test_rename_struct_field_for_shorthand); |
61 | replacement_text.push_str(new_name); | 61 | replacement_text.push_str(new_name); |
62 | replacement_text.push_str(": "); | 62 | replacement_text.push_str(": "); |
63 | TextRange::new(reference.file_range.range.start(), reference.file_range.range.start()) | 63 | TextRange::new(reference.file_range.range.start(), reference.file_range.range.start()) |
64 | } | 64 | } |
65 | ReferenceKind::FieldShorthandForLocal => { | 65 | ReferenceKind::FieldShorthandForLocal => { |
66 | tested_by!(test_rename_local_for_field_shorthand); | 66 | mark::hit!(test_rename_local_for_field_shorthand); |
67 | replacement_text.push_str(": "); | 67 | replacement_text.push_str(": "); |
68 | replacement_text.push_str(new_name); | 68 | replacement_text.push_str(new_name); |
69 | TextRange::new(reference.file_range.range.end(), reference.file_range.range.end()) | 69 | TextRange::new(reference.file_range.range.end(), reference.file_range.range.end()) |
@@ -260,7 +260,7 @@ fn rename_reference( | |||
260 | mod tests { | 260 | mod tests { |
261 | use insta::assert_debug_snapshot; | 261 | use insta::assert_debug_snapshot; |
262 | use ra_text_edit::TextEditBuilder; | 262 | use ra_text_edit::TextEditBuilder; |
263 | use test_utils::{assert_eq_text, covers}; | 263 | use test_utils::{assert_eq_text, mark}; |
264 | 264 | ||
265 | use crate::{ | 265 | use crate::{ |
266 | mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, | 266 | mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, |
@@ -492,7 +492,7 @@ mod tests { | |||
492 | 492 | ||
493 | #[test] | 493 | #[test] |
494 | fn test_rename_struct_field_for_shorthand() { | 494 | fn test_rename_struct_field_for_shorthand() { |
495 | covers!(test_rename_struct_field_for_shorthand); | 495 | mark::check!(test_rename_struct_field_for_shorthand); |
496 | test_rename( | 496 | test_rename( |
497 | r#" | 497 | r#" |
498 | struct Foo { | 498 | struct Foo { |
@@ -522,7 +522,7 @@ mod tests { | |||
522 | 522 | ||
523 | #[test] | 523 | #[test] |
524 | fn test_rename_local_for_field_shorthand() { | 524 | fn test_rename_local_for_field_shorthand() { |
525 | covers!(test_rename_local_for_field_shorthand); | 525 | mark::check!(test_rename_local_for_field_shorthand); |
526 | test_rename( | 526 | test_rename( |
527 | r#" | 527 | r#" |
528 | struct Foo { | 528 | struct Foo { |
@@ -670,6 +670,7 @@ mod tests { | |||
670 | }, | 670 | }, |
671 | ], | 671 | ], |
672 | cursor_position: None, | 672 | cursor_position: None, |
673 | is_snippet: false, | ||
673 | }, | 674 | }, |
674 | }, | 675 | }, |
675 | ) | 676 | ) |
@@ -722,6 +723,7 @@ mod tests { | |||
722 | }, | 723 | }, |
723 | ], | 724 | ], |
724 | cursor_position: None, | 725 | cursor_position: None, |
726 | is_snippet: false, | ||
725 | }, | 727 | }, |
726 | }, | 728 | }, |
727 | ) | 729 | ) |
@@ -818,6 +820,7 @@ mod tests { | |||
818 | }, | 820 | }, |
819 | ], | 821 | ], |
820 | cursor_position: None, | 822 | cursor_position: None, |
823 | is_snippet: false, | ||
821 | }, | 824 | }, |
822 | }, | 825 | }, |
823 | ) | 826 | ) |
diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 4f7eb2c5b..3a3d0b0ac 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir::{Attrs, HirFileId, InFile, Semantics}; | 3 | use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics}; |
4 | use itertools::Itertools; | 4 | use itertools::Itertools; |
5 | use ra_ide_db::RootDatabase; | 5 | use ra_ide_db::RootDatabase; |
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
@@ -70,14 +70,36 @@ fn runnable_fn( | |||
70 | RunnableKind::Bin | 70 | RunnableKind::Bin |
71 | } else { | 71 | } else { |
72 | let test_id = if let Some(module) = sema.to_def(&fn_def).map(|def| def.module(sema.db)) { | 72 | let test_id = if let Some(module) = sema.to_def(&fn_def).map(|def| def.module(sema.db)) { |
73 | let path = module | 73 | let def = sema.to_def(&fn_def)?; |
74 | let impl_trait_name = | ||
75 | def.as_assoc_item(sema.db).and_then(|assoc_item| { | ||
76 | match assoc_item.container(sema.db) { | ||
77 | hir::AssocItemContainer::Trait(trait_item) => { | ||
78 | Some(trait_item.name(sema.db).to_string()) | ||
79 | } | ||
80 | hir::AssocItemContainer::ImplDef(impl_def) => impl_def | ||
81 | .target_ty(sema.db) | ||
82 | .as_adt() | ||
83 | .map(|adt| adt.name(sema.db).to_string()), | ||
84 | } | ||
85 | }); | ||
86 | |||
87 | let path_iter = module | ||
74 | .path_to_root(sema.db) | 88 | .path_to_root(sema.db) |
75 | .into_iter() | 89 | .into_iter() |
76 | .rev() | 90 | .rev() |
77 | .filter_map(|it| it.name(sema.db)) | 91 | .filter_map(|it| it.name(sema.db)) |
78 | .map(|name| name.to_string()) | 92 | .map(|name| name.to_string()); |
79 | .chain(std::iter::once(name_string)) | 93 | |
80 | .join("::"); | 94 | let path = if let Some(impl_trait_name) = impl_trait_name { |
95 | path_iter | ||
96 | .chain(std::iter::once(impl_trait_name)) | ||
97 | .chain(std::iter::once(name_string)) | ||
98 | .join("::") | ||
99 | } else { | ||
100 | path_iter.chain(std::iter::once(name_string)).join("::") | ||
101 | }; | ||
102 | |||
81 | TestId::Path(path) | 103 | TestId::Path(path) |
82 | } else { | 104 | } else { |
83 | TestId::Name(name_string) | 105 | TestId::Name(name_string) |
@@ -279,6 +301,46 @@ mod tests { | |||
279 | } | 301 | } |
280 | 302 | ||
281 | #[test] | 303 | #[test] |
304 | fn test_runnables_doc_test_in_impl() { | ||
305 | let (analysis, pos) = analysis_and_position( | ||
306 | r#" | ||
307 | //- /lib.rs | ||
308 | <|> //empty | ||
309 | fn main() {} | ||
310 | |||
311 | struct Data; | ||
312 | impl Data { | ||
313 | /// ``` | ||
314 | /// let x = 5; | ||
315 | /// ``` | ||
316 | fn foo() {} | ||
317 | } | ||
318 | "#, | ||
319 | ); | ||
320 | let runnables = analysis.runnables(pos.file_id).unwrap(); | ||
321 | assert_debug_snapshot!(&runnables, | ||
322 | @r###" | ||
323 | [ | ||
324 | Runnable { | ||
325 | range: 1..21, | ||
326 | kind: Bin, | ||
327 | features_needed: None, | ||
328 | }, | ||
329 | Runnable { | ||
330 | range: 51..105, | ||
331 | kind: DocTest { | ||
332 | test_id: Path( | ||
333 | "Data::foo", | ||
334 | ), | ||
335 | }, | ||
336 | features_needed: None, | ||
337 | }, | ||
338 | ] | ||
339 | "### | ||
340 | ); | ||
341 | } | ||
342 | |||
343 | #[test] | ||
282 | fn test_runnables_module() { | 344 | fn test_runnables_module() { |
283 | let (analysis, pos) = analysis_and_position( | 345 | let (analysis, pos) = analysis_and_position( |
284 | r#" | 346 | r#" |
diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index 6f04f0be4..cd48cad93 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs | |||
@@ -82,7 +82,6 @@ fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<SingleFileChange> | |||
82 | Some(SingleFileChange { | 82 | Some(SingleFileChange { |
83 | label: "add semicolon".to_string(), | 83 | label: "add semicolon".to_string(), |
84 | edit: TextEdit::insert(offset, ";".to_string()), | 84 | edit: TextEdit::insert(offset, ";".to_string()), |
85 | cursor_position: None, | ||
86 | }) | 85 | }) |
87 | } | 86 | } |
88 | 87 | ||
@@ -111,7 +110,6 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<SingleFileChange> | |||
111 | Some(SingleFileChange { | 110 | Some(SingleFileChange { |
112 | label: "reindent dot".to_string(), | 111 | label: "reindent dot".to_string(), |
113 | edit: TextEdit::replace(TextRange::new(offset - current_indent_len, offset), target_indent), | 112 | edit: TextEdit::replace(TextRange::new(offset - current_indent_len, offset), target_indent), |
114 | cursor_position: Some(offset + target_indent_len - current_indent_len + TextSize::of('.')), | ||
115 | }) | 113 | }) |
116 | } | 114 | } |
117 | 115 | ||
@@ -130,7 +128,6 @@ fn on_arrow_typed(file: &SourceFile, offset: TextSize) -> Option<SingleFileChang | |||
130 | Some(SingleFileChange { | 128 | Some(SingleFileChange { |
131 | label: "add space after return type".to_string(), | 129 | label: "add space after return type".to_string(), |
132 | edit: TextEdit::insert(after_arrow, " ".to_string()), | 130 | edit: TextEdit::insert(after_arrow, " ".to_string()), |
133 | cursor_position: Some(after_arrow), | ||
134 | }) | 131 | }) |
135 | } | 132 | } |
136 | 133 | ||
@@ -140,7 +137,7 @@ mod tests { | |||
140 | 137 | ||
141 | use super::*; | 138 | use super::*; |
142 | 139 | ||
143 | fn do_type_char(char_typed: char, before: &str) -> Option<(String, SingleFileChange)> { | 140 | fn do_type_char(char_typed: char, before: &str) -> Option<String> { |
144 | let (offset, before) = extract_offset(before); | 141 | let (offset, before) = extract_offset(before); |
145 | let edit = TextEdit::insert(offset, char_typed.to_string()); | 142 | let edit = TextEdit::insert(offset, char_typed.to_string()); |
146 | let mut before = before.to_string(); | 143 | let mut before = before.to_string(); |
@@ -148,21 +145,15 @@ mod tests { | |||
148 | let parse = SourceFile::parse(&before); | 145 | let parse = SourceFile::parse(&before); |
149 | on_char_typed_inner(&parse.tree(), offset, char_typed).map(|it| { | 146 | on_char_typed_inner(&parse.tree(), offset, char_typed).map(|it| { |
150 | it.edit.apply(&mut before); | 147 | it.edit.apply(&mut before); |
151 | (before.to_string(), it) | 148 | before.to_string() |
152 | }) | 149 | }) |
153 | } | 150 | } |
154 | 151 | ||
155 | fn type_char(char_typed: char, before: &str, after: &str) { | 152 | fn type_char(char_typed: char, before: &str, after: &str) { |
156 | let (actual, file_change) = do_type_char(char_typed, before) | 153 | let actual = do_type_char(char_typed, before) |
157 | .unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed)); | 154 | .unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed)); |
158 | 155 | ||
159 | if after.contains("<|>") { | 156 | assert_eq_text!(after, &actual); |
160 | let (offset, after) = extract_offset(after); | ||
161 | assert_eq_text!(&after, &actual); | ||
162 | assert_eq!(file_change.cursor_position, Some(offset)) | ||
163 | } else { | ||
164 | assert_eq_text!(after, &actual); | ||
165 | } | ||
166 | } | 157 | } |
167 | 158 | ||
168 | fn type_char_noop(char_typed: char, before: &str) { | 159 | fn type_char_noop(char_typed: char, before: &str) { |
@@ -350,6 +341,6 @@ fn foo() { | |||
350 | 341 | ||
351 | #[test] | 342 | #[test] |
352 | fn adds_space_after_return_type() { | 343 | fn adds_space_after_return_type() { |
353 | type_char('>', "fn foo() -<|>{ 92 }", "fn foo() -><|> { 92 }") | 344 | type_char('>', "fn foo() -<|>{ 92 }", "fn foo() -> { 92 }") |
354 | } | 345 | } |
355 | } | 346 | } |