diff --git a/Cargo.lock b/Cargo.lock index 850e072..6bab392 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -532,38 +532,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" -[[package]] -name = "copilot-impl" -version = "0.0.0" -dependencies = [ - "async-trait", - "bazed-stew-interface", - "color-eyre", - "copilot-interface", - "interprocess", - "serde_json", - "tokio", - "tracing", - "tracing-error", - "tracing-subscriber", -] - -[[package]] -name = "copilot-interface" -version = "0.0.0" -dependencies = [ - "async-trait", - "bazed-stew-interface", - "bazed-stew-macros", - "interprocess", - "serde", - "serde_json", - "tokio", - "tracing", - "tracing-error", - "tracing-subscriber", -] - [[package]] name = "core-foundation" version = "0.9.3" @@ -858,6 +826,38 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +[[package]] +name = "example-plugin-impl" +version = "0.0.0" +dependencies = [ + "async-trait", + "bazed-stew-interface", + "color-eyre", + "example-plugin-interface", + "interprocess", + "serde_json", + "tokio", + "tracing", + "tracing-error", + "tracing-subscriber", +] + +[[package]] +name = "example-plugin-interface" +version = "0.0.0" +dependencies = [ + "async-trait", + "bazed-stew-interface", + "bazed-stew-macros", + "interprocess", + "serde", + "serde_json", + "tokio", + "tracing", + "tracing-error", + "tracing-subscriber", +] + [[package]] name = "eyre" version = "0.6.8" diff --git a/Cargo.toml b/Cargo.toml index c82974b..5d63469 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,7 @@ bazed-input-mapper = { path = "crates/bazed-input-mapper", version = "0.0.0" } bazed-stew-macros = { path = "crates/bazed-stew-macros", version = "0.0.0" } bazed-stew-interface = { path = "crates/bazed-stew-interface", version = "0.0.0" } bazed-stew = { path = "crates/bazed-stew", version = "0.0.0" } -copilot-interface = { path = "crates/copilot-interface", version = "0.0.0" } +example-plugin-interface = { path = "crates/example-plugin-interface", version = "0.0.0" } [workspace.dependencies.tracing-subscriber] version = "0.3.16" diff --git a/crates/bazed-stew/src/executable.rs b/crates/bazed-stew/src/executable.rs index 30d6b1c..0a3f4c2 100644 --- a/crates/bazed-stew/src/executable.rs +++ b/crates/bazed-stew/src/executable.rs @@ -23,7 +23,7 @@ impl PluginExecutable { return None; } let file_name = path.file_name()?.to_string_lossy(); - let version = file_name.split('=').nth(1)?.to_string(); + let version = file_name.split('@').nth(1)?.to_string(); Version::parse(&version).is_ok().then_some(Self(path)) } @@ -33,12 +33,12 @@ impl PluginExecutable { pub fn name(&self) -> String { let file_name = self.0.file_name().unwrap().to_string_lossy(); - file_name.split('=').next().unwrap().to_string() + file_name.split('@').next().unwrap().to_string() } pub fn version(&self) -> Version { let file_name = self.0.file_name().unwrap().to_string_lossy(); - let version = file_name.split('=').nth(1).unwrap().to_string(); + let version = file_name.split('@').nth(1).unwrap().to_string(); Version::parse(&version).unwrap() } diff --git a/crates/bazed-stew/src/lib.rs b/crates/bazed-stew/src/lib.rs index 28ae657..e08294b 100644 --- a/crates/bazed-stew/src/lib.rs +++ b/crates/bazed-stew/src/lib.rs @@ -28,11 +28,11 @@ pub async fn run_stew(load_path: Vec) { plugins: Arc::new(DashMap::new()), rpc_call_send, }; - let copilot = search_plugin(&load_path, "copilot", &"*".parse().unwrap()); - if let Some(copilot) = copilot { - stew.start_plugin(&copilot).await; + let example_plugin = search_plugin(&load_path, "example-plugin", &"*".parse().unwrap()); + if let Some(example_plugin) = example_plugin { + stew.start_plugin(&example_plugin).await; } else { - tracing::error!("Failed to find copilot plugin"); + tracing::error!("Failed to find example plugin"); } tracing::info!("Starting to listen to rpc calls"); diff --git a/crates/copilot-interface/.gitignore b/crates/copilot-interface/.gitignore deleted file mode 100644 index 4fffb2f..0000000 --- a/crates/copilot-interface/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target -/Cargo.lock diff --git a/crates/copilot-interface/src/lib.rs b/crates/copilot-interface/src/lib.rs deleted file mode 100644 index 10cedcb..0000000 --- a/crates/copilot-interface/src/lib.rs +++ /dev/null @@ -1,10 +0,0 @@ -#[bazed_stew_macros::plugin(name = "copilot", version = "0.1.0", stew_version = "0.1")] -#[async_trait::async_trait] -pub trait Copilot { - /// Add a value to the counter. - async fn plus(&mut self, n: usize); - /// Subtract a value from the counter. Fails if the counter would be < 0. - async fn minus(&mut self, n: usize) -> Result<(), String>; - /// Get the current value. - async fn value(&mut self) -> usize; -} diff --git a/crates/copilot-impl/Cargo.toml b/crates/example-plugin-impl/Cargo.toml similarity index 78% rename from crates/copilot-impl/Cargo.toml rename to crates/example-plugin-impl/Cargo.toml index fa1ed9b..0bcf254 100644 --- a/crates/copilot-impl/Cargo.toml +++ b/crates/example-plugin-impl/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "copilot-impl" +name = "example-plugin-impl" version = "0.0.0" edition = "2021" -description = "The bazed editor's github copilot plugin" +description = "A basic example of a plugin implementation" authors.workspace = true categories.workspace = true keywords.workspace = true @@ -21,5 +21,5 @@ tokio.workspace = true tracing-subscriber.workspace = true tracing-error.workspace = true -copilot-interface.workspace = true +example-plugin-interface.workspace = true color-eyre.workspace = true diff --git a/crates/copilot-impl/src/main.rs b/crates/example-plugin-impl/src/main.rs similarity index 65% rename from crates/copilot-impl/src/main.rs rename to crates/example-plugin-impl/src/main.rs index 14873ae..f916ae5 100644 --- a/crates/copilot-impl/src/main.rs +++ b/crates/example-plugin-impl/src/main.rs @@ -1,20 +1,18 @@ -use copilot_interface::CopilotClient; +use example_plugin_interface::ExamplePluginClient; use tracing_error::ErrorLayer; -use tracing_subscriber::{ - prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, -}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; struct Plugin { counter: usize, } #[async_trait::async_trait] -impl copilot_interface::Copilot for Plugin { - async fn plus(&mut self, n: usize) { +impl example_plugin_interface::ExamplePlugin for Plugin { + async fn increase(&mut self, n: usize) { self.counter += n; } - async fn minus(&mut self, n: usize) -> Result<(), String> { + async fn decrease(&mut self, n: usize) -> Result<(), String> { if self.counter < n { Err("Can't subtract more than the current value".to_string()) } else { @@ -22,6 +20,7 @@ impl copilot_interface::Copilot for Plugin { Ok(()) } } + async fn value(&mut self) -> usize { self.counter } @@ -30,22 +29,24 @@ impl copilot_interface::Copilot for Plugin { #[tokio::main] async fn main() -> color_eyre::Result<()> { init_logging(); - tracing::info!("Copilot started"); + tracing::info!("Example plugin started"); let plugin = Plugin { counter: 0 }; let mut stew_session = bazed_stew_interface::init_session_with_state(plugin); tracing::info!("Stew session running"); - copilot_interface::server::initialize(&mut stew_session).await?; + example_plugin_interface::server::initialize(&mut stew_session).await?; tracing::info!("Initialized"); - let mut other_plugin = CopilotClient::load(stew_session.clone()).await?; + let mut other_plugin = ExamplePluginClient::load(stew_session.clone()).await?; - other_plugin.plus(5).await?; - other_plugin.plus(5).await?; + other_plugin.increase(5).await?; + other_plugin.increase(5).await?; let result = other_plugin.value().await?; + assert_eq!(result, 10); tracing::info!("Result value: {result:?}"); - let result = other_plugin.minus(15).await?; + let result = other_plugin.decrease(15).await?; tracing::info!("Result minus: {result:?}"); + assert!(result.is_err()); loop { tokio::time::sleep(std::time::Duration::from_secs(1)).await; diff --git a/crates/copilot-interface/Cargo.toml b/crates/example-plugin-interface/Cargo.toml similarity index 84% rename from crates/copilot-interface/Cargo.toml rename to crates/example-plugin-interface/Cargo.toml index 9f982f2..3a560b7 100644 --- a/crates/copilot-interface/Cargo.toml +++ b/crates/example-plugin-interface/Cargo.toml @@ -1,7 +1,8 @@ [package] -name = "copilot-interface" +name = "example-plugin-interface" version = "0.0.0" edition = "2021" +description = "A basic example of a plugin implementation" authors.workspace = true categories.workspace = true keywords.workspace = true diff --git a/crates/example-plugin-interface/src/lib.rs b/crates/example-plugin-interface/src/lib.rs new file mode 100644 index 0000000..8498650 --- /dev/null +++ b/crates/example-plugin-interface/src/lib.rs @@ -0,0 +1,10 @@ +#[bazed_stew_macros::plugin(name = "example-plugin", version = "0.1.0", stew_version = "0.1")] +#[async_trait::async_trait] +pub trait ExamplePlugin { + /// Add a value to the counter. + async fn increase(&mut self, n: usize); + /// Subtract a value from the counter. Fails if the counter would be < 0. + async fn decrease(&mut self, n: usize) -> Result<(), String>; + /// Get the current value. + async fn value(&mut self) -> usize; +}