mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-11 16:34:45 +00:00
compiler: Add current document into snapshot
It went missing before as it gets added to the `TypeLoader` that gets snapshot only after the function we snapshot in...
This commit is contained in:
parent
a1857e6154
commit
f55ef8fa08
3 changed files with 38 additions and 5 deletions
|
|
@ -83,7 +83,8 @@ pub async fn run_passes(
|
||||||
run_import_passes(doc, type_loader, diag);
|
run_import_passes(doc, type_loader, diag);
|
||||||
check_public_api::check_public_api(doc, diag);
|
check_public_api::check_public_api(doc, diag);
|
||||||
|
|
||||||
let raw_type_loader = keep_raw.then(|| crate::typeloader::snapshot(type_loader).unwrap());
|
let raw_type_loader =
|
||||||
|
keep_raw.then(|| crate::typeloader::snapshot_with_extra_doc(type_loader, doc).unwrap());
|
||||||
|
|
||||||
collect_subcomponents::collect_subcomponents(root_component);
|
collect_subcomponents::collect_subcomponents(root_component);
|
||||||
for component in (root_component.used_types.borrow().sub_components.iter())
|
for component in (root_component.used_types.borrow().sub_components.iter())
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,41 @@ pub fn snapshot(type_loader: &TypeLoader) -> Option<TypeLoader> {
|
||||||
snapshotter.snapshot_type_loader(type_loader)
|
snapshotter.snapshot_type_loader(type_loader)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This function makes a snapshot of the current state of the type loader.
|
||||||
|
/// This snapshot includes everything: Elements, Components, known types, ...
|
||||||
|
/// and can be used to roll back to earlier states in the compilation process.
|
||||||
|
///
|
||||||
|
/// One way this is used is to create a raw `TypeLoader` for analysis purposes
|
||||||
|
/// or to load a set of changes, see if those compile and then role back
|
||||||
|
///
|
||||||
|
/// The result may be `None` if the `TypeLoader` is actually in the process
|
||||||
|
/// of loading more documents and is `Some` `TypeLoader` with a copy off all
|
||||||
|
/// state connected with the original `TypeLoader`.
|
||||||
|
///
|
||||||
|
/// The Document will be added to the type_loader after it was snapshotted as well.
|
||||||
|
pub(crate) fn snapshot_with_extra_doc(
|
||||||
|
type_loader: &TypeLoader,
|
||||||
|
doc: &object_tree::Document,
|
||||||
|
) -> Option<TypeLoader> {
|
||||||
|
let mut snapshotter = Snapshotter {
|
||||||
|
component_map: HashMap::new(),
|
||||||
|
element_map: HashMap::new(),
|
||||||
|
type_register_map: HashMap::new(),
|
||||||
|
};
|
||||||
|
let mut result = snapshotter.snapshot_type_loader(type_loader);
|
||||||
|
|
||||||
|
let new_doc = snapshotter.snapshot_document(doc);
|
||||||
|
|
||||||
|
if let Some(doc_node) = &new_doc.node {
|
||||||
|
let path = doc_node.source_file.path().to_path_buf();
|
||||||
|
if let Some(r) = &mut result {
|
||||||
|
r.all_documents.docs.insert(path, new_doc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) struct Snapshotter {
|
pub(crate) struct Snapshotter {
|
||||||
component_map:
|
component_map:
|
||||||
HashMap<by_address::ByAddress<Rc<object_tree::Component>>, Rc<object_tree::Component>>,
|
HashMap<by_address::ByAddress<Rc<object_tree::Component>>, Rc<object_tree::Component>>,
|
||||||
|
|
|
||||||
|
|
@ -271,10 +271,7 @@ pub fn apply_workspace_edit(
|
||||||
.drain()
|
.drain()
|
||||||
.filter_map(|(url, v)| {
|
.filter_map(|(url, v)| {
|
||||||
let edit_result = v.finalize()?;
|
let edit_result = v.finalize()?;
|
||||||
Some(EditedText {
|
Some(EditedText { url, contents: edit_result.0 })
|
||||||
url,
|
|
||||||
contents: edit_result.0,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue