summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-11-30 18:10:50 +0100
committerGitHub <noreply@github.com>2023-11-30 18:10:50 +0100
commitb0f36540fe3cb439fd0981cbb1ef5df6668ddbdf (patch)
tree6d1d7329361ad25506cc7e1cb7ea135b9434191b
parent65bea269a45784d5b70bf4290bf55c2ddcd670e4 (diff)
feat(plugins): skip plugin cache flag (#2971)
* feat(plugins): allow explicitly skipping the plugin cache when loading * style(fmt): rustfmt * fix tests
-rw-r--r--default-plugins/status-bar/src/second_line.rs2
-rw-r--r--src/main.rs4
-rw-r--r--zellij-server/src/plugins/mod.rs19
-rw-r--r--zellij-server/src/plugins/plugin_loader.rs65
-rw-r--r--zellij-server/src/plugins/unit/plugin_tests.rs70
-rw-r--r--zellij-server/src/plugins/wasm_bridge.rs2
-rw-r--r--zellij-server/src/pty.rs5
-rw-r--r--zellij-server/src/route.rs17
-rw-r--r--zellij-server/src/screen.rs92
-rw-r--r--zellij-server/src/unit/screen_tests.rs5
-rw-r--r--zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_launch_or_focus_plugin_action.snap3
-rw-r--r--zellij-utils/assets/prost/api.action.rs4
-rw-r--r--zellij-utils/src/cli.rs10
-rw-r--r--zellij-utils/src/input/actions.rs46
-rw-r--r--zellij-utils/src/kdl/mod.rs8
-rw-r--r--zellij-utils/src/plugin_api/action.proto2
-rw-r--r--zellij-utils/src/plugin_api/action.rs34
-rw-r--r--zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap1
-rw-r--r--zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap1
-rw-r--r--zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap1
-rw-r--r--zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap1
-rw-r--r--zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap1
22 files changed, 308 insertions, 85 deletions
diff --git a/default-plugins/status-bar/src/second_line.rs b/default-plugins/status-bar/src/second_line.rs
index d33ddad8c..53fbc6ec5 100644
--- a/default-plugins/status-bar/src/second_line.rs
+++ b/default-plugins/status-bar/src/second_line.rs
@@ -245,7 +245,7 @@ fn get_keys_and_hints(mi: &ModeInfo) -> Vec<(String, String, Vec<Key>)> {
action_key(&km, &[A::SearchToggleOption(SOpt::WholeWord)])),
]} else if mi.mode == IM::Session { vec![
(s("Detach"), s("Detach"), action_key(&km, &[Action::Detach])),
- (s("Session Manager"), s("Manager"), action_key(&km, &[A::LaunchOrFocusPlugin(Default::default(), true, true, false), TO_NORMAL])), // not entirely accurate
+ (s("Session Manager"), s("Manager"), action_key(&km, &[A::LaunchOrFocusPlugin(Default::default(), true, true, false, false), TO_NORMAL])), // not entirely accurate
(s("Select pane"), s("Select"), to_normal_key),
]} else if mi.mode == IM::Tmux { vec![
(s("Move focus"), s("Move"), action_key_group(&km, &[
diff --git a/src/main.rs b/src/main.rs
index 72dce0d26..955a982b6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -31,6 +31,7 @@ fn main() {
start_suspended,
})) = opts.command
{
+ let skip_plugin_cache = false; // N/A for this action
let command_cli_action = CliAction::NewPane {
command,
plugin: None,
@@ -42,6 +43,7 @@ fn main() {
close_on_exit,
start_suspended,
configuration: None,
+ skip_plugin_cache,
};
commands::send_action_to_session(command_cli_action, opts.session, config);
std::process::exit(0);
@@ -51,6 +53,7 @@ fn main() {
floating,
in_place,
configuration,
+ skip_plugin_cache,
})) = opts.command
{
let command_cli_action = CliAction::NewPane {
@@ -64,6 +67,7 @@ fn main() {
close_on_exit: false,
start_suspended: false,
configuration,
+ skip_plugin_cache,
};
commands::send_action_to_session(command_cli_action, opts.session, config);
std::process::exit(0);
diff --git a/zellij-server/src/plugins/mod.rs b/zellij-server/src/plugins/mod.rs
index 2086268d8..9dbacd5c3 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 39cb43623..1f001db1a 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 08ac5b832..ca8433583 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![(
@@ -688,6 +689,7 @@ pub fn plugin_workers() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
// we send a SystemClipboardFailure to trigger the custom handler in the fixture plugin that
@@ -763,6 +765,7 @@ pub fn plugin_workers_persist_state() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
// we send a SystemClipboardFailure to trigger the custom handler in the fixture plugin that
@@ -842,6 +845,7 @@ pub fn can_subscribe_to_hd_events() {
client_id,
size,
None,
+ false,
));
// extra long time because we only start the fs watcher on plugin load
std::thread::sleep(std::time::Duration::from_millis(5000));
@@ -915,6 +919,7 @@ pub fn switch_to_mode_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -985,6 +990,7 @@ pub fn switch_to_mode_plugin_command_permission_denied() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1055,6 +1061,7 @@ pub fn new_tabs_with_layout_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1139,6 +1146,7 @@ pub fn new_tab_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1209,6 +1217,7 @@ pub fn go_to_next_tab_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1278,6 +1287,7 @@ pub fn go_to_previous_tab_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1347,6 +1357,7 @@ pub fn resize_focused_pane_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1416,6 +1427,7 @@ pub fn resize_focused_pane_with_direction_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1485,6 +1497,7 @@ pub fn focus_next_pane_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1554,6 +1567,7 @@ pub fn focus_previous_pane_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1623,6 +1637,7 @@ pub fn move_focus_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1692,6 +1707,7 @@ pub fn move_focus_or_tab_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1761,6 +1777,7 @@ pub fn edit_scrollback_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1830,6 +1847,7 @@ pub fn write_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1899,6 +1917,7 @@ pub fn write_chars_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -1968,6 +1987,7 @@ pub fn toggle_tab_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2037,6 +2057,7 @@ pub fn move_pane_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2106,6 +2127,7 @@ pub fn move_pane_with_direction_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2176,6 +2198,7 @@ pub fn clear_screen_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2246,6 +2269,7 @@ pub fn scroll_up_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2315,6 +2339,7 @@ pub fn scroll_down_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2384,6 +2409,7 @@ pub fn scroll_to_top_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2453,6 +2479,7 @@ pub fn scroll_to_bottom_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2522,6 +2549,7 @@ pub fn page_scroll_up_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2591,6 +2619,7 @@ pub fn page_scroll_down_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2660,6 +2689,7 @@ pub fn toggle_focus_fullscreen_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2729,6 +2759,7 @@ pub fn toggle_pane_frames_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2798,6 +2829,7 @@ pub fn toggle_pane_embed_or_eject_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2867,6 +2899,7 @@ pub fn undo_rename_pane_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -2936,6 +2969,7 @@ pub fn close_focus_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -3005,6 +3039,7 @@ pub fn toggle_active_tab_sync_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -3074,6 +3109,7 @@ pub fn close_focused_tab_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -3143,6 +3179,7 @@ pub fn undo_rename_tab_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -3212,6 +3249,7 @@ pub fn previous_swap_layout_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -3281,6 +3319,7 @@ pub fn next_swap_layout_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -3350,6 +3389,7 @@ pub fn go_to_tab_name_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -3419,6 +3459,7 @@ pub fn focus_or_create_tab_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -3488,6 +3529,7 @@ pub fn go_to_tab() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -3557,6 +3599,7 @@ pub fn start_or_reload_plugin() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -3633,6 +3676,7 @@ pub fn quit_zellij_plugin_command() {
client_id,
size,
None,
+ false,
));
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@@ -3709,6 +3753,7 @@ pub fn detach_plugin_