mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
commit
e7a8d21a52
2 changed files with 5 additions and 23 deletions
|
@ -15,10 +15,10 @@ use syntax::{
|
|||
ast::{self, HasLoopBody},
|
||||
match_ast, AstNode,
|
||||
SyntaxKind::{self, IDENT, INT_NUMBER},
|
||||
SyntaxNode, SyntaxToken, TextRange, T,
|
||||
SyntaxToken, TextRange, T,
|
||||
};
|
||||
|
||||
use crate::{navigation_target::ToNav, references, NavigationTarget, TryToNav};
|
||||
use crate::{navigation_target::ToNav, NavigationTarget, TryToNav};
|
||||
|
||||
#[derive(PartialEq, Eq, Hash)]
|
||||
pub struct HighlightedRange {
|
||||
|
@ -81,7 +81,7 @@ pub(crate) fn highlight_related(
|
|||
}
|
||||
T![|] if config.closure_captures => highlight_closure_captures(sema, token, file_id),
|
||||
T![move] if config.closure_captures => highlight_closure_captures(sema, token, file_id),
|
||||
_ if config.references => highlight_references(sema, &syntax, token, pos),
|
||||
_ if config.references => highlight_references(sema, token, pos),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,6 @@ fn highlight_closure_captures(
|
|||
|
||||
fn highlight_references(
|
||||
sema: &Semantics<'_, RootDatabase>,
|
||||
node: &SyntaxNode,
|
||||
token: SyntaxToken,
|
||||
FilePosition { file_id, offset }: FilePosition,
|
||||
) -> Option<Vec<HighlightedRange>> {
|
||||
|
@ -239,7 +238,7 @@ fn highlight_references(
|
|||
continue;
|
||||
}
|
||||
let hl_range = nav.focus_range.map(|range| {
|
||||
let category = references::decl_mutability(&def, node, range)
|
||||
let category = matches!(def, Definition::Local(l) if l.is_mut(sema.db))
|
||||
.then_some(ReferenceCategory::Write);
|
||||
HighlightedRange { range, category }
|
||||
});
|
||||
|
|
|
@ -21,7 +21,6 @@ use ide_db::{
|
|||
use itertools::Itertools;
|
||||
use nohash_hasher::IntMap;
|
||||
use syntax::{
|
||||
algo::find_node_at_offset,
|
||||
ast::{self, HasName},
|
||||
match_ast, AstNode,
|
||||
SyntaxKind::*,
|
||||
|
@ -98,9 +97,8 @@ pub(crate) fn find_all_refs(
|
|||
.or_default()
|
||||
.push((extra_ref.focus_or_full_range(), None));
|
||||
}
|
||||
let decl_range = nav.focus_or_full_range();
|
||||
Declaration {
|
||||
is_mut: decl_mutability(&def, sema.parse(nav.file_id).syntax(), decl_range),
|
||||
is_mut: matches!(def, Definition::Local(l) if l.is_mut(sema.db)),
|
||||
nav,
|
||||
}
|
||||
});
|
||||
|
@ -189,21 +187,6 @@ pub(crate) fn find_defs<'a>(
|
|||
)
|
||||
}
|
||||
|
||||
pub(crate) fn decl_mutability(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> bool {
|
||||
match def {
|
||||
Definition::Local(_) | Definition::Field(_) => {}
|
||||
_ => return false,
|
||||
};
|
||||
|
||||
match find_node_at_offset::<ast::LetStmt>(syntax, range.start()) {
|
||||
Some(stmt) if stmt.initializer().is_some() => match stmt.pat() {
|
||||
Some(ast::Pat::IdentPat(it)) => it.mut_token().is_some(),
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Filter out all non-literal usages for adt-defs
|
||||
fn retain_adt_literal_usages(
|
||||
usages: &mut UsageSearchResult,
|
||||
|
|
Loading…
Reference in a new issue