Clean up warnings, add RojoTree into ServeSession

This commit is contained in:
Lucien Greathouse
2019-09-09 15:17:03 -07:00
parent 3e759b3e8e
commit bb6ab74c19
9 changed files with 23 additions and 21 deletions

View File

@@ -6,3 +6,4 @@ sessionId: "[session id]"
serverVersion: 0.5.0 serverVersion: 0.5.0
protocolVersion: 3 protocolVersion: 3
expectedPlaceIds: ~ expectedPlaceIds: ~
rootInstanceId: "[root id]"

View File

@@ -28,7 +28,8 @@ fn empty() {
let info = session.wait_to_come_online(); let info = session.wait_to_come_online();
assert_yaml_snapshot!(info, { assert_yaml_snapshot!(info, {
".sessionId" => "[session id]" ".sessionId" => "[session id]",
".rootInstanceId" => "[root id]"
}); });
}); });
} }

View File

@@ -70,7 +70,7 @@ pub fn serve(options: &ServeOptions) -> Result<(), ServeError> {
let patch_set = compute_patch_set(&snapshot, &tree, root_id); let patch_set = compute_patch_set(&snapshot, &tree, root_id);
apply_patch_set(&mut tree, &patch_set); apply_patch_set(&mut tree, &patch_set);
let session = Arc::new(ServeSession::new(maybe_project)); let session = Arc::new(ServeSession::new(tree, maybe_project));
let server = LiveServer::new(session); let server = LiveServer::new(session);
server.start(port); server.start(port);

View File

@@ -19,19 +19,6 @@ impl<T> FsResultExt<T> for Result<T, FsError> {
} }
} }
// TODO: New error type that contains errors specific to our application,
// wrapping io::Error either directly or through another error type that has
// path information.
//
// It's possible that we should hoist up the path information one more level, or
// destructure/restructure information to hoist the path out of FsError and just
// embed io::Error?
pub enum ImfsError {
NotFound,
WrongKind,
Io(io::Error),
}
/// A wrapper around io::Error that also attaches the path associated with the /// A wrapper around io::Error that also attaches the path associated with the
/// error. /// error.
#[derive(Debug, Fail)] #[derive(Debug, Fail)]

View File

@@ -34,7 +34,7 @@ struct SourceProject {
impl SourceProject { impl SourceProject {
/// Consumes the SourceProject and yields a Project, ready for prime-time. /// Consumes the SourceProject and yields a Project, ready for prime-time.
pub fn into_project(mut self, project_file_location: &Path) -> Project { pub fn into_project(self, project_file_location: &Path) -> Project {
let tree = self.tree.into_project_node(project_file_location); let tree = self.tree.into_project_node(project_file_location);
Project { Project {

View File

@@ -1,23 +1,29 @@
use std::collections::HashSet; use std::collections::HashSet;
use crate::{project::Project, session_id::SessionId}; use crate::{project::Project, session_id::SessionId, snapshot::RojoTree};
/// Contains all of the state for a Rojo serve session. /// Contains all of the state for a Rojo serve session.
pub struct ServeSession { pub struct ServeSession {
root_project: Option<Project>, root_project: Option<Project>,
session_id: SessionId, session_id: SessionId,
tree: RojoTree,
} }
impl ServeSession { impl ServeSession {
pub fn new(root_project: Option<Project>) -> ServeSession { pub fn new(tree: RojoTree, root_project: Option<Project>) -> ServeSession {
let session_id = SessionId::new(); let session_id = SessionId::new();
ServeSession { ServeSession {
session_id, session_id,
root_project, root_project,
tree,
} }
} }
pub fn tree(&self) -> &RojoTree {
&self.tree
}
pub fn session_id(&self) -> SessionId { pub fn session_id(&self) -> SessionId {
self.session_id self.session_id
} }

View File

@@ -111,10 +111,12 @@ fn snapshot_init<F: ImfsFetcher>(
let init_path = folder_entry.path().join(init_name); let init_path = folder_entry.path().join(init_name);
if let Some(init_entry) = imfs.get(init_path).with_not_found()? { if let Some(init_entry) = imfs.get(init_path).with_not_found()? {
if let Some(mut dir_snapshot) = SnapshotDir::from_imfs(imfs, folder_entry)? { if let Some(dir_snapshot) = SnapshotDir::from_imfs(imfs, folder_entry)? {
if let Some(mut init_snapshot) = snapshot_lua_file(imfs, &init_entry)? { if let Some(mut init_snapshot) = snapshot_lua_file(imfs, &init_entry)? {
init_snapshot.name = dir_snapshot.name; init_snapshot.name = dir_snapshot.name;
init_snapshot.children = dir_snapshot.children; init_snapshot.children = dir_snapshot.children;
// TODO: Metadata
// TODO: Validate directory class name is "Folder"
return Ok(Some(init_snapshot)); return Ok(Some(init_snapshot));
} }

View File

@@ -53,11 +53,15 @@ impl ApiService {
/// Get a summary of information about the server /// Get a summary of information about the server
fn handle_api_rojo(&self) -> Response<Body> { fn handle_api_rojo(&self) -> Response<Body> {
let tree = self.serve_session.tree();
let root_instance_id = tree.get_root_id();
response_json(&ServerInfoResponse { response_json(&ServerInfoResponse {
server_version: SERVER_VERSION.to_owned(), server_version: SERVER_VERSION.to_owned(),
protocol_version: PROTOCOL_VERSION, protocol_version: PROTOCOL_VERSION,
session_id: self.serve_session.session_id(), session_id: self.serve_session.session_id(),
expected_place_ids: self.serve_session.serve_place_ids().map(Clone::clone), expected_place_ids: self.serve_session.serve_place_ids().cloned(),
root_instance_id,
}) })
} }

View File

@@ -2,6 +2,7 @@
use std::collections::HashSet; use std::collections::HashSet;
use rbx_dom_weak::RbxId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::session_id::SessionId; use crate::session_id::SessionId;
@@ -20,7 +21,7 @@ pub struct ServerInfoResponse {
pub server_version: String, pub server_version: String,
pub protocol_version: u64, pub protocol_version: u64,
pub expected_place_ids: Option<HashSet<u64>>, pub expected_place_ids: Option<HashSet<u64>>,
// pub root_instance_id: RbxId, pub root_instance_id: RbxId,
} }
/// Response body from /api/read/{id} /// Response body from /api/read/{id}