mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 12:45:05 +00:00
Remove InstanceSnapshotContext in favor of InstanceContext (#271)
* Drop plugin context on the floor * Remove redirect from old context to new context * Pass InstanceContext via & instead of &mut reference * Re-use context value in ChangeProcessor from metadata
This commit is contained in:
committed by
GitHub
parent
12df80da56
commit
948303aac8
@@ -14,7 +14,7 @@ use crate::{
|
||||
snapshot::{
|
||||
apply_patch_set, compute_patch_set, AppliedPatchSet, InstigatingSource, PatchSet, RojoTree,
|
||||
},
|
||||
snapshot_middleware::{snapshot_from_vfs, snapshot_project_node, InstanceSnapshotContext},
|
||||
snapshot_middleware::{snapshot_from_vfs, snapshot_project_node},
|
||||
vfs::{FsResultExt, Vfs, VfsEvent, VfsFetcher},
|
||||
};
|
||||
|
||||
@@ -141,10 +141,6 @@ fn update_affected_instances<F: VfsFetcher>(
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: Use persisted snapshot context struct instead of recreating it
|
||||
// every time.
|
||||
let mut snapshot_context = InstanceSnapshotContext::default();
|
||||
|
||||
// How we process a file change event depends on what created this
|
||||
// file/folder in the first place.
|
||||
let applied_patch_set = match instigating_source {
|
||||
@@ -161,7 +157,7 @@ fn update_affected_instances<F: VfsFetcher>(
|
||||
// starting at that path and use it as the source for
|
||||
// our patch.
|
||||
|
||||
let snapshot = snapshot_from_vfs(&mut snapshot_context, &vfs, &entry)
|
||||
let snapshot = snapshot_from_vfs(&metadata.context, &vfs, &entry)
|
||||
.expect("snapshot failed")
|
||||
.expect("snapshot did not return an instance");
|
||||
|
||||
@@ -188,7 +184,7 @@ fn update_affected_instances<F: VfsFetcher>(
|
||||
// the project file, we snapshot the entire project node again.
|
||||
|
||||
let snapshot =
|
||||
snapshot_project_node(&mut snapshot_context, instance_name, project_node, &vfs)
|
||||
snapshot_project_node(&metadata.context, instance_name, project_node, &vfs)
|
||||
.expect("snapshot failed")
|
||||
.expect("snapshot did not return an instance");
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
//! Initialization routines that are used by more than one Rojo command or
|
||||
//! utility.
|
||||
|
||||
use std::{path::Path, sync::Arc};
|
||||
use std::path::Path;
|
||||
|
||||
use rbx_dom_weak::RbxInstanceProperties;
|
||||
|
||||
use crate::{
|
||||
project::{Project, ProjectLoadError},
|
||||
snapshot::{apply_patch_set, compute_patch_set, InstancePropertiesWithMeta, RojoTree},
|
||||
snapshot_middleware::{snapshot_from_vfs, InstanceSnapshotContext, SnapshotPluginContext},
|
||||
snapshot::{
|
||||
apply_patch_set, compute_patch_set, InstanceContext, InstancePropertiesWithMeta, RojoTree,
|
||||
},
|
||||
snapshot_middleware::snapshot_from_vfs,
|
||||
vfs::{Vfs, VfsFetcher},
|
||||
};
|
||||
|
||||
@@ -36,13 +38,12 @@ pub fn start<F: VfsFetcher>(
|
||||
let root_id = tree.get_root_id();
|
||||
|
||||
log::trace!("Constructing snapshot context");
|
||||
let mut snapshot_context = InstanceSnapshotContext::default();
|
||||
let snapshot_context = InstanceContext::default();
|
||||
if let Some(project) = &maybe_project {
|
||||
// If the project file defines no plugins, then there's no need to
|
||||
// initialize the snapshot plugin context.
|
||||
if !project.plugins.is_empty() {
|
||||
snapshot_context.plugin_context =
|
||||
Some(Arc::new(SnapshotPluginContext::new(&project.plugins)));
|
||||
// TODO: Initialize plugins in instance context
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +53,7 @@ pub fn start<F: VfsFetcher>(
|
||||
.expect("could not get project path");
|
||||
|
||||
log::trace!("Generating snapshot of instances from VFS");
|
||||
let snapshot = snapshot_from_vfs(&mut snapshot_context, vfs, &entry)
|
||||
let snapshot = snapshot_from_vfs(&snapshot_context, vfs, &entry)
|
||||
.expect("snapshot failed")
|
||||
.expect("snapshot did not return an instance");
|
||||
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
use std::{fmt, fs, ops::Deref, path::Path, sync::Arc};
|
||||
|
||||
use rlua::{Lua, RegistryKey};
|
||||
|
||||
use super::error::SnapshotError;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InstanceSnapshotContext {
|
||||
/// Holds all the state needed to run user plugins as part of the snapshot
|
||||
/// process.
|
||||
///
|
||||
/// If this is None, then plugins should not be evaluated at all.
|
||||
pub plugin_context: Option<Arc<SnapshotPluginContext>>,
|
||||
}
|
||||
|
||||
impl Default for InstanceSnapshotContext {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
plugin_context: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SnapshotPluginContext {
|
||||
pub state: IgnoreDebug<Lua>,
|
||||
|
||||
/// Registry keys pointing to the values returned by each user plugin. When
|
||||
/// processing user plugins, these should be applied in order.
|
||||
pub plugin_functions: Vec<RegistryKey>,
|
||||
}
|
||||
|
||||
impl SnapshotPluginContext {
|
||||
pub fn new<P: AsRef<Path>>(plugin_paths: &[P]) -> Self {
|
||||
let lua_state = Lua::new();
|
||||
|
||||
let plugin_functions = plugin_paths
|
||||
.iter()
|
||||
.map(|path| {
|
||||
let path = path.as_ref();
|
||||
|
||||
let content =
|
||||
fs::read_to_string(path).map_err(|err| SnapshotError::wrap(err, path))?;
|
||||
|
||||
lua_state.context(|lua_context| {
|
||||
// Plugins are currently expected to return a function that will
|
||||
// be run when a snapshot needs to be generated.
|
||||
let result = lua_context
|
||||
.load(&content)
|
||||
.set_name(&path.display().to_string())?
|
||||
.call::<_, rlua::Function>(())?;
|
||||
|
||||
let key = lua_context.create_registry_value(result)?;
|
||||
|
||||
Ok(key)
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>, SnapshotError>>()
|
||||
.expect("Plugin initialization error");
|
||||
|
||||
Self {
|
||||
state: IgnoreDebug(lua_state),
|
||||
plugin_functions,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Utility type to enable having a field of a struct not implement Debug and
|
||||
/// instead show a placeholder.
|
||||
#[derive(Clone)]
|
||||
pub struct IgnoreDebug<T>(pub T);
|
||||
|
||||
impl<T> fmt::Debug for IgnoreDebug<T> {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "<no debug representation>")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for IgnoreDebug<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &T {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct VfsSnapshotContext;
|
||||
@@ -5,12 +5,11 @@ use rbx_dom_weak::RbxValue;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
snapshot::{InstanceMetadata, InstanceSnapshot},
|
||||
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
|
||||
vfs::{FsResultExt, Vfs, VfsEntry, VfsFetcher},
|
||||
};
|
||||
|
||||
use super::{
|
||||
context::InstanceSnapshotContext,
|
||||
meta_file::AdjacentMetadata,
|
||||
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
|
||||
util::match_file_name,
|
||||
@@ -20,7 +19,7 @@ pub struct SnapshotCsv;
|
||||
|
||||
impl SnapshotMiddleware for SnapshotCsv {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
_context: &mut InstanceSnapshotContext,
|
||||
_context: &InstanceContext,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult {
|
||||
@@ -159,7 +158,7 @@ Ack,Ack!,,An exclamation of despair,¡Ay!"#,
|
||||
|
||||
let entry = vfs.get("/foo.csv").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotCsv::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotCsv::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@@ -181,7 +180,7 @@ Ack,Ack!,,An exclamation of despair,¡Ay!"#,
|
||||
|
||||
let entry = vfs.get("/foo.csv").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotCsv::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotCsv::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -3,12 +3,11 @@ use std::collections::HashMap;
|
||||
use rbx_dom_weak::{RbxId, RbxTree};
|
||||
|
||||
use crate::{
|
||||
snapshot::{InstanceMetadata, InstanceSnapshot},
|
||||
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
|
||||
vfs::{DirectorySnapshot, FsResultExt, Vfs, VfsEntry, VfsFetcher, VfsSnapshot},
|
||||
};
|
||||
|
||||
use super::{
|
||||
context::InstanceSnapshotContext,
|
||||
error::SnapshotError,
|
||||
meta_file::DirectoryMetadata,
|
||||
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
|
||||
@@ -19,7 +18,7 @@ pub struct SnapshotDir;
|
||||
|
||||
impl SnapshotMiddleware for SnapshotDir {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult {
|
||||
@@ -116,7 +115,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotDir::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotDir::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@@ -134,7 +133,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotDir::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotDir::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -5,12 +5,11 @@ use rbx_reflection::try_resolve_value;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
snapshot::InstanceSnapshot,
|
||||
snapshot::{InstanceContext, InstanceSnapshot},
|
||||
vfs::{Vfs, VfsEntry, VfsFetcher},
|
||||
};
|
||||
|
||||
use super::{
|
||||
context::InstanceSnapshotContext,
|
||||
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
|
||||
util::match_file_name,
|
||||
};
|
||||
@@ -19,7 +18,7 @@ pub struct SnapshotJsonModel;
|
||||
|
||||
impl SnapshotMiddleware for SnapshotJsonModel {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
_context: &mut InstanceSnapshotContext,
|
||||
_context: &InstanceContext,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult {
|
||||
@@ -164,7 +163,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo.model.json").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotJsonModel::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotJsonModel::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -4,12 +4,11 @@ use maplit::hashmap;
|
||||
use rbx_dom_weak::RbxValue;
|
||||
|
||||
use crate::{
|
||||
snapshot::{InstanceMetadata, InstanceSnapshot},
|
||||
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
|
||||
vfs::{FsResultExt, Vfs, VfsEntry, VfsFetcher},
|
||||
};
|
||||
|
||||
use super::{
|
||||
context::InstanceSnapshotContext,
|
||||
dir::SnapshotDir,
|
||||
meta_file::AdjacentMetadata,
|
||||
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
|
||||
@@ -20,7 +19,7 @@ pub struct SnapshotLua;
|
||||
|
||||
impl SnapshotMiddleware for SnapshotLua {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult {
|
||||
@@ -108,7 +107,7 @@ fn snapshot_lua_file<F: VfsFetcher>(vfs: &Vfs<F>, entry: &VfsEntry) -> SnapshotI
|
||||
/// Scripts named `init.lua`, `init.server.lua`, or `init.client.lua` usurp
|
||||
/// their parents, which acts similarly to `__init__.py` from the Python world.
|
||||
fn snapshot_init<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs<F>,
|
||||
folder_entry: &VfsEntry,
|
||||
init_name: &str,
|
||||
@@ -155,7 +154,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo.lua").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotLua::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotLua::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@@ -171,7 +170,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo.server.lua").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotLua::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotLua::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@@ -187,7 +186,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo.client.lua").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotLua::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotLua::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@@ -205,7 +204,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/root").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotLua::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotLua::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@@ -229,7 +228,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo.lua").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotLua::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotLua::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@@ -253,7 +252,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo.server.lua").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotLua::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotLua::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@@ -279,7 +278,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/bar.server.lua").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotLua::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotLua::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
use rbx_dom_weak::{RbxId, RbxTree};
|
||||
|
||||
use crate::{
|
||||
snapshot::InstanceSnapshot,
|
||||
snapshot::{InstanceContext, InstanceSnapshot},
|
||||
vfs::{Vfs, VfsEntry, VfsFetcher, VfsSnapshot},
|
||||
};
|
||||
|
||||
use super::{context::InstanceSnapshotContext, error::SnapshotError};
|
||||
use super::error::SnapshotError;
|
||||
|
||||
pub type SnapshotInstanceResult = Result<Option<InstanceSnapshot>, SnapshotError>;
|
||||
pub type SnapshotFileResult = Option<(String, VfsSnapshot)>;
|
||||
|
||||
pub trait SnapshotMiddleware {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
mod context;
|
||||
mod csv;
|
||||
mod dir;
|
||||
mod error;
|
||||
@@ -19,7 +18,6 @@ mod txt;
|
||||
mod user_plugins;
|
||||
mod util;
|
||||
|
||||
pub use self::context::*;
|
||||
pub use self::error::*;
|
||||
|
||||
use rbx_dom_weak::{RbxId, RbxTree};
|
||||
@@ -37,7 +35,10 @@ use self::{
|
||||
txt::SnapshotTxt,
|
||||
user_plugins::SnapshotUserPlugins,
|
||||
};
|
||||
use crate::vfs::{Vfs, VfsEntry, VfsFetcher};
|
||||
use crate::{
|
||||
snapshot::InstanceContext,
|
||||
vfs::{Vfs, VfsEntry, VfsFetcher},
|
||||
};
|
||||
|
||||
pub use self::project::snapshot_project_node;
|
||||
|
||||
@@ -45,7 +46,7 @@ macro_rules! middlewares {
|
||||
( $($middleware: ident,)* ) => {
|
||||
/// Generates a snapshot of instances from the given VfsEntry.
|
||||
pub fn snapshot_from_vfs<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult {
|
||||
|
||||
@@ -4,12 +4,11 @@ use rbx_reflection::try_resolve_value;
|
||||
|
||||
use crate::{
|
||||
project::{Project, ProjectNode},
|
||||
snapshot::{InstanceMetadata, InstanceSnapshot, InstigatingSource},
|
||||
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot, InstigatingSource},
|
||||
vfs::{FsResultExt, Vfs, VfsEntry, VfsFetcher},
|
||||
};
|
||||
|
||||
use super::{
|
||||
context::InstanceSnapshotContext,
|
||||
error::SnapshotError,
|
||||
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
|
||||
snapshot_from_vfs,
|
||||
@@ -22,7 +21,7 @@ pub struct SnapshotProject;
|
||||
|
||||
impl SnapshotMiddleware for SnapshotProject {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult {
|
||||
@@ -77,7 +76,7 @@ impl SnapshotMiddleware for SnapshotProject {
|
||||
}
|
||||
|
||||
pub fn snapshot_project_node<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
context: &InstanceContext,
|
||||
instance_name: &str,
|
||||
node: &ProjectNode,
|
||||
vfs: &Vfs<F>,
|
||||
@@ -214,7 +213,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotProject::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotProject::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.expect("snapshot error")
|
||||
.expect("snapshot returned no instances");
|
||||
|
||||
@@ -241,7 +240,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo/hello.project.json").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotProject::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotProject::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.expect("snapshot error")
|
||||
.expect("snapshot returned no instances");
|
||||
|
||||
@@ -274,7 +273,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotProject::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotProject::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.expect("snapshot error")
|
||||
.expect("snapshot returned no instances");
|
||||
|
||||
@@ -304,7 +303,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotProject::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotProject::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.expect("snapshot error")
|
||||
.expect("snapshot returned no instances");
|
||||
|
||||
@@ -335,7 +334,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotProject::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotProject::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.expect("snapshot error")
|
||||
.expect("snapshot returned no instances");
|
||||
|
||||
@@ -363,7 +362,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotProject::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotProject::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.expect("snapshot error")
|
||||
.expect("snapshot returned no instances");
|
||||
|
||||
@@ -398,7 +397,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotProject::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotProject::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.expect("snapshot error")
|
||||
.expect("snapshot returned no instances");
|
||||
|
||||
@@ -437,7 +436,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotProject::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotProject::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.expect("snapshot error")
|
||||
.expect("snapshot returned no instances");
|
||||
|
||||
@@ -481,7 +480,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotProject::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotProject::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.expect("snapshot error")
|
||||
.expect("snapshot returned no instances");
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use crate::{
|
||||
snapshot::{InstanceMetadata, InstanceSnapshot},
|
||||
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
|
||||
vfs::{Vfs, VfsEntry, VfsFetcher},
|
||||
};
|
||||
|
||||
use super::{
|
||||
context::InstanceSnapshotContext,
|
||||
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
|
||||
util::match_file_name,
|
||||
};
|
||||
@@ -13,7 +12,7 @@ pub struct SnapshotRbxlx;
|
||||
|
||||
impl SnapshotMiddleware for SnapshotRbxlx {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
_context: &mut InstanceSnapshotContext,
|
||||
_context: &InstanceContext,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult {
|
||||
|
||||
@@ -3,12 +3,11 @@ use std::collections::HashMap;
|
||||
use rbx_dom_weak::{RbxInstanceProperties, RbxTree};
|
||||
|
||||
use crate::{
|
||||
snapshot::{InstanceMetadata, InstanceSnapshot},
|
||||
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
|
||||
vfs::{Vfs, VfsEntry, VfsFetcher},
|
||||
};
|
||||
|
||||
use super::{
|
||||
context::InstanceSnapshotContext,
|
||||
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
|
||||
util::match_file_name,
|
||||
};
|
||||
@@ -17,7 +16,7 @@ pub struct SnapshotRbxm;
|
||||
|
||||
impl SnapshotMiddleware for SnapshotRbxm {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
_context: &mut InstanceSnapshotContext,
|
||||
_context: &InstanceContext,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult {
|
||||
@@ -74,7 +73,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo.rbxm").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotRbxm::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotRbxm::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use crate::{
|
||||
snapshot::{InstanceMetadata, InstanceSnapshot},
|
||||
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
|
||||
vfs::{Vfs, VfsEntry, VfsFetcher},
|
||||
};
|
||||
|
||||
use super::{
|
||||
context::InstanceSnapshotContext,
|
||||
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
|
||||
util::match_file_name,
|
||||
};
|
||||
@@ -13,7 +12,7 @@ pub struct SnapshotRbxmx;
|
||||
|
||||
impl SnapshotMiddleware for SnapshotRbxmx {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
_context: &mut InstanceSnapshotContext,
|
||||
_context: &InstanceContext,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult {
|
||||
@@ -78,7 +77,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo.rbxmx").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotRbxmx::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotRbxmx::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -4,12 +4,11 @@ use maplit::hashmap;
|
||||
use rbx_dom_weak::{RbxId, RbxTree, RbxValue};
|
||||
|
||||
use crate::{
|
||||
snapshot::{InstanceMetadata, InstanceSnapshot},
|
||||
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
|
||||
vfs::{FileSnapshot, FsResultExt, Vfs, VfsEntry, VfsFetcher, VfsSnapshot},
|
||||
};
|
||||
|
||||
use super::{
|
||||
context::InstanceSnapshotContext,
|
||||
error::SnapshotError,
|
||||
meta_file::AdjacentMetadata,
|
||||
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
|
||||
@@ -20,7 +19,7 @@ pub struct SnapshotTxt;
|
||||
|
||||
impl SnapshotMiddleware for SnapshotTxt {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
_context: &mut InstanceSnapshotContext,
|
||||
_context: &InstanceContext,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult {
|
||||
@@ -114,7 +113,7 @@ mod test {
|
||||
|
||||
let entry = vfs.get("/foo.txt").unwrap();
|
||||
let instance_snapshot =
|
||||
SnapshotTxt::from_vfs(&mut InstanceSnapshotContext::default(), &mut vfs, &entry)
|
||||
SnapshotTxt::from_vfs(&InstanceContext::default(), &mut vfs, &entry)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::vfs::{Vfs, VfsEntry, VfsFetcher};
|
||||
|
||||
use super::{
|
||||
context::InstanceSnapshotContext,
|
||||
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
|
||||
use crate::{
|
||||
snapshot::InstanceContext,
|
||||
vfs::{Vfs, VfsEntry, VfsFetcher},
|
||||
};
|
||||
|
||||
use super::middleware::{SnapshotInstanceResult, SnapshotMiddleware};
|
||||
|
||||
/// Handles snapshotting of any file that a user plugin wants to handle.
|
||||
///
|
||||
/// User plugins are specified in the project file, but there are never user
|
||||
@@ -15,53 +15,41 @@ pub struct SnapshotUserPlugins;
|
||||
|
||||
impl SnapshotMiddleware for SnapshotUserPlugins {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
_context: &InstanceContext,
|
||||
_vfs: &Vfs<F>,
|
||||
_entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult {
|
||||
// User plugins are only enabled if present on the snapshot context.
|
||||
let plugin_context = match &mut context.plugin_context {
|
||||
Some(ctx) => ctx,
|
||||
None => return Ok(None),
|
||||
};
|
||||
// TODO: Invoke plugin here and get result out.
|
||||
|
||||
plugin_context.state.context(|lua_context| {
|
||||
lua_context.scope(|_scope| {
|
||||
for _key in &plugin_context.plugin_functions {
|
||||
// TODO: Invoke plugin here and get result out.
|
||||
|
||||
// The current plan for plugins here is to make them work
|
||||
// like Redux/Rodux middleware. A plugin will be a function
|
||||
// that accepts the next middleware in the chain as a
|
||||
// function and the snapshot subject (the VFS entry).
|
||||
//
|
||||
// Plugins can (but don't have to) invoke the next snapshot
|
||||
// function and may or may not mutate the result. The hope
|
||||
// is that this model enables the most flexibility possible
|
||||
// for plugins to modify existing Rojo output, as well as
|
||||
// generate new outputs.
|
||||
//
|
||||
// Open questions:
|
||||
// * How will middleware be ordered? Does putting user
|
||||
// middleware always at the beginning or always at the end
|
||||
// of the chain reduce the scope of what that middleware
|
||||
// can do?
|
||||
//
|
||||
// * Will plugins hurt Rojo's ability to parallelize
|
||||
// snapshotting in the future?
|
||||
//
|
||||
// * Do the mutable handles to the Vfs and the snapshot
|
||||
// context prevent plugins from invoking other plugins
|
||||
// indirectly?
|
||||
//
|
||||
// * Will there be problems using a single Lua state because
|
||||
// of re-entrancy?
|
||||
//
|
||||
// * Can the Lua <-> Rojo bindings used for middleware be
|
||||
// reused for or from another project like Remodel?
|
||||
}
|
||||
})
|
||||
});
|
||||
// The current plan for plugins here is to make them work
|
||||
// like Redux/Rodux middleware. A plugin will be a function
|
||||
// that accepts the next middleware in the chain as a
|
||||
// function and the snapshot subject (the VFS entry).
|
||||
//
|
||||
// Plugins can (but don't have to) invoke the next snapshot
|
||||
// function and may or may not mutate the result. The hope
|
||||
// is that this model enables the most flexibility possible
|
||||
// for plugins to modify existing Rojo output, as well as
|
||||
// generate new outputs.
|
||||
//
|
||||
// Open questions:
|
||||
// * How will middleware be ordered? Does putting user
|
||||
// middleware always at the beginning or always at the end
|
||||
// of the chain reduce the scope of what that middleware
|
||||
// can do?
|
||||
//
|
||||
// * Will plugins hurt Rojo's ability to parallelize
|
||||
// snapshotting in the future?
|
||||
//
|
||||
// * Do the mutable handles to the Vfs and the snapshot
|
||||
// context prevent plugins from invoking other plugins
|
||||
// indirectly?
|
||||
//
|
||||
// * Will there be problems using a single Lua state because
|
||||
// of re-entrancy?
|
||||
//
|
||||
// * Can the Lua <-> Rojo bindings used for middleware be
|
||||
// reused for or from another project like Remodel?
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user