From 955d2eea452b82f7286de902424d2cf5d4b78401 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 21 Nov 2018 20:44:05 +0300 Subject: add test loggin API to db --- .../ra_analysis/src/descriptors/module/nameres.rs | 64 +++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'crates/ra_analysis/src/descriptors/module') 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 #[cfg(test)] mod tests { use crate::{ - mock_analysis::analysis_and_position, + AnalysisChange, + mock_analysis::{MockAnalysis, analysis_and_position}, descriptors::{DescriptorDatabase, module::ModuleDescriptor}, input::FilesDatabase, }; @@ -396,4 +397,65 @@ mod tests { let resolution = &item_map.per_module[&module_id].items[&name]; assert!(resolution.def_id.is_some()); } + + #[test] + fn typing_inside_a_function_should_not_invalidate_item_map() { + let mock_analysis = MockAnalysis::with_files( + " + //- /lib.rs + mod foo; + + use crate::foo::bar::Baz; + + fn foo() -> i32 { + 1 + 1 + } + //- /foo/mod.rs + pub mod bar; + + //- /foo/bar.rs + pub struct Baz; + ", + ); + + let file_id = mock_analysis.id_of("/lib.rs"); + let mut host = mock_analysis.analysis_host(); + + let source_root = host.analysis().imp.db.file_source_root(file_id); + + { + let db = host.analysis().imp.db; + let events = db.log_executed(|| { + db._item_map(source_root).unwrap(); + }); + assert!(format!("{:?}", events).contains("_item_map")) + } + + let mut change = AnalysisChange::new(); + + change.change_file( + file_id, + " + mod foo; + + use crate::foo::bar::Baz; + + fn foo() -> i32 { 92 } + " + .to_string(), + ); + + host.apply_change(change); + + { + let db = host.analysis().imp.db; + let events = db.log_executed(|| { + db._item_map(source_root).unwrap(); + }); + // assert!( + // !format!("{:?}", events).contains("_item_map"), + // "{:#?}", events + // ) + } + } } -- cgit v1.2.3