Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/hir/src/semantics/source_to_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,21 @@ impl<'db> SourceToDefCache<'db> {
self.expansion_info_cache.entry(macro_file).or_insert_with(|| {
let exp_info = macro_file.expansion_info(db);

// Ensure that the cache contains syntax nodes from expanded macros,
// whose root may be in another file.
let InMacroFile { file_id, value } = exp_info.expanded();
Self::cache(&mut self.root_to_file_cache, value, file_id.into());

// include!("foo.rs") invocations are awkward: in addition to the
// expansion site there's the included file (foo.rs), so we need to
// ensure that it exists in the cache too.
if macro_file.is_include_macro(db) {
let arg = exp_info.arg();
if let Some(arg_node) = arg.value {
Self::cache(&mut self.root_to_file_cache, arg_node.tree_top(), arg.file_id);
}
}

exp_info
})
}
Expand Down
17 changes: 17 additions & 0 deletions crates/ide-assists/src/handlers/inline_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,23 @@ macro_rules! num {
);
}

#[test]
fn inline_macro_in_included_file() {
// Regression test for climbing from the included file into an uncached includer root.
check_assist_not_applicable(
inline_macro,
r#"
//- minicore:include
//- /main.rs
include!("a.rs");
//- /a.rs
fn foo() {
let x = 1$0;
}
"#,
);
}

#[test]
fn inline_macro_simple_not_applicable_broken_macro() {
// FIXME: This is a bug. The macro should not expand, but it's
Expand Down