Skip to content

Commit 99f1e66

Browse files
committed
Only report unique text ranges in highlight_related
1 parent 72bfbb0 commit 99f1e66

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

crates/hir/src/semantics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ impl<'db> SemanticsImpl<'db> {
538538
res
539539
}
540540

541+
// Note this return type is deliberate as [`find_nodes_at_offset_with_descend`] wants to stop
542+
// traversing the inner iterator when it finds a node.
541543
fn descend_node_at_offset(
542544
&self,
543545
node: &SyntaxNode,

crates/ide/src/highlight_related.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ use ide_db::{
66
search::{FileReference, ReferenceAccess, SearchScope},
77
RootDatabase,
88
};
9-
use itertools::Itertools;
9+
use rustc_hash::FxHashSet;
1010
use syntax::{
1111
ast::{self, LoopBodyOwner},
1212
match_ast, AstNode, SyntaxNode, SyntaxToken, TextRange, TextSize, T,
1313
};
1414

1515
use crate::{display::TryToNav, references, NavigationTarget};
1616

17+
#[derive(PartialEq, Eq, Hash)]
1718
pub struct HighlightedRange {
1819
pub range: TextRange,
1920
pub access: Option<ReferenceAccess>,
@@ -100,11 +101,11 @@ fn highlight_references(
100101
})
101102
});
102103

103-
let res: Vec<_> = declarations.chain(usages).collect();
104+
let res: FxHashSet<_> = declarations.chain(usages).collect();
104105
if res.is_empty() {
105106
None
106107
} else {
107-
Some(res)
108+
Some(res.into_iter().collect())
108109
}
109110
}
110111

@@ -276,7 +277,7 @@ fn find_defs(
276277
sema: &Semantics<RootDatabase>,
277278
syntax: &SyntaxNode,
278279
offset: TextSize,
279-
) -> Vec<Definition> {
280+
) -> FxHashSet<Definition> {
280281
sema.find_nodes_at_offset_with_descend(syntax, offset)
281282
.flat_map(|name_like| {
282283
Some(match name_like {
@@ -309,7 +310,6 @@ fn find_defs(
309310
})
310311
})
311312
.flatten()
312-
.unique()
313313
.collect()
314314
}
315315

@@ -423,8 +423,6 @@ macro_rules! foo {
423423
424424
foo!(bar$0);
425425
// ^^^
426-
// ^^^
427-
// ^^^
428426
fn foo() {
429427
let bar: bar = bar();
430428
// ^^^
@@ -443,7 +441,6 @@ macro_rules! foo {
443441
444442
foo!(bar);
445443
// ^^^
446-
// ^^^
447444
fn foo() {
448445
let bar: bar$0 = bar();
449446
// ^^^
@@ -873,7 +870,6 @@ fn function(field: u32) {
873870
//^^^^^
874871
Struct { field$0 }
875872
//^^^^^ read
876-
//^^^^^ read
877873
}
878874
"#,
879875
);

crates/ide_db/src/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct FileReference {
6161
pub access: Option<ReferenceAccess>,
6262
}
6363

64-
#[derive(Debug, Copy, Clone, PartialEq)]
64+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
6565
pub enum ReferenceAccess {
6666
Read,
6767
Write,

0 commit comments

Comments
 (0)