aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/descriptors/module/nameres.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module/nameres.rs')
-rw-r--r--crates/ra_analysis/src/descriptors/module/nameres.rs64
1 files changed, 63 insertions, 1 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/nameres.rs b/crates/ra_analysis/src/descriptors/module/nameres.rs
index 4c555421d..648ec5e43 100644
--- a/crates/ra_analysis/src/descriptors/module/nameres.rs
+++ b/crates/ra_analysis/src/descriptors/module/nameres.rs
@@ -358,7 +358,8 @@ where
358#[cfg(test)] 358#[cfg(test)]
359mod tests { 359mod tests {
360 use crate::{ 360 use crate::{
361 mock_analysis::analysis_and_position, 361 AnalysisChange,
362 mock_analysis::{MockAnalysis, analysis_and_position},
362 descriptors::{DescriptorDatabase, module::ModuleDescriptor}, 363 descriptors::{DescriptorDatabase, module::ModuleDescriptor},
363 input::FilesDatabase, 364 input::FilesDatabase,
364}; 365};
@@ -396,4 +397,65 @@ mod tests {
396 let resolution = &item_map.per_module[&module_id].items[&name]; 397 let resolution = &item_map.per_module[&module_id].items[&name];
397 assert!(resolution.def_id.is_some()); 398 assert!(resolution.def_id.is_some());
398 } 399 }
400
401 #[test]
402 fn typing_inside_a_function_should_not_invalidate_item_map() {
403 let mock_analysis = MockAnalysis::with_files(
404 "
405 //- /lib.rs
406 mod foo;
407
408 use crate::foo::bar::Baz;
409
410 fn foo() -> i32 {
411 1 + 1
412 }
413 //- /foo/mod.rs
414 pub mod bar;
415
416 //- /foo/bar.rs
417 pub struct Baz;
418 ",
419 );
420
421 let file_id = mock_analysis.id_of("/lib.rs");
422 let mut host = mock_analysis.analysis_host();
423
424 let source_root = host.analysis().imp.db.file_source_root(file_id);
425
426 {
427 let db = host.analysis().imp.db;
428 let events = db.log_executed(|| {
429 db._item_map(source_root).unwrap();
430 });
431 assert!(format!("{:?}", events).contains("_item_map"))
432 }
433
434 let mut change = AnalysisChange::new();
435
436 change.change_file(
437 file_id,
438 "
439 mod foo;
440
441 use crate::foo::bar::Baz;
442
443 fn foo() -> i32 { 92 }
444 "
445 .to_string(),
446 );
447
448 host.apply_change(change);
449
450 {
451 let db = host.analysis().imp.db;
452 let events = db.log_executed(|| {
453 db._item_map(source_root).unwrap();
454 });
455 // assert!(
456 // !format!("{:?}", events).contains("_item_map"),
457 // "{:#?}", events
458 // )
459 }
460 }
399} 461}