diff options
author | Aram Drevekenin <aram@poor.dev> | 2023-08-09 22:26:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-09 22:26:00 +0200 |
commit | 1bedfc90021558cb201695444107afe5bddd2c17 (patch) | |
tree | 38dd31b5ab112aa9b1c3a54edb07331013bf7d87 /default-plugins | |
parent | c3e140cb4b3c0897329bf07ee7f51e9fd402b3df (diff) |
feat(plugins): use protocol buffers for serializing across the wasm boundary (#2686)
* work
* almost done with command protobuffers
* done translating command data structures
* mid transferring of every command to protobuff command
* transferred plugin_command.rs, now moving on to shim.rs
* plugin command working with protobufs
* protobuffers in update
* protobuf event tests
* various TODOs and comments
* fix zellij-tile
* clean up prost deps
* remove version mismatch error
* fix panic
* some cleanups
* clean up event protobuffers
* clean up command protobuffers
* clean up various protobufs
* refactor protobufs
* update comments
* some transformation fixes
* use protobufs for workers
* style(fmt): rustfmt
* style(fmt): rustfmt
* chore(build): add protoc
* chore(build): authenticate protoc
Diffstat (limited to 'default-plugins')
-rw-r--r-- | default-plugins/fixture-plugin-for-tests/src/main.rs | 61 | ||||
-rw-r--r-- | default-plugins/strider/src/main.rs | 80 | ||||
-rw-r--r-- | default-plugins/strider/src/search/mod.rs | 28 | ||||
-rw-r--r-- | default-plugins/strider/src/search/search_state.rs | 46 | ||||
-rw-r--r-- | default-plugins/strider/src/state.rs | 5 |
5 files changed, 128 insertions, 92 deletions
diff --git a/default-plugins/fixture-plugin-for-tests/src/main.rs b/default-plugins/fixture-plugin-for-tests/src/main.rs index 074aa1a4d..fe8b034b9 100644 --- a/default-plugins/fixture-plugin-for-tests/src/main.rs +++ b/default-plugins/fixture-plugin-for-tests/src/main.rs @@ -22,13 +22,14 @@ impl<'de> ZellijWorker<'de> for TestWorker { fn on_message(&mut self, message: String, payload: String) { if message == "ping" { self.number_of_messages_received += 1; - post_message_to_plugin( - "pong".into(), - format!( + post_message_to_plugin(PluginMessage { + worker_name: None, + name: "pong".into(), + payload: format!( "{}, received {} messages", payload, self.number_of_messages_received ), - ); + }); } } } @@ -143,22 +144,30 @@ impl ZellijPlugin for State { start_or_reload_plugin(plugin_url) }, Key::Ctrl('g') => { - open_file(std::path::PathBuf::from("/path/to/my/file.rs").as_path()); + open_file(FileToOpen { + path: std::path::PathBuf::from("/path/to/my/file.rs"), + ..Default::default() + }); }, Key::Ctrl('h') => { - open_file_floating(std::path::PathBuf::from("/path/to/my/file.rs").as_path()); + open_file_floating(FileToOpen { + path: std::path::PathBuf::from("/path/to/my/file.rs"), + ..Default::default() + }); }, Key::Ctrl('i') => { - open_file_with_line( - std::path::PathBuf::from("/path/to/my/file.rs").as_path(), - 42, - ); + open_file(FileToOpen { + path: std::path::PathBuf::from("/path/to/my/file.rs"), + line_number: Some(42), + ..Default::default() + }); }, Key::Ctrl('j') => { - open_file_with_line_floating( - std::path::PathBuf::from("/path/to/my/file.rs").as_path(), - 42, - ); + open_file_floating(FileToOpen { + path: std::path::PathBuf::from("/path/to/my/file.rs"), + line_number: Some(42), + ..Default::default() + }); }, Key::Ctrl('k') => { open_terminal(std::path::PathBuf::from("/path/to/my/file.rs").as_path()); @@ -169,16 +178,18 @@ impl ZellijPlugin for State { ); }, Key::Ctrl('m') => { - open_command_pane( - std::path::PathBuf::from("/path/to/my/file.rs").as_path(), - vec!["arg1".to_owned(), "arg2".to_owned()], - ); + open_command_pane(CommandToRun { + path: std::path::PathBuf::from("/path/to/my/file.rs"), + args: vec!["arg1".to_owned(), "arg2".to_owned()], + ..Default::default() + }); }, Key::Ctrl('n') => { - open_command_pane_floating( - std::path::PathBuf::from("/path/to/my/file.rs").as_path(), - vec!["arg1".to_owned(), "arg2".to_owned()], - ); + open_command_pane_floating(CommandToRun { + path: std::path::PathBuf::from("/path/to/my/file.rs"), + args: vec!["arg1".to_owned(), "arg2".to_owned()], + ..Default::default() + }); }, Key::Ctrl('o') => { switch_tab_to(1); @@ -225,7 +236,11 @@ impl ZellijPlugin for State { }, Event::SystemClipboardFailure => { // this is just to trigger the worker message - post_message_to("test", "ping", "gimme_back_my_payload"); + post_message_to(PluginMessage { + worker_name: Some("test".into()), + name: "ping".into(), + payload: "gimme_back_my_payload".into(), + }); }, _ => {}, } diff --git a/default-plugins/strider/src/main.rs b/default-plugins/strider/src/main.rs index 35ff92ea7..e620930c0 100644 --- a/default-plugins/strider/src/main.rs +++ b/default-plugins/strider/src/main.rs @@ -31,16 +31,16 @@ impl ZellijPlugin for State { EventType::FileSystemUpdate, EventType::FileSystemDelete, ]); - post_message_to( - "file_name_search", - &serde_json::to_string(&MessageToSearch::ScanFolder).unwrap(), - "", - ); - post_message_to( - "file_contents_search", - &serde_json::to_string(&MessageToSearch::ScanFolder).unwrap(), - "", - ); + post_message_to(PluginMessage { + worker_name: Some("file_name_search".into()), + name: serde_json::to_string(&MessageToSearch::ScanFolder).unwrap(), + payload: "".into(), + }); + post_message_to(PluginMessage { + worker_name: Some("file_contents_search".into()), + name: serde_json::to_string(&MessageToSearch::ScanFolder).unwrap(), + payload: "".into(), + }); self.search_state.loading = true; set_timeout(0.5); // for displaying loading animation } @@ -191,48 +191,48 @@ impl ZellijPlugin for State { .iter() .map(|p| p.to_string_lossy().to_string()) .collect(); - post_message_to( - "file_name_search", - &serde_json::to_string(&MessageToSearch::FileSystemCreate).unwrap(), - &serde_json::to_string(&paths).unwrap(), - ); - post_message_to( - "file_contents_search", - &serde_json::to_string(&MessageToSearch::FileSystemCreate).unwrap(), - &serde_json::to_string(&paths).unwrap(), - ); + post_message_to(PluginMessage { + worker_name: Some("file_name_search".into()), + name: serde_json::to_string(&MessageToSearch::FileSystemCreate).unwrap(), + payload: serde_json::to_string(&paths).unwrap(), + }); + post_message_to(PluginMessage { + worker_name: Some("file_contents_search".into()), + name: serde_json::to_string(&MessageToSearch::FileSystemCreate).unwrap(), + payload: serde_json::to_string(&paths).unwrap(), + }); }, Event::FileSystemUpdate(paths) => { let paths: Vec<String> = paths .iter() .map(|p| p.to_string_lossy().to_string()) .collect(); - post_message_to( - "file_name_search", - &serde_json::to_string(&MessageToSearch::FileSystemUpdate).unwrap(), - &serde_json::to_string(&paths).unwrap(), - ); - post_message_to( - "file_contents_search", - &serde_json::to_string(&MessageToSearch::FileSystemUpdate).unwrap(), - &serde_json::to_string(&paths).unwrap(), - ); + post_message_to(PluginMessage { + worker_name: Some("file_name_search".into()), + name: serde_json::to_string(&MessageToSearch::FileSystemUpdate).unwrap(), + payload: serde_json::to_string(&paths).unwrap(), + }); + post_message_to(PluginMessage { + worker_name: Some("file_contents_search".into()), + name: serde_json::to_string(&MessageToSearch::FileSystemUpdate).unwrap(), + payload: serde_json::to_string(&paths).unwrap(), + }); }, Event::FileSystemDelete(paths) => { let paths: Vec<String> = paths .iter() .map(|p| p.to_string_lossy().to_string()) .collect(); - post_message_to( - "file_name_search", - &serde_json::to_string(&MessageToSearch::FileSystemDelete).unwrap(), - &serde_json::to_string(&paths).unwrap(), - ); - post_message_to( - "file_contents_search", - &serde_json::to_string(&MessageToSearch::FileSystemDelete).unwrap(), - &serde_json::to_string(&paths).unwrap(), - ); + post_message_to(PluginMessage { + worker_name: Some("file_name_search".into()), + name: serde_json::to_string(&MessageToSearch::FileSystemDelete).unwrap(), + payload: serde_json::to_string(&paths).unwrap(), + }); + post_message_to(PluginMessage { + worker_name: Some("file_contents_search".into()), + name: serde_json::to_string(&MessageToSearch::FileSystemDelete).unwrap(), + payload: serde_json::to_string(&paths).unwrap(), + }); }, _ => { dbg!("Unknown event {:?}", event); diff --git a/default-plugins/strider/src/search/mod.rs b/default-plugins/strider/src/search/mod.rs index 33c8a60b0..6ffa60cba 100644 --- a/default-plugins/strider/src/search/mod.rs +++ b/default-plugins/strider/src/search/mod.rs @@ -41,10 +41,11 @@ impl Search { match serde_json::from_str::<MessageToSearch>(&message) { Ok(MessageToSearch::ScanFolder) => { self.scan_hd(); - post_message_to_plugin( - serde_json::to_string(&MessageToPlugin::DoneScanningFolder).unwrap(), - "".to_owned(), - ); + post_message_to_plugin(PluginMessage { + worker_name: None, + name: serde_json::to_string(&MessageToPlugin::DoneScanningFolder).unwrap(), + payload: "".to_owned(), + }); }, Ok(MessageToSearch::Search) => { if let Some(current_search_term) = self.read_search_term_from_hd_cache() { @@ -115,16 +116,19 @@ impl Search { } } if let Some(file_names_search_results) = file_names_search_results { - post_message_to_plugin( - serde_json::to_string(&MessageToPlugin::UpdateFileNameSearchResults).unwrap(), - serde_json::to_string(&file_names_search_results).unwrap(), - ); + post_message_to_plugin(PluginMessage { + name: serde_json::to_string(&MessageToPlugin::UpdateFileNameSearchResults).unwrap(), + payload: serde_json::to_string(&file_names_search_results).unwrap(), + ..Default::default() + }); } if let Some(file_contents_search_results) = file_contents_search_results { - post_message_to_plugin( - serde_json::to_string(&MessageToPlugin::UpdateFileContentsSearchResults).unwrap(), - serde_json::to_string(&file_contents_search_results).unwrap(), - ); + post_message_to_plugin(PluginMessage { + name: serde_json::to_string(&MessageToPlugin::UpdateFileContentsSearchResults) + .unwrap(), + payload: serde_json::to_string(&file_contents_search_results).unwrap(), + ..Default::default() + }); } } pub fn rescan_files(&mut self, paths: String) { diff --git a/default-plugins/strider/src/search/search_state.rs b/default-plugins/strider/src/search/search_state.rs index 865a98e55..834a74fe6 100644 --- a/default-plugins/strider/src/search/search_state.rs +++ b/default-plugins/strider/src/search/search_state.rs @@ -3,8 +3,8 @@ use crate::search::{MessageToSearch, ResultsOfSearch}; use serde::{Deserialize, Serialize}; use std::path::PathBuf; use zellij_tile::prelude::{ - hide_self, open_file, open_file_floating, open_file_with_line, open_file_with_line_floating, - open_terminal, open_terminal_floating, post_message_to, Key, + hide_self, open_file, open_file_floating, open_terminal, open_terminal_floating, + post_message_to, FileToOpen, Key, PluginMessage, }; pub const CURRENT_SEARCH_TERM: &str = "/data/current_search_term"; @@ -88,18 +88,32 @@ impl SearchState { match self.selected_search_result_entry() { Some(SearchResult::File { path, .. }) => { if self.should_open_floating { - open_file_floating(&PathBuf::from(path)) + open_file_floating(FileToOpen { + path: PathBuf::from(path), + ..Default::default() + }); } else { - open_file(&PathBuf::from(path)); + open_file(FileToOpen { + path: PathBuf::from(path), + ..Default::default() + }); } }, Some(SearchResult::LineInFile { path, line_number, .. }) => { if self.should_open_floating { - open_file_with_line_floating(&PathBuf::from(path), line_number); + open_file_floating(FileToOpen { + path: PathBuf::from(path), + line_number: Some(line_number), + ..Default::default() + }); } else { - open_file_with_line(&PathBuf::from(path), line_number); + open_file(FileToOpen { + path: PathBuf::from(path), + line_number: Some(line_number), + ..Default::default() + }); } }, None => eprintln!("Search results not found"), @@ -153,16 +167,16 @@ impl SearchState { match std::fs::write(CURRENT_SEARCH_TERM, &self.search_term) { Ok(_) => { if !self.search_term.is_empty() { - post_message_to( - "file_name_search", - &serde_json::to_string(&MessageToSearch::Search).unwrap(), - "", - ); - post_message_to( - "file_contents_search", - &serde_json::to_string(&MessageToSearch::Search).unwrap(), - "", - ); + post_message_to(PluginMessage { + worker_name: Some("file_name_search".into()), + name: serde_json::to_string(&MessageToSearch::Search).unwrap(), + payload: "".into(), + }); + post_message_to(PluginMessage { + worker_name: Some("file_contents_search".into()), + name: serde_json::to_string(&MessageToSearch::Search).unwrap(), + payload: "".into(), + }); self.file_name_search_results.clear(); self.file_contents_search_results.clear(); } diff --git a/default-plugins/strider/src/state.rs b/default-plugins/strider/src/state.rs index 8dd09653a..67e9b8917 100644 --- a/default-plugins/strider/src/state.rs +++ b/default-plugins/strider/src/state.rs @@ -66,7 +66,10 @@ impl State { self.path = p; refresh_directory(self); }, - FsEntry::File(p, _) => open_file(p.strip_prefix(ROOT).unwrap()), + FsEntry::File(p, _) => open_file(FileToOpen { + path: p.strip_prefix(ROOT).unwrap().into(), + ..Default::default() + }), } } } |