User plugin foundations for 0.6.0 (#257)

Starts work on #55.

This is similar to the previous work in #125. It's gated behind a new Cargo
feature, `user-plugins`. This time, the config gate is much smaller. The
`plugins` member of projects is still accessible when plugins aren't enabled,
but is always empty. Additionally, user plugins are only enabled if there's a
Lua state present in the snapshot context when the `SnapshotUserPlugins`
snapshot middleware runs. This not ever the case currently.

This code has very little possibility of rotting while we focus on other work,
since it'll be guaranteed to still compile and can be tested in isolation
without the feature being turned on.
This commit is contained in:
Lucien Greathouse
2019-10-11 15:45:02 -07:00
committed by GitHub
parent f3dc78b7cd
commit b093626a21
17 changed files with 306 additions and 22 deletions

View File

@@ -48,7 +48,8 @@ impl SnapshotMiddleware for SnapshotProject {
// Snapshotting a project should always return an instance, so this
// unwrap is safe.
let mut snapshot = snapshot_project_node(&project.name, &project.tree, imfs)?.unwrap();
let mut snapshot =
snapshot_project_node(context, &project.name, &project.tree, imfs)?.unwrap();
// Setting the instigating source to the project file path is a little
// coarse.
@@ -76,6 +77,7 @@ impl SnapshotMiddleware for SnapshotProject {
}
fn snapshot_project_node<F: ImfsFetcher>(
context: &mut InstanceSnapshotContext,
instance_name: &str,
node: &ProjectNode,
imfs: &mut Imfs<F>,
@@ -92,7 +94,7 @@ fn snapshot_project_node<F: ImfsFetcher>(
if let Some(path) = &node.path {
let entry = imfs.get(path)?;
if let Some(snapshot) = snapshot_from_imfs(imfs, &entry)? {
if let Some(snapshot) = snapshot_from_imfs(context, imfs, &entry)? {
// If a class name was already specified, then it'll override the
// class name of this snapshot ONLY if it's a Folder.
//
@@ -142,7 +144,7 @@ fn snapshot_project_node<F: ImfsFetcher>(
.expect("$className or $path must be specified");
for (child_name, child_project_node) in &node.children {
if let Some(child) = snapshot_project_node(child_name, child_project_node, imfs)? {
if let Some(child) = snapshot_project_node(context, child_name, child_project_node, imfs)? {
children.push(child);
}
}