Add handle_file_change to plugin API

This solves the problem I was running into with the ScriptPlugin implementation -- if foo/init.lua changes, foo needs to be requested, not 'foo/init.lua' (which would then erroneously create a ModuleScript before this commit)
This commit is contained in:
Lucien Greathouse
2017-12-17 22:46:56 -08:00
parent c75cbebbf0
commit 6472a2cbce
4 changed files with 51 additions and 16 deletions

View File

@@ -1,13 +1,20 @@
use rbx::RbxItem;
use vfs::VfsItem;
use core::Route;
pub enum PluginResult {
pub enum TransformResult {
Value(Option<RbxItem>),
Pass,
}
pub enum FileChangeResult {
MarkChanged(Option<Vec<Route>>),
Pass,
}
pub trait Plugin {
fn transform_file(&self, plugins: &PluginChain, vfs_item: &VfsItem) -> PluginResult;
fn transform_file(&self, plugins: &PluginChain, vfs_item: &VfsItem) -> TransformResult;
fn handle_file_change(&self, route: &Route) -> FileChangeResult;
}
pub struct PluginChain {
@@ -24,8 +31,8 @@ impl PluginChain {
pub fn transform_file(&self, vfs_item: &VfsItem) -> Option<RbxItem> {
for plugin in &self.plugins {
match plugin.transform_file(self, vfs_item) {
PluginResult::Value(rbx_item) => return rbx_item,
PluginResult::Pass => {},
TransformResult::Value(rbx_item) => return rbx_item,
TransformResult::Pass => {},
}
}