Skip to content
Closed
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
52 changes: 52 additions & 0 deletions crates/hir_def/src/nameres/tests/incremental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,55 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
}
}

#[test]
fn typing_inside_a_function_should_not_invalidate_expansions() {
let (mut db, pos) = TestDB::with_position(
r#"
//- /lib.rs
macro_rules! m {
($ident:ident) => {
fn $ident() { };
}
}
mod foo;

//- /foo/mod.rs
pub mod bar;

//- /foo/bar.rs
m!(X);
fn quux() { 1$0 }
m!(Y);
m!(Z);
"#,
);
let krate = db.test_crate();
{
let events = db.log_executed(|| {
let crate_def_map = db.crate_def_map(krate);
let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
assert_eq!(module_data.scope.resolutions().count(), 4);
});
let n_recalculated_item_trees = events.iter().filter(|it| it.contains("item_tree")).count();
assert_eq!(n_recalculated_item_trees, 6);
}

let new_text = r#"
m!(X);
fn quux() { 92 }
m!(Y);
m!(Z);
"#;
db.set_file_text(pos.file_id, Arc::new(new_text.to_string()));

{
let events = db.log_executed(|| {
let crate_def_map = db.crate_def_map(krate);
let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
assert_eq!(module_data.scope.resolutions().count(), 4);
});
let n_recalculated_item_trees = events.iter().filter(|it| it.contains("item_tree")).count();
assert_eq!(n_recalculated_item_trees, 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonas-schievink currently this returns 4 rather than 1. That is, we recalculate item_tree for file itself, as well as for each of the macro calls. Am I correct that we don't expect this happening?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that shouldn't happen

}
}