Unnamed repository; edit this file 'description' to name the repository.
Early exit in search properly
Lukas Wirth 2025-01-15
parent d82e1a2 · commit 2a89e4a
-rw-r--r--crates/hir/src/semantics.rs2
-rw-r--r--crates/ide-db/src/search.rs11
2 files changed, 9 insertions, 4 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index a1a596675b..41ec7f3e7a 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -1756,7 +1756,7 @@ impl<'db> SemanticsImpl<'db> {
let file_id = self.lookup(&root_node).unwrap_or_else(|| {
panic!(
"\n\nFailed to lookup {:?} in this Semantics.\n\
- Make sure to use only query nodes, derived from this instance of Semantics.\n\
+ Make sure to only query nodes derived from this instance of Semantics.\n\
root node: {:?}\n\
known nodes: {}\n\n",
node,
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs
index 68199dd871..a75aba137b 100644
--- a/crates/ide-db/src/search.rs
+++ b/crates/ide-db/src/search.rs
@@ -953,14 +953,19 @@ impl<'a> FindUsages<'a> {
// Search for occurrences of the items name
for offset in Self::match_indices(&text, finder, search_range) {
- tree.token_at_offset(offset).for_each(|token| {
- let Some(str_token) = ast::String::cast(token.clone()) else { return };
+ let ret = tree.token_at_offset(offset).any(|token| {
+ let Some(str_token) = ast::String::cast(token.clone()) else { return false };
if let Some((range, Some(nameres))) =
sema.check_for_format_args_template(token, offset)
{
- if self.found_format_args_ref(file_id, range, str_token, nameres, sink) {}
+ return self
+ .found_format_args_ref(file_id, range, str_token, nameres, sink);
}
+ false
});
+ if ret {
+ return;
+ }
for name in
Self::find_nodes(sema, name, &tree, offset).filter_map(ast::NameLike::cast)