Skip to content

Commit 3427d36

Browse files
committed
fix: Fix search not searching bodies of attributed items
1 parent e158dc7 commit 3427d36

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

crates/hir-expand/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ impl<'a> InFile<&'a SyntaxNode> {
815815
/// Falls back to the macro call range if the node cannot be mapped up fully.
816816
///
817817
/// For attributes and derives, this will point back to the attribute only.
818-
/// For the entire item `InFile::use original_file_range_full`.
818+
/// For the entire item use [`InFile::original_file_range_full`].
819819
pub fn original_file_range(self, db: &dyn db::AstDatabase) -> FileRange {
820820
match self.file_id.repr() {
821821
HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() },
@@ -830,6 +830,21 @@ impl<'a> InFile<&'a SyntaxNode> {
830830
}
831831
}
832832

833+
/// Falls back to the macro call range if the node cannot be mapped up fully.
834+
pub fn original_file_range_full(self, db: &dyn db::AstDatabase) -> FileRange {
835+
match self.file_id.repr() {
836+
HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() },
837+
HirFileIdRepr::MacroFile(mac_file) => {
838+
if let Some(res) = self.original_file_range_opt(db) {
839+
return res;
840+
}
841+
// Fall back to whole macro call.
842+
let loc = db.lookup_intern_macro_call(mac_file.macro_call_id);
843+
loc.kind.original_call_range_with_body(db)
844+
}
845+
}
846+
}
847+
833848
/// Attempts to map the syntax node back up its macro calls.
834849
pub fn original_file_range_opt(self, db: &dyn db::AstDatabase) -> Option<FileRange> {
835850
match ascend_node_border_tokens(db, self) {

crates/ide-db/src/search.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,14 @@ impl Definition {
244244
DefWithBody::Variant(v) => v.source(db).map(|src| src.syntax().cloned()),
245245
};
246246
return match def {
247-
Some(def) => SearchScope::file_range(def.as_ref().original_file_range(db)),
247+
Some(def) => SearchScope::file_range(def.as_ref().original_file_range_full(db)),
248248
None => SearchScope::single_file(file_id),
249249
};
250250
}
251251

252252
if let Definition::SelfType(impl_) = self {
253253
return match impl_.source(db).map(|src| src.syntax().cloned()) {
254-
Some(def) => SearchScope::file_range(def.as_ref().original_file_range(db)),
254+
Some(def) => SearchScope::file_range(def.as_ref().original_file_range_full(db)),
255255
None => SearchScope::single_file(file_id),
256256
};
257257
}
@@ -268,7 +268,7 @@ impl Definition {
268268
hir::GenericDef::Const(it) => it.source(db).map(|src| src.syntax().cloned()),
269269
};
270270
return match def {
271-
Some(def) => SearchScope::file_range(def.as_ref().original_file_range(db)),
271+
Some(def) => SearchScope::file_range(def.as_ref().original_file_range_full(db)),
272272
None => SearchScope::single_file(file_id),
273273
};
274274
}

0 commit comments

Comments
 (0)