diff --git a/src/serve_session.rs b/src/serve_session.rs index 6f51f0a6f..85ae77934 100644 --- a/src/serve_session.rs +++ b/src/serve_session.rs @@ -123,7 +123,8 @@ impl ServeSession { let root_id = tree.get_root_id(); - let instance_context = InstanceContext::from(root_project.emit_legacy_scripts); + let instance_context = + InstanceContext::with_emit_legacy_scripts(root_project.emit_legacy_scripts); log::trace!("Generating snapshot of instances from VFS"); let snapshot = snapshot_from_vfs(&instance_context, &vfs, start_path)?; diff --git a/src/snapshot/metadata.rs b/src/snapshot/metadata.rs index 295735ef6..54675c087 100644 --- a/src/snapshot/metadata.rs +++ b/src/snapshot/metadata.rs @@ -117,6 +117,14 @@ impl InstanceContext { } } + pub fn with_emit_legacy_scripts(emit_legacy_scripts: Option) -> Self { + Self { + emit_legacy_scripts: emit_legacy_scripts + .unwrap_or_else(|| emit_legacy_scripts_default().unwrap()), + ..Self::new() + } + } + /// Extend the list of ignore rules in the context with the given new rules. pub fn add_path_ignore_rules(&mut self, new_rules: I) where @@ -136,28 +144,7 @@ impl InstanceContext { } pub fn set_emit_legacy_scripts(&mut self, emit_legacy_scripts: bool) { - self.emit_legacy_scripts = emit_legacy_scripts - } -} - -// serve_session always passes an option from the config file, but tests want it to be explict -#[cfg(test)] -impl From for InstanceContext { - fn from(emit_legacy_scripts: bool) -> Self { - Self { - emit_legacy_scripts, - ..Self::new() - } - } -} - -impl From> for InstanceContext { - fn from(emit_legacy_scripts: Option) -> Self { - Self { - emit_legacy_scripts: emit_legacy_scripts - .unwrap_or_else(|| emit_legacy_scripts_default().unwrap()), - ..Self::new() - } + self.emit_legacy_scripts = emit_legacy_scripts; } } diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index c99b4837e..1307b0666 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -148,7 +148,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(true), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &mut vfs, Path::new("/foo.lua"), ) @@ -169,7 +169,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(false), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/foo.lua"), ) @@ -190,7 +190,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(true), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &mut vfs, Path::new("/foo.server.lua"), ) @@ -211,7 +211,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(false), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/foo.server.lua"), ) @@ -232,7 +232,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(true), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &mut vfs, Path::new("/foo.client.lua"), ) @@ -253,7 +253,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(false), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/foo.client.lua"), ) @@ -279,10 +279,13 @@ mod test { let mut vfs = Vfs::new(imfs); - let instance_snapshot = - snapshot_lua(&InstanceContext::from(true), &mut vfs, Path::new("/root")) - .unwrap() - .unwrap(); + let instance_snapshot = snapshot_lua( + &InstanceContext::with_emit_legacy_scripts(Some(true)), + &mut vfs, + Path::new("/root"), + ) + .unwrap() + .unwrap(); insta::with_settings!({ sort_maps => true }, { insta::assert_yaml_snapshot!(instance_snapshot); @@ -309,7 +312,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(true), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &mut vfs, Path::new("/foo.lua"), ) @@ -341,7 +344,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(false), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/foo.lua"), ) @@ -373,7 +376,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(true), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &mut vfs, Path::new("/foo.server.lua"), ) @@ -405,7 +408,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(false), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/foo.server.lua"), ) @@ -439,7 +442,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(true), + &InstanceContext::with_emit_legacy_scripts(Some(true)), &mut vfs, Path::new("/bar.server.lua"), ) @@ -473,7 +476,7 @@ mod test { let mut vfs = Vfs::new(imfs); let instance_snapshot = snapshot_lua( - &InstanceContext::from(false), + &InstanceContext::with_emit_legacy_scripts(Some(false)), &mut vfs, Path::new("/bar.server.lua"), )