mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
ide: improve ReferenceCategoryType
It is bitset semantically --- many categorical things can be true about a reference at the same time. In parciular, a reference can be a "test" and a "write" at the same time.
This commit is contained in:
parent
1179c3ee83
commit
9bd8eee21e
9 changed files with 167 additions and 132 deletions
|
@ -30,7 +30,7 @@ use crate::{FilePosition, NavigationTarget, TryToNav};
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct ReferenceSearchResult {
|
||||
pub declaration: Option<Declaration>,
|
||||
pub references: IntMap<FileId, Vec<(TextRange, Option<ReferenceCategory>)>>,
|
||||
pub references: IntMap<FileId, Vec<(TextRange, ReferenceCategory)>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -66,7 +66,7 @@ pub(crate) fn find_all_refs(
|
|||
retain_adt_literal_usages(&mut usages, def, sema);
|
||||
}
|
||||
|
||||
let mut references = usages
|
||||
let mut references: IntMap<FileId, Vec<(TextRange, ReferenceCategory)>> = usages
|
||||
.into_iter()
|
||||
.map(|(file_id, refs)| {
|
||||
(
|
||||
|
@ -77,7 +77,7 @@ pub(crate) fn find_all_refs(
|
|||
.collect(),
|
||||
)
|
||||
})
|
||||
.collect::<IntMap<_, Vec<_>>>();
|
||||
.collect();
|
||||
let declaration = match def {
|
||||
Definition::Module(module) => {
|
||||
Some(NavigationTarget::from_module_to_decl(sema.db, module))
|
||||
|
@ -93,7 +93,7 @@ pub(crate) fn find_all_refs(
|
|||
references
|
||||
.entry(extra_ref.file_id)
|
||||
.or_default()
|
||||
.push((extra_ref.focus_or_full_range(), None));
|
||||
.push((extra_ref.focus_or_full_range(), ReferenceCategory::empty()));
|
||||
}
|
||||
Declaration {
|
||||
is_mut: matches!(def, Definition::Local(l) if l.is_mut(sema.db)),
|
||||
|
@ -300,7 +300,7 @@ fn is_lit_name_ref(name_ref: &ast::NameRef) -> bool {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use expect_test::{expect, Expect};
|
||||
use ide_db::{base_db::FileId, search::ReferenceCategory};
|
||||
use ide_db::base_db::FileId;
|
||||
use stdx::format_to;
|
||||
|
||||
use crate::{fixture, SearchScope};
|
||||
|
@ -324,7 +324,7 @@ fn test() {
|
|||
test_func Function FileId(0) 0..17 3..12
|
||||
|
||||
FileId(0) 35..44
|
||||
FileId(0) 75..84 Test
|
||||
FileId(0) 75..84 test
|
||||
"#]],
|
||||
);
|
||||
|
||||
|
@ -345,7 +345,7 @@ fn test() {
|
|||
test_func Function FileId(0) 0..17 3..12
|
||||
|
||||
FileId(0) 35..44
|
||||
FileId(0) 96..105 Test
|
||||
FileId(0) 96..105 test
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -600,12 +600,12 @@ fn main() {
|
|||
i = 5;
|
||||
}"#,
|
||||
expect![[r#"
|
||||
i Local FileId(0) 20..25 24..25 Write
|
||||
i Local FileId(0) 20..25 24..25 write
|
||||
|
||||
FileId(0) 50..51 Write
|
||||
FileId(0) 54..55 Read
|
||||
FileId(0) 76..77 Write
|
||||
FileId(0) 94..95 Write
|
||||
FileId(0) 50..51 write
|
||||
FileId(0) 54..55 read
|
||||
FileId(0) 76..77 write
|
||||
FileId(0) 94..95 write
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -626,8 +626,8 @@ fn bar() {
|
|||
expect![[r#"
|
||||
spam Local FileId(0) 19..23 19..23
|
||||
|
||||
FileId(0) 34..38 Read
|
||||
FileId(0) 41..45 Read
|
||||
FileId(0) 34..38 read
|
||||
FileId(0) 41..45 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -641,7 +641,7 @@ fn foo(i : u32) -> u32 { i$0 }
|
|||
expect![[r#"
|
||||
i ValueParam FileId(0) 7..8 7..8
|
||||
|
||||
FileId(0) 25..26 Read
|
||||
FileId(0) 25..26 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -655,7 +655,7 @@ fn foo(i$0 : u32) -> u32 { i }
|
|||
expect![[r#"
|
||||
i ValueParam FileId(0) 7..8 7..8
|
||||
|
||||
FileId(0) 25..26 Read
|
||||
FileId(0) 25..26 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -676,7 +676,7 @@ fn main(s: Foo) {
|
|||
expect![[r#"
|
||||
spam Field FileId(0) 17..30 21..25
|
||||
|
||||
FileId(0) 67..71 Read
|
||||
FileId(0) 67..71 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -824,7 +824,7 @@ pub struct Foo {
|
|||
expect![[r#"
|
||||
foo Module FileId(0) 0..8 4..7
|
||||
|
||||
FileId(0) 14..17 Import
|
||||
FileId(0) 14..17 import
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -842,7 +842,7 @@ use self$0;
|
|||
expect![[r#"
|
||||
foo Module FileId(0) 0..8 4..7
|
||||
|
||||
FileId(1) 4..8 Import
|
||||
FileId(1) 4..8 import
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -857,7 +857,7 @@ use self$0;
|
|||
expect![[r#"
|
||||
Module FileId(0) 0..10
|
||||
|
||||
FileId(0) 4..8 Import
|
||||
FileId(0) 4..8 import
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -885,7 +885,7 @@ pub(super) struct Foo$0 {
|
|||
expect![[r#"
|
||||
Foo Struct FileId(2) 0..41 18..21 some
|
||||
|
||||
FileId(1) 20..23 Import
|
||||
FileId(1) 20..23 import
|
||||
FileId(1) 47..50
|
||||
"#]],
|
||||
);
|
||||
|
@ -960,10 +960,10 @@ fn foo() {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
i Local FileId(0) 19..24 23..24 Write
|
||||
i Local FileId(0) 19..24 23..24 write
|
||||
|
||||
FileId(0) 34..35 Write
|
||||
FileId(0) 38..39 Read
|
||||
FileId(0) 34..35 write
|
||||
FileId(0) 38..39 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -984,8 +984,8 @@ fn foo() {
|
|||
expect![[r#"
|
||||
f Field FileId(0) 15..21 15..16
|
||||
|
||||
FileId(0) 55..56 Read
|
||||
FileId(0) 68..69 Write
|
||||
FileId(0) 55..56 read
|
||||
FileId(0) 68..69 write
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1002,7 +1002,7 @@ fn foo() {
|
|||
expect![[r#"
|
||||
i Local FileId(0) 19..20 19..20
|
||||
|
||||
FileId(0) 26..27 Write
|
||||
FileId(0) 26..27 write
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1048,7 +1048,7 @@ fn g() { f(); }
|
|||
expect![[r#"
|
||||
f Function FileId(0) 22..31 25..26
|
||||
|
||||
FileId(1) 11..12 Import
|
||||
FileId(1) 11..12 import
|
||||
FileId(1) 24..25
|
||||
"#]],
|
||||
);
|
||||
|
@ -1071,7 +1071,7 @@ fn f(s: S) {
|
|||
expect![[r#"
|
||||
field Field FileId(0) 15..24 15..20
|
||||
|
||||
FileId(0) 68..73 Read
|
||||
FileId(0) 68..73 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1095,7 +1095,7 @@ fn f(e: En) {
|
|||
expect![[r#"
|
||||
field Field FileId(0) 32..41 32..37
|
||||
|
||||
FileId(0) 102..107 Read
|
||||
FileId(0) 102..107 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1119,7 +1119,7 @@ fn f() -> m::En {
|
|||
expect![[r#"
|
||||
field Field FileId(0) 56..65 56..61
|
||||
|
||||
FileId(0) 125..130 Read
|
||||
FileId(0) 125..130 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1144,8 +1144,8 @@ impl Foo {
|
|||
expect![[r#"
|
||||
self SelfParam FileId(0) 47..51 47..51
|
||||
|
||||
FileId(0) 71..75 Read
|
||||
FileId(0) 152..156 Read
|
||||
FileId(0) 71..75 read
|
||||
FileId(0) 152..156 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1165,7 +1165,7 @@ impl Foo {
|
|||
expect![[r#"
|
||||
self SelfParam FileId(0) 47..51 47..51
|
||||
|
||||
FileId(0) 63..67 Read
|
||||
FileId(0) 63..67 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1185,16 +1185,16 @@ impl Foo {
|
|||
if let Some(decl) = refs.declaration {
|
||||
format_to!(actual, "{}", decl.nav.debug_render());
|
||||
if decl.is_mut {
|
||||
format_to!(actual, " {:?}", ReferenceCategory::Write)
|
||||
format_to!(actual, " write",)
|
||||
}
|
||||
actual += "\n\n";
|
||||
}
|
||||
|
||||
for (file_id, references) in &refs.references {
|
||||
for (range, access) in references {
|
||||
for (range, category) in references {
|
||||
format_to!(actual, "{:?} {:?}", file_id, range);
|
||||
if let Some(access) = access {
|
||||
format_to!(actual, " {:?}", access);
|
||||
for (name, _flag) in category.iter_names() {
|
||||
format_to!(actual, " {}", name.to_lowercase());
|
||||
}
|
||||
actual += "\n";
|
||||
}
|
||||
|
@ -1281,7 +1281,7 @@ fn main() {
|
|||
expect![[r#"
|
||||
a Local FileId(0) 59..60 59..60
|
||||
|
||||
FileId(0) 80..81 Read
|
||||
FileId(0) 80..81 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1299,7 +1299,7 @@ fn main() {
|
|||
expect![[r#"
|
||||
a Local FileId(0) 59..60 59..60
|
||||
|
||||
FileId(0) 80..81 Read
|
||||
FileId(0) 80..81 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1479,7 +1479,7 @@ fn test$0() {
|
|||
expect![[r#"
|
||||
test Function FileId(0) 0..33 11..15
|
||||
|
||||
FileId(0) 24..28 Test
|
||||
FileId(0) 24..28 test
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1538,9 +1538,9 @@ pub use level1::Foo;
|
|||
expect![[r#"
|
||||
Foo Struct FileId(0) 0..15 11..14
|
||||
|
||||
FileId(1) 16..19 Import
|
||||
FileId(2) 16..19 Import
|
||||
FileId(3) 16..19 Import
|
||||
FileId(1) 16..19 import
|
||||
FileId(2) 16..19 import
|
||||
FileId(3) 16..19 import
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1568,7 +1568,7 @@ lib::foo!();
|
|||
expect![[r#"
|
||||
foo Macro FileId(1) 0..61 29..32
|
||||
|
||||
FileId(0) 46..49 Import
|
||||
FileId(0) 46..49 import
|
||||
FileId(2) 0..3
|
||||
FileId(3) 5..8
|
||||
"#]],
|
||||
|
@ -1731,7 +1731,7 @@ struct Foo;
|
|||
expect![[r#"
|
||||
derive_identity Derive FileId(2) 1..107 45..60
|
||||
|
||||
FileId(0) 17..31 Import
|
||||
FileId(0) 17..31 import
|
||||
FileId(0) 56..70
|
||||
"#]],
|
||||
);
|
||||
|
@ -2055,7 +2055,7 @@ fn method() {}
|
|||
expect![[r#"
|
||||
method Field FileId(0) 60..70 60..66
|
||||
|
||||
FileId(0) 136..142 Read
|
||||
FileId(0) 136..142 read
|
||||
"#]],
|
||||
);
|
||||
check(
|
||||
|
@ -2101,7 +2101,7 @@ fn method() {}
|
|||
expect![[r#"
|
||||
method Field FileId(0) 60..70 60..66
|
||||
|
||||
FileId(0) 136..142 Read
|
||||
FileId(0) 136..142 read
|
||||
"#]],
|
||||
);
|
||||
check(
|
||||
|
@ -2160,9 +2160,9 @@ fn test() {
|
|||
expect![[r#"
|
||||
a Local FileId(0) 20..21 20..21
|
||||
|
||||
FileId(0) 56..57 Read
|
||||
FileId(0) 60..61 Read
|
||||
FileId(0) 68..69 Read
|
||||
FileId(0) 56..57 read
|
||||
FileId(0) 60..61 read
|
||||
FileId(0) 68..69 read
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue