Skip to content

Commit 6584e63

Browse files
committed
minor: Simplify
1 parent 0a8c784 commit 6584e63

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

crates/ide/src/highlight_related.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use syntax::{
1515
ast::{self, HasLoopBody},
1616
match_ast, AstNode,
1717
SyntaxKind::{self, IDENT, INT_NUMBER},
18-
SyntaxNode, SyntaxToken, TextRange, T,
18+
SyntaxToken, TextRange, T,
1919
};
2020

21-
use crate::{navigation_target::ToNav, references, NavigationTarget, TryToNav};
21+
use crate::{navigation_target::ToNav, NavigationTarget, TryToNav};
2222

2323
#[derive(PartialEq, Eq, Hash)]
2424
pub struct HighlightedRange {
@@ -81,7 +81,7 @@ pub(crate) fn highlight_related(
8181
}
8282
T![|] if config.closure_captures => highlight_closure_captures(sema, token, file_id),
8383
T![move] if config.closure_captures => highlight_closure_captures(sema, token, file_id),
84-
_ if config.references => highlight_references(sema, &syntax, token, pos),
84+
_ if config.references => highlight_references(sema, token, pos),
8585
_ => None,
8686
}
8787
}
@@ -129,7 +129,6 @@ fn highlight_closure_captures(
129129

130130
fn highlight_references(
131131
sema: &Semantics<'_, RootDatabase>,
132-
node: &SyntaxNode,
133132
token: SyntaxToken,
134133
FilePosition { file_id, offset }: FilePosition,
135134
) -> Option<Vec<HighlightedRange>> {
@@ -239,7 +238,7 @@ fn highlight_references(
239238
continue;
240239
}
241240
let hl_range = nav.focus_range.map(|range| {
242-
let category = references::decl_mutability(&def, node, range)
241+
let category = matches!(def, Definition::Local(l) if l.is_mut(sema.db))
243242
.then_some(ReferenceCategory::Write);
244243
HighlightedRange { range, category }
245244
});

crates/ide/src/references.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use ide_db::{
2121
use itertools::Itertools;
2222
use nohash_hasher::IntMap;
2323
use syntax::{
24-
algo::find_node_at_offset,
2524
ast::{self, HasName},
2625
match_ast, AstNode,
2726
SyntaxKind::*,
@@ -98,9 +97,8 @@ pub(crate) fn find_all_refs(
9897
.or_default()
9998
.push((extra_ref.focus_or_full_range(), None));
10099
}
101-
let decl_range = nav.focus_or_full_range();
102100
Declaration {
103-
is_mut: decl_mutability(&def, sema.parse(nav.file_id).syntax(), decl_range),
101+
is_mut: matches!(def, Definition::Local(l) if l.is_mut(sema.db)),
104102
nav,
105103
}
106104
});
@@ -189,21 +187,6 @@ pub(crate) fn find_defs<'a>(
189187
)
190188
}
191189

192-
pub(crate) fn decl_mutability(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> bool {
193-
match def {
194-
Definition::Local(_) | Definition::Field(_) => {}
195-
_ => return false,
196-
};
197-
198-
match find_node_at_offset::<ast::LetStmt>(syntax, range.start()) {
199-
Some(stmt) if stmt.initializer().is_some() => match stmt.pat() {
200-
Some(ast::Pat::IdentPat(it)) => it.mut_token().is_some(),
201-
_ => false,
202-
},
203-
_ => false,
204-
}
205-
}
206-
207190
/// Filter out all non-literal usages for adt-defs
208191
fn retain_adt_literal_usages(
209192
usages: &mut UsageSearchResult,

0 commit comments

Comments
 (0)