forked from rojo-rbx/rojo
Move instigating source out of contributing paths (#253)
* Refactor contributing_paths into contributing_sources, deleting project node sources * Instead of changing contributing_paths, add instigating_source * Remove InstanceMetadata::project_node * Stop pushing project path to front of contributing_paths since it doesn't matter now * Remove accidental UI change for path display
This commit is contained in:
committed by
GitHub
parent
2025b8a494
commit
052ca52cc3
@@ -1,4 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::{fmt, path::PathBuf};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -13,48 +13,64 @@ pub struct InstanceMetadata {
|
||||
/// manage.
|
||||
pub ignore_unknown_instances: bool,
|
||||
|
||||
/// If a change occurs to this instance, the instigating source is what
|
||||
/// should be run through the snapshot functions to regenerate it.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub instigating_source: Option<InstigatingSource>,
|
||||
|
||||
/// The paths that, when changed, could cause the function that generated
|
||||
/// this snapshot to generate a different snapshot. Paths should be included
|
||||
/// even if they don't exist, since the presence of a file can change the
|
||||
/// outcome of a snapshot function.
|
||||
///
|
||||
/// The first path in this list is considered the "instigating path", and
|
||||
/// will be the snapshot target if any of the contributing paths change.
|
||||
///
|
||||
/// For example, a file named foo.lua might have these contributing paths:
|
||||
/// - foo.lua (instigating path)
|
||||
/// - foo.lua
|
||||
/// - foo.meta.json (even if this file doesn't exist!)
|
||||
///
|
||||
/// A directory named bar/ included in the project file might have these:
|
||||
/// - bar/ (instigating path)
|
||||
/// A directory named bar/ might have these:
|
||||
/// - bar/
|
||||
/// - bar/init.meta.json
|
||||
/// - bar/init.lua
|
||||
/// - bar/init.server.lua
|
||||
/// - bar/init.client.lua
|
||||
/// - default.project.json
|
||||
/// - bar/default.project.json
|
||||
///
|
||||
/// This path is used to make sure that file changes update all instances
|
||||
/// that may need updates.
|
||||
// TODO: Change this to be a SmallVec for performance in common cases?
|
||||
#[serde(serialize_with = "path_serializer::serialize_vec_absolute")]
|
||||
pub contributing_paths: Vec<PathBuf>,
|
||||
|
||||
/// If this instance was defined in a project file, this is the name from
|
||||
/// the project file and the node under it.
|
||||
///
|
||||
/// This information is used to make sure the instance has the correct name,
|
||||
/// project-added children, and metadata when it's updated in response to a
|
||||
/// file change.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub project_node: Option<(String, ProjectNode)>,
|
||||
}
|
||||
|
||||
impl Default for InstanceMetadata {
|
||||
fn default() -> Self {
|
||||
InstanceMetadata {
|
||||
ignore_unknown_instances: false,
|
||||
instigating_source: None,
|
||||
contributing_paths: Vec::new(),
|
||||
project_node: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum InstigatingSource {
|
||||
Path(#[serde(serialize_with = "path_serializer::serialize_absolute")] PathBuf),
|
||||
ProjectNode(String, ProjectNode),
|
||||
}
|
||||
|
||||
impl fmt::Debug for InstigatingSource {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
InstigatingSource::Path(path) => write!(formatter, "Path({})", path.display()),
|
||||
InstigatingSource::ProjectNode(name, node) => {
|
||||
write!(formatter, "ProjectNode({}: {:?}", name, node)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PathBuf> for InstigatingSource {
|
||||
fn from(path: PathBuf) -> Self {
|
||||
InstigatingSource::Path(path)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ mod patch_compute;
|
||||
mod tree;
|
||||
|
||||
pub use instance_snapshot::InstanceSnapshot;
|
||||
pub use metadata::InstanceMetadata;
|
||||
pub use metadata::*;
|
||||
pub use patch::*;
|
||||
pub use patch_apply::apply_patch_set;
|
||||
pub use patch_compute::compute_patch_set;
|
||||
|
||||
Reference in New Issue
Block a user