mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Only report unique text ranges in highlight_related
This commit is contained in:
parent
72bfbb0691
commit
99f1e66997
3 changed files with 8 additions and 10 deletions
|
@ -538,6 +538,8 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note this return type is deliberate as [`find_nodes_at_offset_with_descend`] wants to stop
|
||||||
|
// traversing the inner iterator when it finds a node.
|
||||||
fn descend_node_at_offset(
|
fn descend_node_at_offset(
|
||||||
&self,
|
&self,
|
||||||
node: &SyntaxNode,
|
node: &SyntaxNode,
|
||||||
|
|
|
@ -6,7 +6,7 @@ use ide_db::{
|
||||||
search::{FileReference, ReferenceAccess, SearchScope},
|
search::{FileReference, ReferenceAccess, SearchScope},
|
||||||
RootDatabase,
|
RootDatabase,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use rustc_hash::FxHashSet;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, LoopBodyOwner},
|
ast::{self, LoopBodyOwner},
|
||||||
match_ast, AstNode, SyntaxNode, SyntaxToken, TextRange, TextSize, T,
|
match_ast, AstNode, SyntaxNode, SyntaxToken, TextRange, TextSize, T,
|
||||||
|
@ -14,6 +14,7 @@ use syntax::{
|
||||||
|
|
||||||
use crate::{display::TryToNav, references, NavigationTarget};
|
use crate::{display::TryToNav, references, NavigationTarget};
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, Hash)]
|
||||||
pub struct HighlightedRange {
|
pub struct HighlightedRange {
|
||||||
pub range: TextRange,
|
pub range: TextRange,
|
||||||
pub access: Option<ReferenceAccess>,
|
pub access: Option<ReferenceAccess>,
|
||||||
|
@ -100,11 +101,11 @@ fn highlight_references(
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let res: Vec<_> = declarations.chain(usages).collect();
|
let res: FxHashSet<_> = declarations.chain(usages).collect();
|
||||||
if res.is_empty() {
|
if res.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(res)
|
Some(res.into_iter().collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +277,7 @@ fn find_defs(
|
||||||
sema: &Semantics<RootDatabase>,
|
sema: &Semantics<RootDatabase>,
|
||||||
syntax: &SyntaxNode,
|
syntax: &SyntaxNode,
|
||||||
offset: TextSize,
|
offset: TextSize,
|
||||||
) -> Vec<Definition> {
|
) -> FxHashSet<Definition> {
|
||||||
sema.find_nodes_at_offset_with_descend(syntax, offset)
|
sema.find_nodes_at_offset_with_descend(syntax, offset)
|
||||||
.flat_map(|name_like| {
|
.flat_map(|name_like| {
|
||||||
Some(match name_like {
|
Some(match name_like {
|
||||||
|
@ -309,7 +310,6 @@ fn find_defs(
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
.unique()
|
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,8 +423,6 @@ macro_rules! foo {
|
||||||
|
|
||||||
foo!(bar$0);
|
foo!(bar$0);
|
||||||
// ^^^
|
// ^^^
|
||||||
// ^^^
|
|
||||||
// ^^^
|
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let bar: bar = bar();
|
let bar: bar = bar();
|
||||||
// ^^^
|
// ^^^
|
||||||
|
@ -443,7 +441,6 @@ macro_rules! foo {
|
||||||
|
|
||||||
foo!(bar);
|
foo!(bar);
|
||||||
// ^^^
|
// ^^^
|
||||||
// ^^^
|
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let bar: bar$0 = bar();
|
let bar: bar$0 = bar();
|
||||||
// ^^^
|
// ^^^
|
||||||
|
@ -873,7 +870,6 @@ fn function(field: u32) {
|
||||||
//^^^^^
|
//^^^^^
|
||||||
Struct { field$0 }
|
Struct { field$0 }
|
||||||
//^^^^^ read
|
//^^^^^ read
|
||||||
//^^^^^ read
|
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub struct FileReference {
|
||||||
pub access: Option<ReferenceAccess>,
|
pub access: Option<ReferenceAccess>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum ReferenceAccess {
|
pub enum ReferenceAccess {
|
||||||
Read,
|
Read,
|
||||||
Write,
|
Write,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue