forked from rojo-rbx/rojo
Expand diagnostics and exploratively fix some edge cases
This commit is contained in:
@@ -21,6 +21,8 @@ local function makeInstanceMap()
|
|||||||
if instance ~= nil then
|
if instance ~= nil then
|
||||||
self.fromIds[id] = nil
|
self.fromIds[id] = nil
|
||||||
self.fromInstances[instance] = nil
|
self.fromInstances[instance] = nil
|
||||||
|
else
|
||||||
|
Logging.warn("Attempted to remove nonexistant ID %s", tostring(id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -30,12 +32,14 @@ local function makeInstanceMap()
|
|||||||
if id ~= nil then
|
if id ~= nil then
|
||||||
self.fromInstances[instance] = nil
|
self.fromInstances[instance] = nil
|
||||||
self.fromIds[id] = nil
|
self.fromIds[id] = nil
|
||||||
|
else
|
||||||
|
Logging.warn("Attempted to remove nonexistant instance %s", tostring(instance))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function self:destroyId(id)
|
function self:destroyId(id)
|
||||||
self:removeId(id)
|
|
||||||
local instance = self.fromIds[id]
|
local instance = self.fromIds[id]
|
||||||
|
self:removeId(id)
|
||||||
|
|
||||||
if instance ~= nil then
|
if instance ~= nil then
|
||||||
local descendantsToDestroy = {}
|
local descendantsToDestroy = {}
|
||||||
@@ -51,6 +55,8 @@ local function makeInstanceMap()
|
|||||||
end
|
end
|
||||||
|
|
||||||
instance:Destroy()
|
instance:Destroy()
|
||||||
|
else
|
||||||
|
Logging.warn("Attempted to destroy nonexistant ID %s", tostring(id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::{
|
|||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Serialize)]
|
||||||
struct PathMapNode<T> {
|
struct PathMapNode<T> {
|
||||||
value: T,
|
value: T,
|
||||||
children: HashSet<PathBuf>,
|
children: HashSet<PathBuf>,
|
||||||
@@ -11,7 +11,7 @@ struct PathMapNode<T> {
|
|||||||
|
|
||||||
/// A map from paths to instance IDs, with a bit of additional data that enables
|
/// A map from paths to instance IDs, with a bit of additional data that enables
|
||||||
/// removing a path and all of its child paths from the tree more quickly.
|
/// removing a path and all of its child paths from the tree more quickly.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct PathMap<T> {
|
pub struct PathMap<T> {
|
||||||
nodes: HashMap<PathBuf, PathMapNode<T>>,
|
nodes: HashMap<PathBuf, PathMapNode<T>>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,9 @@ impl RbxSession {
|
|||||||
trace!("Snapshotting path {}", closest_path.display());
|
trace!("Snapshotting path {}", closest_path.display());
|
||||||
|
|
||||||
let snapshot = snapshot_instances_from_imfs(&imfs, &closest_path, &mut self.sync_point_names)
|
let snapshot = snapshot_instances_from_imfs(&imfs, &closest_path, &mut self.sync_point_names)
|
||||||
.expect("Could not generate instance snapshot");
|
.unwrap_or_else(|| panic!("Could not generate instance snapshot for path {}", closest_path.display()));
|
||||||
|
|
||||||
|
trace!("Snapshot: {:#?}", snapshot);
|
||||||
|
|
||||||
reconcile_subtree(&mut self.tree, instance_id, &snapshot, &mut self.path_map, &mut self.instance_metadata_map, &mut changes);
|
reconcile_subtree(&mut self.tree, instance_id, &snapshot, &mut self.path_map, &mut self.instance_metadata_map, &mut changes);
|
||||||
}
|
}
|
||||||
@@ -106,40 +108,14 @@ impl RbxSession {
|
|||||||
|
|
||||||
pub fn path_removed(&mut self, path: &Path) {
|
pub fn path_removed(&mut self, path: &Path) {
|
||||||
info!("Path removed: {}", path.display());
|
info!("Path removed: {}", path.display());
|
||||||
|
self.path_map.remove(path);
|
||||||
let instance_id = match self.path_map.remove(path) {
|
self.path_created_or_updated(path);
|
||||||
Some(id) => id,
|
|
||||||
None => {
|
|
||||||
// TODO: init.lua files won't be in the path map, that should be
|
|
||||||
// patched up!
|
|
||||||
trace!("Path was not in path map, ignoring removal.");
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
let removed_subtree = match self.tree.remove_instance(instance_id) {
|
|
||||||
Some(tree) => tree,
|
|
||||||
None => {
|
|
||||||
warn!("Rojo tried to remove an instance that was half cleaned-up. This is probably a bug in Rojo.");
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
let changes = InstanceChanges {
|
|
||||||
added: HashSet::new(),
|
|
||||||
removed: removed_subtree.iter_all_ids().collect(),
|
|
||||||
updated: HashSet::new(),
|
|
||||||
};
|
|
||||||
|
|
||||||
trace!("Pushing changes: {}", changes);
|
|
||||||
|
|
||||||
self.message_queue.push_messages(&[changes]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn path_renamed(&mut self, from_path: &Path, to_path: &Path) {
|
pub fn path_renamed(&mut self, from_path: &Path, to_path: &Path) {
|
||||||
info!("Path renamed from {} to {}", from_path.display(), to_path.display());
|
info!("Path renamed from {} to {}", from_path.display(), to_path.display());
|
||||||
self.path_removed(from_path);
|
self.path_created_or_updated(from_path);
|
||||||
self.path_created(to_path);
|
self.path_created_or_updated(to_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_tree(&self) -> &RbxTree {
|
pub fn get_tree(&self) -> &RbxTree {
|
||||||
@@ -149,6 +125,10 @@ impl RbxSession {
|
|||||||
pub fn get_instance_metadata_map(&self) -> &HashMap<RbxId, InstanceProjectNodeMetadata> {
|
pub fn get_instance_metadata_map(&self) -> &HashMap<RbxId, InstanceProjectNodeMetadata> {
|
||||||
&self.instance_metadata_map
|
&self.instance_metadata_map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn debug_get_path_map(&self) -> &PathMap<RbxId> {
|
||||||
|
&self.path_map
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn construct_oneoff_tree(project: &Project, imfs: &Imfs) -> RbxTree {
|
pub fn construct_oneoff_tree(project: &Project, imfs: &Imfs) -> RbxTree {
|
||||||
@@ -291,6 +271,7 @@ fn snapshot_instances_from_imfs<'a>(
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
ImfsItem::Directory(directory) => {
|
ImfsItem::Directory(directory) => {
|
||||||
|
// TODO: Expand init support to handle server and client scripts
|
||||||
let init_path = directory.path.join("init.lua");
|
let init_path = directory.path.join("init.lua");
|
||||||
|
|
||||||
let mut instance = if directory.children.contains(&init_path) {
|
let mut instance = if directory.children.contains(&init_path) {
|
||||||
@@ -306,7 +287,7 @@ fn snapshot_instances_from_imfs<'a>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
instance.name = if let Some(actual_name) = sync_point_names.get(imfs_path) {
|
instance.name = if let Some(actual_name) = sync_point_names.get(&directory.path) {
|
||||||
Cow::Owned(actual_name.clone())
|
Cow::Owned(actual_name.clone())
|
||||||
} else {
|
} else {
|
||||||
Cow::Borrowed(directory.path.file_name()?.to_str()?)
|
Cow::Borrowed(directory.path.file_name()?.to_str()?)
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ impl InstanceChanges {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct RbxSnapshotInstance<'a> {
|
pub struct RbxSnapshotInstance<'a> {
|
||||||
pub name: Cow<'a, str>,
|
pub name: Cow<'a, str>,
|
||||||
pub class_name: Cow<'a, str>,
|
pub class_name: Cow<'a, str>,
|
||||||
@@ -125,6 +126,14 @@ pub fn reconcile_subtree(
|
|||||||
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
|
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
|
||||||
changes: &mut InstanceChanges,
|
changes: &mut InstanceChanges,
|
||||||
) {
|
) {
|
||||||
|
if let Some(source_path) = &snapshot.source_path {
|
||||||
|
path_map.insert(source_path.clone(), id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(metadata) = &snapshot.metadata {
|
||||||
|
instance_metadata_map.insert(id, metadata.clone());
|
||||||
|
}
|
||||||
|
|
||||||
if reconcile_instance_properties(tree.get_instance_mut(id).unwrap(), snapshot) {
|
if reconcile_instance_properties(tree.get_instance_mut(id).unwrap(), snapshot) {
|
||||||
changes.updated.insert(id);
|
changes.updated.insert(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,6 +178,12 @@ impl Server {
|
|||||||
Response::svg(graphviz_to_svg(&dot_source))
|
Response::svg(graphviz_to_svg(&dot_source))
|
||||||
},
|
},
|
||||||
|
|
||||||
|
(GET) (/visualize/path_map) => {
|
||||||
|
let rbx_session = self.session.rbx_session.lock().unwrap();
|
||||||
|
|
||||||
|
Response::json(&rbx_session.debug_get_path_map())
|
||||||
|
},
|
||||||
|
|
||||||
_ => Response::empty_404()
|
_ => Response::empty_404()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user