mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-24 14:45:56 +00:00
Use plugin chain code in Vfs
This commit is contained in:
11
src/bin.rs
11
src/bin.rs
@@ -33,6 +33,8 @@ use std::thread;
|
|||||||
use core::Config;
|
use core::Config;
|
||||||
use pathext::canonicalish;
|
use pathext::canonicalish;
|
||||||
use project::{Project, ProjectLoadError};
|
use project::{Project, ProjectLoadError};
|
||||||
|
use plugin::{PluginChain};
|
||||||
|
use plugins::{DefaultPlugin, ScriptPlugin};
|
||||||
use vfs::Vfs;
|
use vfs::Vfs;
|
||||||
use vfs_watch::VfsWatcher;
|
use vfs_watch::VfsWatcher;
|
||||||
|
|
||||||
@@ -148,6 +150,13 @@ fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref PLUGIN_CHAIN: PluginChain = PluginChain::new(vec![
|
||||||
|
Box::new(ScriptPlugin::new()),
|
||||||
|
Box::new(DefaultPlugin::new()),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
let config = Config {
|
let config = Config {
|
||||||
port,
|
port,
|
||||||
verbose,
|
verbose,
|
||||||
@@ -159,7 +168,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let vfs = {
|
let vfs = {
|
||||||
let mut vfs = Vfs::new(config.clone());
|
let mut vfs = Vfs::new(config.clone(), &PLUGIN_CHAIN);
|
||||||
|
|
||||||
for (name, project_partition) in &project.partitions {
|
for (name, project_partition) in &project.partitions {
|
||||||
let path = {
|
let path = {
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ pub trait Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct PluginChain {
|
pub struct PluginChain {
|
||||||
plugins: Vec<Box<Plugin + Send>>,
|
plugins: Vec<Box<Plugin + Send + Sync>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PluginChain {
|
impl PluginChain {
|
||||||
pub fn new(plugins: Vec<Box<Plugin + Send>>) -> PluginChain {
|
pub fn new(plugins: Vec<Box<Plugin + Send + Sync>>) -> PluginChain {
|
||||||
PluginChain {
|
PluginChain {
|
||||||
plugins,
|
plugins,
|
||||||
}
|
}
|
||||||
@@ -38,4 +38,15 @@ impl PluginChain {
|
|||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_file_change(&self, route: &Route) -> Option<Vec<Route>> {
|
||||||
|
for plugin in &self.plugins {
|
||||||
|
match plugin.handle_file_change(route) {
|
||||||
|
FileChangeResult::MarkChanged(changes) => return changes,
|
||||||
|
FileChangeResult::Pass => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/vfs.rs
23
src/vfs.rs
@@ -6,6 +6,7 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use core::Config;
|
use core::Config;
|
||||||
|
use plugin::PluginChain;
|
||||||
|
|
||||||
/// Represents a virtual layer over multiple parts of the filesystem.
|
/// Represents a virtual layer over multiple parts of the filesystem.
|
||||||
///
|
///
|
||||||
@@ -24,6 +25,8 @@ pub struct Vfs {
|
|||||||
/// created, along with a timestamp denoting when.
|
/// created, along with a timestamp denoting when.
|
||||||
pub change_history: Vec<VfsChange>,
|
pub change_history: Vec<VfsChange>,
|
||||||
|
|
||||||
|
plugin_chain: &'static PluginChain,
|
||||||
|
|
||||||
config: Config,
|
config: Config,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,11 +54,12 @@ impl VfsItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Vfs {
|
impl Vfs {
|
||||||
pub fn new(config: Config) -> Vfs {
|
pub fn new(config: Config, plugin_chain: &'static PluginChain) -> Vfs {
|
||||||
Vfs {
|
Vfs {
|
||||||
partitions: HashMap::new(),
|
partitions: HashMap::new(),
|
||||||
start_time: Instant::now(),
|
start_time: Instant::now(),
|
||||||
change_history: Vec::new(),
|
change_history: Vec::new(),
|
||||||
|
plugin_chain,
|
||||||
config,
|
config,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,13 +168,20 @@ impl Vfs {
|
|||||||
|
|
||||||
pub fn add_change(&mut self, timestamp: f64, route: Vec<String>) {
|
pub fn add_change(&mut self, timestamp: f64, route: Vec<String>) {
|
||||||
if self.config.verbose {
|
if self.config.verbose {
|
||||||
println!("Added change {:?}", route);
|
println!("Received change {:?}, running through plugins...", route);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.change_history.push(VfsChange {
|
match self.plugin_chain.handle_file_change(&route) {
|
||||||
timestamp,
|
Some(routes) => {
|
||||||
route,
|
for route in routes {
|
||||||
});
|
self.change_history.push(VfsChange {
|
||||||
|
timestamp,
|
||||||
|
route,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn changes_since(&self, timestamp: f64) -> &[VfsChange] {
|
pub fn changes_since(&self, timestamp: f64) -> &[VfsChange] {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
use rouille;
|
use rouille;
|
||||||
use serde;
|
use serde;
|
||||||
|
|||||||
Reference in New Issue
Block a user