aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--crates/ra_ide/src/goto_definition.rs8
-rw-r--r--crates/ra_ide/src/references.rs3
-rw-r--r--crates/ra_ide_db/Cargo.toml1
-rw-r--r--crates/ra_ide_db/src/defs.rs6
-rw-r--r--crates/ra_ide_db/src/lib.rs1
-rw-r--r--crates/ra_ide_db/src/marks.rs9
-rw-r--r--crates/test_utils/src/marks.rs15
8 files changed, 37 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 373e176b0..87c288346 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1068,6 +1068,7 @@ dependencies = [
1068 "rayon", 1068 "rayon",
1069 "rustc-hash", 1069 "rustc-hash",
1070 "superslice", 1070 "superslice",
1071 "test_utils",
1071] 1072]
1072 1073
1073[[package]] 1074[[package]]
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index 4a8107d60..a55a13ffc 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -96,7 +96,7 @@ pub(crate) fn reference_definition(
96 96
97#[cfg(test)] 97#[cfg(test)]
98mod tests { 98mod tests {
99 use test_utils::assert_eq_text; 99 use test_utils::{assert_eq_text, covers};
100 100
101 use crate::mock_analysis::analysis_and_position; 101 use crate::mock_analysis::analysis_and_position;
102 102
@@ -208,6 +208,7 @@ 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);
211 check_goto( 212 check_goto(
212 " 213 "
213 //- /lib.rs 214 //- /lib.rs
@@ -224,6 +225,7 @@ mod tests {
224 225
225 #[test] 226 #[test]
226 fn goto_def_for_macros_from_other_crates() { 227 fn goto_def_for_macros_from_other_crates() {
228 covers!(ra_ide_db::goto_def_for_macros);
227 check_goto( 229 check_goto(
228 " 230 "
229 //- /lib.rs 231 //- /lib.rs
@@ -335,6 +337,7 @@ mod tests {
335 337
336 #[test] 338 #[test]
337 fn goto_def_for_methods() { 339 fn goto_def_for_methods() {
340 covers!(ra_ide_db::goto_def_for_methods);
338 check_goto( 341 check_goto(
339 " 342 "
340 //- /lib.rs 343 //- /lib.rs
@@ -354,6 +357,7 @@ mod tests {
354 357
355 #[test] 358 #[test]
356 fn goto_def_for_fields() { 359 fn goto_def_for_fields() {
360 covers!(ra_ide_db::goto_def_for_fields);
357 check_goto( 361 check_goto(
358 " 362 "
359 //- /lib.rs 363 //- /lib.rs
@@ -372,6 +376,7 @@ mod tests {
372 376
373 #[test] 377 #[test]
374 fn goto_def_for_record_fields() { 378 fn goto_def_for_record_fields() {
379 covers!(ra_ide_db::goto_def_for_record_fields);
375 check_goto( 380 check_goto(
376 " 381 "
377 //- /lib.rs 382 //- /lib.rs
@@ -784,6 +789,7 @@ mod tests {
784 789
785 #[test] 790 #[test]
786 fn goto_def_for_field_init_shorthand() { 791 fn goto_def_for_field_init_shorthand() {
792 covers!(ra_ide_db::goto_def_for_field_init_shorthand);
787 check_goto( 793 check_goto(
788 " 794 "
789 //- /lib.rs 795 //- /lib.rs
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index 67be3f6c9..95468d434 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -222,9 +222,6 @@ fn process_definition(
222 } 222 }
223 }; 223 };
224 224
225 // FIXME: reuse sb
226 // See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098
227
228 if let Some(d) = classify_name_ref(&sema, &name_ref) { 225 if let Some(d) = classify_name_ref(&sema, &name_ref) {
229 let d = d.definition(); 226 let d = d.definition();
230 if &d == def { 227 if &d == def {
diff --git a/crates/ra_ide_db/Cargo.toml b/crates/ra_ide_db/Cargo.toml
index 7b285d280..7ff1a536e 100644
--- a/crates/ra_ide_db/Cargo.toml
+++ b/crates/ra_ide_db/Cargo.toml
@@ -21,6 +21,7 @@ ra_syntax = { path = "../ra_syntax" }
21ra_text_edit = { path = "../ra_text_edit" } 21ra_text_edit = { path = "../ra_text_edit" }
22ra_db = { path = "../ra_db" } 22ra_db = { path = "../ra_db" }
23ra_prof = { path = "../ra_prof" } 23ra_prof = { path = "../ra_prof" }
24test_utils = { path = "../test_utils" }
24 25
25# ra_ide should depend only on the top-level `hir` package. if you need 26# ra_ide should depend only on the top-level `hir` package. if you need
26# something from some `hir_xxx` subpackage, reexport the API via `hir`. 27# something from some `hir_xxx` subpackage, reexport the API via `hir`.
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs
index f057435bf..97961bb6d 100644
--- a/crates/ra_ide_db/src/defs.rs
+++ b/crates/ra_ide_db/src/defs.rs
@@ -14,6 +14,7 @@ use ra_syntax::{
14 ast::{self, AstNode, VisibilityOwner}, 14 ast::{self, AstNode, VisibilityOwner},
15 match_ast, 15 match_ast,
16}; 16};
17use test_utils::tested_by;
17 18
18use crate::RootDatabase; 19use crate::RootDatabase;
19 20
@@ -217,18 +218,22 @@ pub fn classify_name_ref(
217 let parent = name_ref.syntax().parent()?; 218 let parent = name_ref.syntax().parent()?;
218 219
219 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { 220 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
221 tested_by!(goto_def_for_methods; force);
220 if let Some(func) = sema.resolve_method_call(&method_call) { 222 if let Some(func) = sema.resolve_method_call(&method_call) {
221 return Some(NameRefClass::Definition(Definition::ModuleDef(func.into()))); 223 return Some(NameRefClass::Definition(Definition::ModuleDef(func.into())));
222 } 224 }
223 } 225 }
224 226
225 if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) { 227 if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) {
228 tested_by!(goto_def_for_fields; force);
226 if let Some(field) = sema.resolve_field(&field_expr) { 229 if let Some(field) = sema.resolve_field(&field_expr) {
227 return Some(NameRefClass::Definition(Definition::StructField(field))); 230 return Some(NameRefClass::Definition(Definition::StructField(field)));
228 } 231 }
229 } 232 }
230 233
231 if let Some(record_field) = ast::RecordField::cast(parent.clone()) { 234 if let Some(record_field) = ast::RecordField::cast(parent.clone()) {
235 tested_by!(goto_def_for_record_fields; force);
236 tested_by!(goto_def_for_field_init_shorthand; force);
232 if let Some((field, local)) = sema.resolve_record_field(&record_field) { 237 if let Some((field, local)) = sema.resolve_record_field(&record_field) {
233 let field = Definition::StructField(field); 238 let field = Definition::StructField(field);
234 let res = match local { 239 let res = match local {
@@ -240,6 +245,7 @@ pub fn classify_name_ref(
240 } 245 }
241 246
242 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { 247 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
248 tested_by!(goto_def_for_macros; force);
243 if let Some(macro_def) = sema.resolve_macro_call(&macro_call) { 249 if let Some(macro_def) = sema.resolve_macro_call(&macro_call) {
244 return Some(NameRefClass::Definition(Definition::Macro(macro_def))); 250 return Some(NameRefClass::Definition(Definition::Macro(macro_def)));
245 } 251 }
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs
index 877ac3c38..aa312c140 100644
--- a/crates/ra_ide_db/src/lib.rs
+++ b/crates/ra_ide_db/src/lib.rs
@@ -2,6 +2,7 @@
2//! 2//!
3//! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search. 3//! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search.
4 4
5pub mod marks;
5pub mod line_index; 6pub mod line_index;
6pub mod line_index_utils; 7pub mod line_index_utils;
7pub mod feature_flags; 8pub mod feature_flags;
diff --git a/crates/ra_ide_db/src/marks.rs b/crates/ra_ide_db/src/marks.rs
new file mode 100644
index 000000000..d088fa257
--- /dev/null
+++ b/crates/ra_ide_db/src/marks.rs
@@ -0,0 +1,9 @@
1//! See test_utils/src/marks.rs
2
3test_utils::marks![
4 goto_def_for_macros
5 goto_def_for_methods
6 goto_def_for_fields
7 goto_def_for_record_fields
8 goto_def_for_field_init_shorthand
9];
diff --git a/crates/test_utils/src/marks.rs b/crates/test_utils/src/marks.rs
index f8fabfaff..c3185e860 100644
--- a/crates/test_utils/src/marks.rs
+++ b/crates/test_utils/src/marks.rs
@@ -30,6 +30,12 @@ use std::sync::atomic::{AtomicUsize, Ordering};
30 30
31#[macro_export] 31#[macro_export]
32macro_rules! tested_by { 32macro_rules! tested_by {
33 ($ident:ident; force) => {{
34 {
35 // sic! use call-site crate
36 crate::marks::$ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
37 }
38 }};
33 ($ident:ident) => {{ 39 ($ident:ident) => {{
34 #[cfg(test)] 40 #[cfg(test)]
35 { 41 {
@@ -41,9 +47,12 @@ macro_rules! tested_by {
41 47
42#[macro_export] 48#[macro_export]
43macro_rules! covers { 49macro_rules! covers {
50 // sic! use call-site crate
44 ($ident:ident) => { 51 ($ident:ident) => {
45 // sic! use call-site crate 52 $crate::covers!(crate::$ident)
46 let _checker = $crate::marks::MarkChecker::new(&crate::marks::$ident); 53 };
54 ($krate:ident :: $ident:ident) => {
55 let _checker = $crate::marks::MarkChecker::new(&$krate::marks::$ident);
47 }; 56 };
48} 57}
49 58
@@ -52,7 +61,7 @@ macro_rules! marks {
52 ($($ident:ident)*) => { 61 ($($ident:ident)*) => {
53 $( 62 $(
54 #[allow(bad_style)] 63 #[allow(bad_style)]
55 pub(crate) static $ident: std::sync::atomic::AtomicUsize = 64 pub static $ident: std::sync::atomic::AtomicUsize =
56 std::sync::atomic::AtomicUsize::new(0); 65 std::sync::atomic::AtomicUsize::new(0);
57 )* 66 )*
58 }; 67 };