diff options
| author | Aram Drevekenin <aram@poor.dev> | 2023-11-30 18:10:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-30 18:10:50 +0100 |
| commit | b0f36540fe3cb439fd0981cbb1ef5df6668ddbdf (patch) | |
| tree | 6d1d7329361ad25506cc7e1cb7ea135b9434191b /zellij-server/src/plugins | |
| parent | chore(version): bump development version (diff) | |
| download | sl0ppij-b0f36540fe3cb439fd0981cbb1ef5df6668ddbdf.tar.gz sl0ppij-b0f36540fe3cb439fd0981cbb1ef5df6668ddbdf.tar.xz sl0ppij-b0f36540fe3cb439fd0981cbb1ef5df6668ddbdf.zip | |
feat(plugins): skip plugin cache flag (#2971)
* feat(plugins): allow explicitly skipping the plugin cache when loading
* style(fmt): rustfmt
* fix tests
Diffstat (limited to 'zellij-server/src/plugins')
| -rw-r--r-- | zellij-server/src/plugins/mod.rs | 19 | ||||
| -rw-r--r-- | zellij-server/src/plugins/plugin_loader.rs | 65 | ||||
| -rw-r--r-- | zellij-server/src/plugins/unit/plugin_tests.rs | 70 | ||||
| -rw-r--r-- | zellij-server/src/plugins/wasm_bridge.rs | 2 |
4 files changed, 132 insertions, 24 deletions
diff --git a/zellij-server/src/plugins/mod.rs b/zellij-server/src/plugins/mod.rs index 2086268d..9dbacd5c 100644 --- a/zellij-server/src/plugins/mod.rs +++ b/zellij-server/src/plugins/mod.rs @@ -51,6 +51,7 @@ pub enum PluginInstruction { ClientId, Size, Option<PathBuf>, // cwd + bool, // skip cache ), Update(Vec<(Option<PluginId>, Option<ClientId>, Event)>), // Focused plugin / broadcast, client_id, event data Unload(PluginId), // plugin_id @@ -184,8 +185,15 @@ pub(crate) fn plugin_thread_main( client_id, size, cwd, - ) => match wasm_bridge.load_plugin(&run, tab_index, size, cwd.clone(), Some(client_id)) - { + skip_cache, + ) => match wasm_bridge.load_plugin( + &run, + tab_index, + size, + cwd.clone(), + skip_cache, + Some(client_id), + ) { Ok(plugin_id) => { drop(bus.senders.send_to_screen(ScreenInstruction::AddPlugin( should_float, @@ -221,7 +229,10 @@ pub(crate) fn plugin_thread_main( log::warn!("Plugin {} not found, starting it instead", run.location); // we intentionally do not provide the client_id here because it belongs to // the cli who spawned the command and is not an existing client_id - match wasm_bridge.load_plugin(&run, tab_index, size, None, None) { + let skip_cache = true; // when reloading we always skip cache + match wasm_bridge + .load_plugin(&run, tab_index, size, None, skip_cache, None) + { Ok(plugin_id) => { let should_be_open_in_place = false; drop(bus.senders.send_to_screen(ScreenInstruction::AddPlugin( @@ -286,11 +297,13 @@ pub(crate) fn plugin_thread_main( extracted_run_instructions.append(&mut extracted_floating_plugins); for run_instruction in extracted_run_instructions { if let Some(Run::Plugin(run)) = run_instruction { + let skip_cache = false; let plugin_id = wasm_bridge.load_plugin( &run, tab_index, size, None, + skip_cache, Some(client_id), )?; plugin_ids diff --git a/zellij-server/src/plugins/plugin_loader.rs b/zellij-server/src/plugins/plugin_loader.rs index 39cb4362..1f001db1 100644 --- a/zellij-server/src/plugins/plugin_loader.rs +++ b/zellij-server/src/plugins/plugin_loader.rs @@ -148,6 +148,7 @@ impl<'a> PluginLoader<'a> { client_attributes: ClientAttributes, default_shell: Option<TerminalAction>, default_layout: Box<Layout>, + skip_cache: bool, ) -> Result<()> { let err_context = || format!("failed to start plugin {plugin_id} for client {client_id}"); let mut plugin_loader = PluginLoader::new( @@ -168,27 +169,49 @@ impl<'a> PluginLoader<'a> { default_shell, default_layout, )?; - plugin_loader - .load_module_from_memory() - .or_else(|_e| plugin_loader.load_module_from_hd_cache()) - .or_else(|_e| plugin_loader.compile_module()) - .and_then(|module| plugin_loader.create_plugin_environment(module)) - .and_then(|(store, instance, plugin_env, subscriptions)| { - plugin_loader.load_plugin_instance( - store, - &instance, - &plugin_env, - &plugin_map, - &subscriptions, - ) - }) - .and_then(|_| { - plugin_loader.clone_instance_for_other_clients( - &connected_clients.lock().unwrap(), - &plugin_map, - ) - }) - .with_context(err_context)?; + if skip_cache { + plugin_loader + .compile_module() + .and_then(|module| plugin_loader.create_plugin_environment(module)) + .and_then(|(store, instance, plugin_env, subscriptions)| { + plugin_loader.load_plugin_instance( + store, + &instance, + &plugin_env, + &plugin_map, + &subscriptions, + ) + }) + .and_then(|_| { + plugin_loader.clone_instance_for_other_clients( + &connected_clients.lock().unwrap(), + &plugin_map, + ) + }) + .with_context(err_context)?; + } else { + plugin_loader + .load_module_from_memory() + .or_else(|_e| plugin_loader.load_module_from_hd_cache()) + .or_else(|_e| plugin_loader.compile_module()) + .and_then(|module| plugin_loader.create_plugin_environment(module)) + .and_then(|(store, instance, plugin_env, subscriptions)| { + plugin_loader.load_plugin_instance( + store, + &instance, + &plugin_env, + &plugin_map, + &subscriptions, + ) + }) + .and_then(|_| { + plugin_loader.clone_instance_for_other_clients( + &connected_clients.lock().unwrap(), + &plugin_map, + ) + }) + .with_context(err_context)?; + }; display_loading_stage!(end, loading_indication, senders, plugin_id); Ok(()) } diff --git a/zellij-server/src/plugins/unit/plugin_tests.rs b/zellij-server/src/plugins/unit/plugin_tests.rs index 08ac5b83..ca843358 100644 --- a/zellij-server/src/plugins/unit/plugin_tests.rs +++ b/zellij-server/src/plugins/unit/plugin_tests.rs @@ -617,6 +617,7 @@ pub fn load_new_plugin_from_hd() { client_id, size, None, + false, )); std::thread::sleep(std::time::Duration::from_millis(500)); let _ = plugin_thread_sender.send(PluginInstruction::Update(vec