@@ -87,6 +87,41 @@ pub fn snapshot(type_loader: &TypeLoader) -> Option<TypeLoader> {
87
87
snapshotter. snapshot_type_loader ( type_loader)
88
88
}
89
89
90
+ /// This function makes a snapshot of the current state of the type loader.
91
+ /// This snapshot includes everything: Elements, Components, known types, ...
92
+ /// and can be used to roll back to earlier states in the compilation process.
93
+ ///
94
+ /// One way this is used is to create a raw `TypeLoader` for analysis purposes
95
+ /// or to load a set of changes, see if those compile and then role back
96
+ ///
97
+ /// The result may be `None` if the `TypeLoader` is actually in the process
98
+ /// of loading more documents and is `Some` `TypeLoader` with a copy off all
99
+ /// state connected with the original `TypeLoader`.
100
+ ///
101
+ /// The Document will be added to the type_loader after it was snapshotted as well.
102
+ pub ( crate ) fn snapshot_with_extra_doc (
103
+ type_loader : & TypeLoader ,
104
+ doc : & object_tree:: Document ,
105
+ ) -> Option < TypeLoader > {
106
+ let mut snapshotter = Snapshotter {
107
+ component_map : HashMap :: new ( ) ,
108
+ element_map : HashMap :: new ( ) ,
109
+ type_register_map : HashMap :: new ( ) ,
110
+ } ;
111
+ let mut result = snapshotter. snapshot_type_loader ( type_loader) ;
112
+
113
+ let new_doc = snapshotter. snapshot_document ( doc) ;
114
+
115
+ if let Some ( doc_node) = & new_doc. node {
116
+ let path = doc_node. source_file . path ( ) . to_path_buf ( ) ;
117
+ if let Some ( r) = & mut result {
118
+ r. all_documents . docs . insert ( path, new_doc) ;
119
+ }
120
+ }
121
+
122
+ result
123
+ }
124
+
90
125
pub ( crate ) struct Snapshotter {
91
126
component_map :
92
127
HashMap < by_address:: ByAddress < Rc < object_tree:: Component > > , Rc < object_tree:: Component > > ,
0 commit comments