diff options
Diffstat (limited to 'crates/ide_ssr')
-rw-r--r-- | crates/ide_ssr/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ide_ssr/src/matching.rs | 3 | ||||
-rw-r--r-- | crates/ide_ssr/src/parsing.rs | 3 | ||||
-rw-r--r-- | crates/ide_ssr/src/replacing.rs | 4 | ||||
-rw-r--r-- | crates/ide_ssr/src/resolving.rs | 9 | ||||
-rw-r--r-- | crates/ide_ssr/src/search.rs | 5 | ||||
-rw-r--r-- | crates/ide_ssr/src/tests.rs | 20 |
7 files changed, 21 insertions, 24 deletions
diff --git a/crates/ide_ssr/Cargo.toml b/crates/ide_ssr/Cargo.toml index edbc1846b..315691f40 100644 --- a/crates/ide_ssr/Cargo.toml +++ b/crates/ide_ssr/Cargo.toml | |||
@@ -11,6 +11,7 @@ edition = "2018" | |||
11 | doctest = false | 11 | doctest = false |
12 | 12 | ||
13 | [dependencies] | 13 | [dependencies] |
14 | cov-mark = "1.1" | ||
14 | rustc-hash = "1.1.0" | 15 | rustc-hash = "1.1.0" |
15 | itertools = "0.10.0" | 16 | itertools = "0.10.0" |
16 | 17 | ||
diff --git a/crates/ide_ssr/src/matching.rs b/crates/ide_ssr/src/matching.rs index df013bae9..e1adb381e 100644 --- a/crates/ide_ssr/src/matching.rs +++ b/crates/ide_ssr/src/matching.rs | |||
@@ -15,7 +15,6 @@ use syntax::{ | |||
15 | ast::{AstNode, AstToken}, | 15 | ast::{AstNode, AstToken}, |
16 | SmolStr, | 16 | SmolStr, |
17 | }; | 17 | }; |
18 | use test_utils::mark; | ||
19 | 18 | ||
20 | // Creates a match error. If we're currently attempting to match some code that we thought we were | 19 | // Creates a match error. If we're currently attempting to match some code that we thought we were |
21 | // going to match, as indicated by the --debug-snippet flag, then populate the reason field. | 20 | // going to match, as indicated by the --debug-snippet flag, then populate the reason field. |
@@ -731,7 +730,7 @@ impl NodeKind { | |||
731 | fn matches(&self, node: &SyntaxNode) -> Result<(), MatchFailed> { | 730 | fn matches(&self, node: &SyntaxNode) -> Result<(), MatchFailed> { |
732 | let ok = match self { | 731 | let ok = match self { |
733 | Self::Literal => { | 732 | Self::Literal => { |
734 | mark::hit!(literal_constraint); | 733 | cov_mark::hit!(literal_constraint); |
735 | ast::Literal::can_cast(node.kind()) | 734 | ast::Literal::can_cast(node.kind()) |
736 | } | 735 | } |
737 | }; | 736 | }; |
diff --git a/crates/ide_ssr/src/parsing.rs b/crates/ide_ssr/src/parsing.rs index 3d5e4feb7..5ff25cb6d 100644 --- a/crates/ide_ssr/src/parsing.rs +++ b/crates/ide_ssr/src/parsing.rs | |||
@@ -10,7 +10,6 @@ use crate::{SsrError, SsrPattern, SsrRule}; | |||
10 | use rustc_hash::{FxHashMap, FxHashSet}; | 10 | use rustc_hash::{FxHashMap, FxHashSet}; |
11 | use std::{fmt::Display, str::FromStr}; | 11 | use std::{fmt::Display, str::FromStr}; |
12 | use syntax::{ast, AstNode, SmolStr, SyntaxKind, SyntaxNode, T}; | 12 | use syntax::{ast, AstNode, SmolStr, SyntaxKind, SyntaxNode, T}; |
13 | use test_utils::mark; | ||
14 | 13 | ||
15 | #[derive(Debug)] | 14 | #[derive(Debug)] |
16 | pub(crate) struct ParsedRule { | 15 | pub(crate) struct ParsedRule { |
@@ -131,7 +130,7 @@ impl RuleBuilder { | |||
131 | let old_len = self.rules.len(); | 130 | let old_len = self.rules.len(); |
132 | self.rules.retain(|rule| contains_path(&rule.pattern)); | 131 | self.rules.retain(|rule| contains_path(&rule.pattern)); |
133 | if self.rules.len() < old_len { | 132 | if self.rules.len() < old_len { |
134 | mark::hit!(pattern_is_a_single_segment_path); | 133 | cov_mark::hit!(pattern_is_a_single_segment_path); |
135 | } | 134 | } |
136 | } | 135 | } |
137 | Ok(self.rules) | 136 | Ok(self.rules) |
diff --git a/crates/ide_ssr/src/replacing.rs b/crates/ide_ssr/src/replacing.rs index 06a94a46c..c9ccc1961 100644 --- a/crates/ide_ssr/src/replacing.rs +++ b/crates/ide_ssr/src/replacing.rs | |||
@@ -5,7 +5,7 @@ use itertools::Itertools; | |||
5 | use rustc_hash::{FxHashMap, FxHashSet}; | 5 | use rustc_hash::{FxHashMap, FxHashSet}; |
6 | use syntax::ast::{self, AstNode, AstToken}; | 6 | use syntax::ast::{self, AstNode, AstToken}; |
7 | use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize}; | 7 | use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize}; |
8 | use test_utils::mark; | 8 | |
9 | use text_edit::TextEdit; | 9 | use text_edit::TextEdit; |
10 | 10 | ||
11 | /// Returns a text edit that will replace each match in `matches` with its corresponding replacement | 11 | /// Returns a text edit that will replace each match in `matches` with its corresponding replacement |
@@ -128,7 +128,7 @@ impl ReplacementRenderer<'_> { | |||
128 | && (placeholder_value.autoderef_count > 0 | 128 | && (placeholder_value.autoderef_count > 0 |
129 | || placeholder_value.autoref_kind != ast::SelfParamKind::Owned) | 129 | || placeholder_value.autoref_kind != ast::SelfParamKind::Owned) |
130 | { | 130 | { |
131 | mark::hit!(replace_autoref_autoderef_capture); | 131 | cov_mark::hit!(replace_autoref_autoderef_capture); |
132 | let ref_kind = match placeholder_value.autoref_kind { | 132 | let ref_kind = match placeholder_value.autoref_kind { |
133 | ast::SelfParamKind::Owned => "", | 133 | ast::SelfParamKind::Owned => "", |
134 | ast::SelfParamKind::Ref => "&", | 134 | ast::SelfParamKind::Ref => "&", |
diff --git a/crates/ide_ssr/src/resolving.rs b/crates/ide_ssr/src/resolving.rs index 14e5a3b69..af94c7bb1 100644 --- a/crates/ide_ssr/src/resolving.rs +++ b/crates/ide_ssr/src/resolving.rs | |||
@@ -6,7 +6,6 @@ use ide_db::base_db::FilePosition; | |||
6 | use parsing::Placeholder; | 6 | use parsing::Placeholder; |
7 | use rustc_hash::FxHashMap; | 7 | use rustc_hash::FxHashMap; |
8 | use syntax::{ast, SmolStr, SyntaxKind, SyntaxNode, SyntaxToken}; | 8 | use syntax::{ast, SmolStr, SyntaxKind, SyntaxNode, SyntaxToken}; |
9 | use test_utils::mark; | ||
10 | 9 | ||
11 | pub(crate) struct ResolutionScope<'db> { | 10 | pub(crate) struct ResolutionScope<'db> { |
12 | scope: hir::SemanticsScope<'db>, | 11 | scope: hir::SemanticsScope<'db>, |
@@ -170,13 +169,13 @@ impl Resolver<'_, '_> { | |||
170 | // calls. e.g. `Foo::bar($s)` should match `x.bar()`. | 169 | // calls. e.g. `Foo::bar($s)` should match `x.bar()`. |
171 | true | 170 | true |
172 | } else { | 171 | } else { |
173 | mark::hit!(replace_associated_trait_default_function_call); | 172 | cov_mark::hit!(replace_associated_trait_default_function_call); |
174 | false | 173 | false |
175 | } | 174 | } |
176 | } | 175 | } |
177 | hir::PathResolution::AssocItem(_) => { | 176 | hir::PathResolution::AssocItem(_) => { |
178 | // Not a function. Could be a constant or an associated type. | 177 | // Not a function. Could be a constant or an associated type. |
179 | mark::hit!(replace_associated_trait_constant); | 178 | cov_mark::hit!(replace_associated_trait_constant); |
180 | false | 179 | false |
181 | } | 180 | } |
182 | _ => true, | 181 | _ => true, |
@@ -267,7 +266,7 @@ fn pick_node_for_resolution(node: SyntaxNode) -> SyntaxNode { | |||
267 | match node.kind() { | 266 | match node.kind() { |
268 | SyntaxKind::EXPR_STMT => { | 267 | SyntaxKind::EXPR_STMT => { |
269 | if let Some(n) = node.first_child() { | 268 | if let Some(n) = node.first_child() { |
270 | mark::hit!(cursor_after_semicolon); | 269 | cov_mark::hit!(cursor_after_semicolon); |
271 | return n; | 270 | return n; |
272 | } | 271 | } |
273 | } | 272 | } |
@@ -291,7 +290,7 @@ fn path_contains_type_arguments(path: Option<ast::Path>) -> bool { | |||
291 | if let Some(path) = path { | 290 | if let Some(path) = path { |
292 | if let Some(segment) = path.segment() { | 291 | if let Some(segment) = path.segment() { |
293 | if segment.generic_arg_list().is_some() { | 292 | if segment.generic_arg_list().is_some() { |
294 | mark::hit!(type_arguments_within_path); | 293 | cov_mark::hit!(type_arguments_within_path); |
295 | return true; | 294 | return true; |
296 | } | 295 | } |
297 | } | 296 | } |
diff --git a/crates/ide_ssr/src/search.rs b/crates/ide_ssr/src/search.rs index 836eb94b2..28cef742c 100644 --- a/crates/ide_ssr/src/search.rs +++ b/crates/ide_ssr/src/search.rs | |||
@@ -12,7 +12,6 @@ use ide_db::{ | |||
12 | }; | 12 | }; |
13 | use rustc_hash::FxHashSet; | 13 | use rustc_hash::FxHashSet; |
14 | use syntax::{ast, AstNode, SyntaxKind, SyntaxNode}; | 14 | use syntax::{ast, AstNode, SyntaxKind, SyntaxNode}; |
15 | use test_utils::mark; | ||
16 | 15 | ||
17 | /// A cache for the results of find_usages. This is for when we have multiple patterns that have the | 16 | /// A cache for the results of find_usages. This is for when we have multiple patterns that have the |
18 | /// same path. e.g. if the pattern was `foo::Bar` that can parse as a path, an expression, a type | 17 | /// same path. e.g. if the pattern was `foo::Bar` that can parse as a path, an expression, a type |
@@ -61,7 +60,7 @@ impl<'db> MatchFinder<'db> { | |||
61 | for file_range in self.find_usages(usage_cache, definition).file_ranges() { | 60 | for file_range in self.find_usages(usage_cache, definition).file_ranges() { |
62 | if let Some(node_to_match) = self.find_node_to_match(resolved_path, file_range) { | 61 | if let Some(node_to_match) = self.find_node_to_match(resolved_path, file_range) { |
63 | if !is_search_permitted_ancestors(&node_to_match) { | 62 | if !is_search_permitted_ancestors(&node_to_match) { |
64 | mark::hit!(use_declaration_with_braces); | 63 | cov_mark::hit!(use_declaration_with_braces); |
65 | continue; | 64 | continue; |
66 | } | 65 | } |
67 | self.try_add_match(rule, &node_to_match, &None, matches_out); | 66 | self.try_add_match(rule, &node_to_match, &None, matches_out); |
@@ -205,7 +204,7 @@ impl<'db> MatchFinder<'db> { | |||
205 | matches_out: &mut Vec<Match>, | 204 | matches_out: &mut Vec<Match>, |
206 | ) { | 205 | ) { |
207 | if !self.within_range_restrictions(code) { | 206 | if !self.within_range_restrictions(code) { |
208 | mark::hit!(replace_nonpath_within_selection); | 207 | cov_mark::hit!(replace_nonpath_within_selection); |
209 | return; | 208 | return; |
210 | } | 209 | } |
211 | if let Ok(m) = matching::get_match(false, rule, code, restrict_range, &self.sema) { | 210 | if let Ok(m) = matching::get_match(false, rule, code, restrict_range, &self.sema) { |
diff --git a/crates/ide_ssr/src/tests.rs b/crates/ide_ssr/src/tests.rs index a3ea44f23..1d8565dc0 100644 --- a/crates/ide_ssr/src/tests.rs +++ b/crates/ide_ssr/src/tests.rs | |||
@@ -3,7 +3,7 @@ use expect_test::{expect, Expect}; | |||
3 | use ide_db::base_db::{salsa::Durability, FileId, FilePosition, FileRange, SourceDatabaseExt}; | 3 | use ide_db::base_db::{salsa::Durability, FileId, FilePosition, FileRange, SourceDatabaseExt}; |
4 | use rustc_hash::FxHashSet; | 4 | use rustc_hash::FxHashSet; |
5 | use std::sync::Arc; | 5 | use std::sync::Arc; |
6 | use test_utils::{mark, RangeOrOffset}; | 6 | use test_utils::RangeOrOffset; |
7 | 7 | ||
8 | fn parse_error_text(query: &str) -> String { | 8 | fn parse_error_text(query: &str) -> String { |
9 | format!("{}", query.parse::<SsrRule>().unwrap_err()) | 9 | format!("{}", query.parse::<SsrRule>().unwrap_err()) |
@@ -492,7 +492,7 @@ fn match_resolved_type_name() { | |||
492 | 492 | ||
493 | #[test] | 493 | #[test] |
494 | fn type_arguments_within_path() { | 494 | fn type_arguments_within_path() { |
495 | mark::check!(type_arguments_within_path); | 495 | cov_mark::check!(type_arguments_within_path); |
496 | let code = r#" | 496 | let code = r#" |
497 | mod foo { | 497 | mod foo { |
498 | pub struct Bar<T> {t: T} | 498 | pub struct Bar<T> {t: T} |
@@ -508,7 +508,7 @@ fn type_arguments_within_path() { | |||
508 | 508 | ||
509 | #[test] | 509 | #[test] |
510 | fn literal_constraint() { | 510 | fn literal_constraint() { |
511 | mark::check!(literal_constraint); | 511 | cov_mark::check!(literal_constraint); |
512 | let code = r#" | 512 | let code = r#" |
513 | enum Option<T> { Some(T), None } | 513 | enum Option<T> { Some(T), None } |
514 | use Option::Some; | 514 | use Option::Some; |
@@ -641,7 +641,7 @@ fn replace_associated_function_call() { | |||
641 | 641 | ||
642 | #[test] | 642 | #[test] |
643 | fn replace_associated_trait_default_function_call() { | 643 | fn replace_associated_trait_default_function_call() { |
644 | mark::check!(replace_associated_trait_default_function_call); | 644 | cov_mark::check!(replace_associated_trait_default_function_call); |
645 | assert_ssr_transform( | 645 | assert_ssr_transform( |
646 | "Bar2::foo() ==>> Bar2::foo2()", | 646 | "Bar2::foo() ==>> Bar2::foo2()", |
647 | r#" | 647 | r#" |
@@ -673,7 +673,7 @@ fn replace_associated_trait_default_function_call() { | |||
673 | 673 | ||
674 | #[test] | 674 | #[test] |
675 | fn replace_associated_trait_constant() { | 675 | fn replace_associated_trait_constant() { |
676 | mark::check!(replace_associated_trait_constant); | 676 | cov_mark::check!(replace_associated_trait_constant); |
677 | assert_ssr_transform( | 677 | assert_ssr_transform( |
678 | "Bar2::VALUE ==>> Bar2::VALUE_2222", | 678 | "Bar2::VALUE ==>> Bar2::VALUE_2222", |
679 | r#" | 679 | r#" |
@@ -998,7 +998,7 @@ fn use_declaration_with_braces() { | |||
998 | // It would be OK for a path rule to match and alter a use declaration. We shouldn't mess it up | 998 | // It would be OK for a path rule to match and alter a use declaration. We shouldn't mess it up |
999 | // though. In particular, we must not change `use foo::{baz, bar}` to `use foo::{baz, | 999 | // though. In particular, we must not change `use foo::{baz, bar}` to `use foo::{baz, |
1000 | // foo2::bar2}`. | 1000 | // foo2::bar2}`. |
1001 | mark::check!(use_declaration_with_braces); | 1001 | cov_mark::check!(use_declaration_with_braces); |
1002 | assert_ssr_transform( | 1002 | assert_ssr_transform( |
1003 | "foo::bar ==>> foo2::bar2", | 1003 | "foo::bar ==>> foo2::bar2", |
1004 | r#" | 1004 | r#" |
@@ -1076,7 +1076,7 @@ fn ufcs_matches_method_call() { | |||
1076 | 1076 | ||
1077 | #[test] | 1077 | #[test] |
1078 | fn pattern_is_a_single_segment_path() { | 1078 | fn pattern_is_a_single_segment_path() { |
1079 | mark::check!(pattern_is_a_single_segment_path); | 1079 | cov_mark::check!(pattern_is_a_single_segment_path); |
1080 | // The first function should not be altered because the `foo` in scope at the cursor position is | 1080 | // The first function should not be altered because the `foo` in scope at the cursor position is |
1081 | // a different `foo`. This case is special because "foo" can be parsed as a pattern (IDENT_PAT -> | 1081 | // a different `foo`. This case is special because "foo" can be parsed as a pattern (IDENT_PAT -> |
1082 | // NAME -> IDENT), which contains no path. If we're not careful we'll end up matching the `foo` | 1082 | // NAME -> IDENT), which contains no path. If we're not careful we'll end up matching the `foo` |
@@ -1118,7 +1118,7 @@ fn replace_local_variable_reference() { | |||
1118 | // The pattern references a local variable `foo` in the block containing the cursor. We should | 1118 | // The pattern references a local variable `foo` in the block containing the cursor. We should |
1119 | // only replace references to this variable `foo`, not other variables that just happen to have | 1119 | // only replace references to this variable `foo`, not other variables that just happen to have |
1120 | // the same name. | 1120 | // the same name. |
1121 | mark::check!(cursor_after_semicolon); | 1121 | cov_mark::check!(cursor_after_semicolon); |
1122 | assert_ssr_transform( | 1122 | assert_ssr_transform( |
1123 | "foo + $a ==>> $a - foo", | 1123 | "foo + $a ==>> $a - foo", |
1124 | r#" | 1124 | r#" |
@@ -1179,7 +1179,7 @@ fn replace_path_within_selection() { | |||
1179 | 1179 | ||
1180 | #[test] | 1180 | #[test] |
1181 | fn replace_nonpath_within_selection() { | 1181 | fn replace_nonpath_within_selection() { |
1182 | mark::check!(replace_nonpath_within_selection); | 1182 | cov_mark::check!(replace_nonpath_within_selection); |
1183 | assert_ssr_transform( | 1183 | assert_ssr_transform( |
1184 | "$a + $b ==>> $b * $a", | 1184 | "$a + $b ==>> $b * $a", |
1185 | r#" | 1185 | r#" |
@@ -1269,7 +1269,7 @@ fn replace_autoref_autoderef_capture() { | |||
1269 | // second, we already have a reference, so it isn't. When $a is used in a context where autoref | 1269 | // second, we already have a reference, so it isn't. When $a is used in a context where autoref |
1270 | // doesn't apply, we need to prefix it with `&`. Finally, we have some cases where autoderef | 1270 | // doesn't apply, we need to prefix it with `&`. Finally, we have some cases where autoderef |
1271 | // needs to be applied. | 1271 | // needs to be applied. |
1272 | mark::check!(replace_autoref_autoderef_capture); | 1272 | cov_mark::check!(replace_autoref_autoderef_capture); |
1273 | let code = r#" | 1273 | let code = r#" |
1274 | struct Foo {} | 1274 | struct Foo {} |
1275 | impl Foo { | 1275 | impl Foo { |