fix(plugins): start plugin pane in cwd of focused pane if possible (#2905)

* fix(plugins): start plugin pane in cwd of focused pane if possible

* disable clippy - I have had enough

* fix tests
This commit is contained in:
Aram Drevekenin 2023-11-06 08:30:17 +01:00 committed by GitHub
parent 9ed8569920
commit a3d63bec55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 257 additions and 109 deletions

View File

@ -65,19 +65,3 @@ jobs:
run: rustup show run: rustup show
- name: Check Format - name: Check Format
run: cargo xtask format --check run: cargo xtask format --check
clippy:
name: Check Clippy Lints
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Protoc
uses: arduino/setup-protoc@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup toolchain
run: rustup show
- uses: Swatinem/rust-cache@v2
- name: Check clippy lints
run: cargo xtask clippy

View File

@ -50,6 +50,7 @@ pub enum PluginInstruction {
Option<PaneId>, // pane id to replace if this is to be opened "in-place" Option<PaneId>, // pane id to replace if this is to be opened "in-place"
ClientId, ClientId,
Size, Size,
Option<PathBuf>, // cwd
), ),
Update(Vec<(Option<PluginId>, Option<ClientId>, Event)>), // Focused plugin / broadcast, client_id, event data Update(Vec<(Option<PluginId>, Option<ClientId>, Event)>), // Focused plugin / broadcast, client_id, event data
Unload(PluginId), // plugin_id Unload(PluginId), // plugin_id
@ -182,7 +183,8 @@ pub(crate) fn plugin_thread_main(
pane_id_to_replace, pane_id_to_replace,
client_id, client_id,
size, size,
) => match wasm_bridge.load_plugin(&run, tab_index, size, Some(client_id)) { cwd,
) => match wasm_bridge.load_plugin(&run, tab_index, size, cwd, Some(client_id)) {
Ok(plugin_id) => { Ok(plugin_id) => {
drop(bus.senders.send_to_screen(ScreenInstruction::AddPlugin( drop(bus.senders.send_to_screen(ScreenInstruction::AddPlugin(
should_float, should_float,
@ -217,7 +219,7 @@ pub(crate) fn plugin_thread_main(
log::warn!("Plugin {} not found, starting it instead", run.location); log::warn!("Plugin {} not found, starting it instead", run.location);
// we intentionally do not provide the client_id here because it belongs to // 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 // the cli who spawned the command and is not an existing client_id
match wasm_bridge.load_plugin(&run, tab_index, size, None) { match wasm_bridge.load_plugin(&run, tab_index, size, None, None) {
Ok(plugin_id) => { Ok(plugin_id) => {
let should_be_open_in_place = false; let should_be_open_in_place = false;
drop(bus.senders.send_to_screen(ScreenInstruction::AddPlugin( drop(bus.senders.send_to_screen(ScreenInstruction::AddPlugin(
@ -281,8 +283,13 @@ pub(crate) fn plugin_thread_main(
extracted_run_instructions.append(&mut extracted_floating_plugins); extracted_run_instructions.append(&mut extracted_floating_plugins);
for run_instruction in extracted_run_instructions { for run_instruction in extracted_run_instructions {
if let Some(Run::Plugin(run)) = run_instruction { if let Some(Run::Plugin(run)) = run_instruction {
let plugin_id = let plugin_id = wasm_bridge.load_plugin(
wasm_bridge.load_plugin(&run, tab_index, size, Some(client_id))?; &run,
tab_index,
size,
None,
Some(client_id),
)?;
plugin_ids plugin_ids
.entry((run.location, run.configuration)) .entry((run.location, run.configuration))
.or_default() .or_default()

View File

@ -616,6 +616,7 @@ pub fn load_new_plugin_from_hd() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -686,6 +687,7 @@ pub fn plugin_workers() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
// we send a SystemClipboardFailure to trigger the custom handler in the fixture plugin that // we send a SystemClipboardFailure to trigger the custom handler in the fixture plugin that
@ -760,6 +762,7 @@ pub fn plugin_workers_persist_state() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
// we send a SystemClipboardFailure to trigger the custom handler in the fixture plugin that // we send a SystemClipboardFailure to trigger the custom handler in the fixture plugin that
@ -838,6 +841,7 @@ pub fn can_subscribe_to_hd_events() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
// extra long time because we only start the fs watcher on plugin load // extra long time because we only start the fs watcher on plugin load
std::thread::sleep(std::time::Duration::from_millis(5000)); std::thread::sleep(std::time::Duration::from_millis(5000));
@ -910,6 +914,7 @@ pub fn switch_to_mode_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -979,6 +984,7 @@ pub fn switch_to_mode_plugin_command_permission_denied() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1048,6 +1054,7 @@ pub fn new_tabs_with_layout_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1131,6 +1138,7 @@ pub fn new_tab_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1200,6 +1208,7 @@ pub fn go_to_next_tab_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1268,6 +1277,7 @@ pub fn go_to_previous_tab_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1336,6 +1346,7 @@ pub fn resize_focused_pane_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1404,6 +1415,7 @@ pub fn resize_focused_pane_with_direction_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1472,6 +1484,7 @@ pub fn focus_next_pane_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1540,6 +1553,7 @@ pub fn focus_previous_pane_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1608,6 +1622,7 @@ pub fn move_focus_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1676,6 +1691,7 @@ pub fn move_focus_or_tab_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1744,6 +1760,7 @@ pub fn edit_scrollback_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1812,6 +1829,7 @@ pub fn write_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1880,6 +1898,7 @@ pub fn write_chars_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -1948,6 +1967,7 @@ pub fn toggle_tab_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2016,6 +2036,7 @@ pub fn move_pane_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2084,6 +2105,7 @@ pub fn move_pane_with_direction_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2153,6 +2175,7 @@ pub fn clear_screen_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2222,6 +2245,7 @@ pub fn scroll_up_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2290,6 +2314,7 @@ pub fn scroll_down_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2358,6 +2383,7 @@ pub fn scroll_to_top_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2426,6 +2452,7 @@ pub fn scroll_to_bottom_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2494,6 +2521,7 @@ pub fn page_scroll_up_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2562,6 +2590,7 @@ pub fn page_scroll_down_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2630,6 +2659,7 @@ pub fn toggle_focus_fullscreen_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2698,6 +2728,7 @@ pub fn toggle_pane_frames_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2766,6 +2797,7 @@ pub fn toggle_pane_embed_or_eject_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2834,6 +2866,7 @@ pub fn undo_rename_pane_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2902,6 +2935,7 @@ pub fn close_focus_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -2970,6 +3004,7 @@ pub fn toggle_active_tab_sync_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3038,6 +3073,7 @@ pub fn close_focused_tab_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3106,6 +3142,7 @@ pub fn undo_rename_tab_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3174,6 +3211,7 @@ pub fn previous_swap_layout_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3242,6 +3280,7 @@ pub fn next_swap_layout_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3310,6 +3349,7 @@ pub fn go_to_tab_name_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3378,6 +3418,7 @@ pub fn focus_or_create_tab_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3446,6 +3487,7 @@ pub fn go_to_tab() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3514,6 +3556,7 @@ pub fn start_or_reload_plugin() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3589,6 +3632,7 @@ pub fn quit_zellij_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3664,6 +3708,7 @@ pub fn detach_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3739,6 +3784,7 @@ pub fn open_file_floating_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3814,6 +3860,7 @@ pub fn open_file_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3890,6 +3937,7 @@ pub fn open_file_with_line_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -3965,6 +4013,7 @@ pub fn open_file_with_line_floating_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4040,6 +4089,7 @@ pub fn open_terminal_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4115,6 +4165,7 @@ pub fn open_terminal_floating_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4190,6 +4241,7 @@ pub fn open_command_pane_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4265,6 +4317,7 @@ pub fn open_command_pane_floating_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4333,6 +4386,7 @@ pub fn switch_to_tab_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4396,6 +4450,7 @@ pub fn hide_self_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4459,6 +4514,7 @@ pub fn show_self_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4527,6 +4583,7 @@ pub fn close_terminal_pane_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4595,6 +4652,7 @@ pub fn close_plugin_pane_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4663,6 +4721,7 @@ pub fn focus_terminal_pane_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4731,6 +4790,7 @@ pub fn focus_plugin_pane_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4799,6 +4859,7 @@ pub fn rename_terminal_pane_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4867,6 +4928,7 @@ pub fn rename_plugin_pane_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -4935,6 +4997,7 @@ pub fn rename_tab_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -5012,6 +5075,7 @@ pub fn send_configuration_to_plugins() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -5077,6 +5141,7 @@ pub fn request_plugin_permissions() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -5166,6 +5231,7 @@ pub fn granted_permission_request_result() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -5254,6 +5320,7 @@ pub fn denied_permission_request_result() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -5321,6 +5388,7 @@ pub fn run_command_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -5396,6 +5464,7 @@ pub fn run_command_with_env_vars_and_cwd_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(
@ -5471,6 +5540,7 @@ pub fn web_request_plugin_command() {
None, None,
client_id, client_id,
size, size,
None,
)); ));
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::sleep(std::time::Duration::from_millis(500));
let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![( let _ = plugin_thread_sender.send(PluginInstruction::Update(vec![(

View File

@ -113,6 +113,7 @@ impl WasmBridge {
run: &RunPlugin, run: &RunPlugin,
tab_index: usize, tab_index: usize,
size: Size, size: Size,
cwd: Option<PathBuf>,
client_id: Option<ClientId>, client_id: Option<ClientId>,
) -> Result<PluginId> { ) -> Result<PluginId> {
// returns the plugin id // returns the plugin id
@ -153,7 +154,7 @@ impl WasmBridge {
let plugin_map = self.plugin_map.clone(); let plugin_map = self.plugin_map.clone();
let connected_clients = self.connected_clients.clone(); let connected_clients = self.connected_clients.clone();
let path_to_default_shell = self.path_to_default_shell.clone(); let path_to_default_shell = self.path_to_default_shell.clone();
let zellij_cwd = self.zellij_cwd.clone(); let zellij_cwd = cwd.unwrap_or_else(|| self.zellij_cwd.clone());
let capabilities = self.capabilities.clone(); let capabilities = self.capabilities.clone();
let client_attributes = self.client_attributes.clone(); let client_attributes = self.client_attributes.clone();
let default_shell = self.default_shell.clone(); let default_shell = self.default_shell.clone();

View File

@ -18,10 +18,11 @@ use zellij_utils::{
input::{ input::{
command::{RunCommand, TerminalAction}, command::{RunCommand, TerminalAction},
layout::{ layout::{
FloatingPaneLayout, Layout, PluginUserConfiguration, Run, RunPluginLocation, FloatingPaneLayout, Layout, PluginUserConfiguration, Run, RunPlugin, RunPluginLocation,
TiledPaneLayout, TiledPaneLayout,
}, },
}, },
pane_size::Size,
session_serialization, session_serialization,
}; };
@ -74,6 +75,16 @@ pub enum PtyInstruction {
), // String is an optional pane name ), // String is an optional pane name
DumpLayout(SessionLayoutMetadata, ClientId), DumpLayout(SessionLayoutMetadata, ClientId),
LogLayoutToHd(SessionLayoutMetadata), LogLayoutToHd(SessionLayoutMetadata),
FillPluginCwd(
Option<bool>, // should float
bool, // should be opened in place
Option<String>, // pane title
RunPlugin,
usize, // tab index
Option<PaneId>, // pane id to replace if this is to be opened "in-place"
ClientId,
Size,
),
Exit, Exit,
} }
@ -94,6 +105,7 @@ impl From<&PtyInstruction> for PtyContext {
PtyInstruction::SpawnInPlaceTerminal(..) => PtyContext::SpawnInPlaceTerminal, PtyInstruction::SpawnInPlaceTerminal(..) => PtyContext::SpawnInPlaceTerminal,
PtyInstruction::DumpLayout(..) => PtyContext::DumpLayout, PtyInstruction::DumpLayout(..) => PtyContext::DumpLayout,
PtyInstruction::LogLayoutToHd(..) => PtyContext::LogLayoutToHd, PtyInstruction::LogLayoutToHd(..) => PtyContext::LogLayoutToHd,
PtyInstruction::FillPluginCwd(..) => PtyContext::FillPluginCwd,
PtyInstruction::Exit => PtyContext::Exit, PtyInstruction::Exit => PtyContext::Exit,
} }
} }
@ -624,6 +636,27 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {
}, },
} }
}, },
PtyInstruction::FillPluginCwd(
should_float,
should_be_open_in_place,
pane_title,
run,
tab_index,
pane_id_to_replace,
client_id,
size,
) => {
pty.fill_plugin_cwd(
should_float,
should_be_open_in_place,
pane_title,
run,
tab_index,
pane_id_to_replace,
client_id,
size,
)?;
},
PtyInstruction::Exit => break, PtyInstruction::Exit => break,
} }
} }
@ -1277,6 +1310,44 @@ impl Pty {
session_layout_metadata.update_terminal_commands(terminal_ids_to_commands); session_layout_metadata.update_terminal_commands(terminal_ids_to_commands);
session_layout_metadata.update_terminal_cwds(terminal_ids_to_cwds); session_layout_metadata.update_terminal_cwds(terminal_ids_to_cwds);
} }
pub fn fill_plugin_cwd(
&self,
should_float: Option<bool>,
should_open_in_place: bool, // should be opened in place
pane_title: Option<String>, // pane title
run: RunPlugin,
tab_index: usize, // tab index
pane_id_to_replace: Option<PaneId>, // pane id to replace if this is to be opened "in-place"
client_id: ClientId,
size: Size,
) -> Result<()> {
let cwd = self
.active_panes
.get(&client_id)
.and_then(|pane| match pane {
PaneId::Plugin(..) => None,
PaneId::Terminal(id) => self.id_to_child_pid.get(id),
})
.and_then(|&id| {
self.bus
.os_input
.as_ref()
.and_then(|input| input.get_cwd(Pid::from_raw(id)))
});
self.bus.senders.send_to_plugin(PluginInstruction::Load(
should_float,
should_open_in_place,
pane_title,
run,
tab_index,
pane_id_to_replace,
client_id,
size,
cwd,
))?;
Ok(())
}
} }
impl Drop for Pty { impl Drop for Pty {

View File

@ -3146,13 +3146,16 @@ pub(crate) fn screen_thread_main(
let size = Size::default(); let size = Size::default();
let should_float = Some(false); let should_float = Some(false);
let should_be_opened_in_place = false; let should_be_opened_in_place = false;
screen.bus.senders.send_to_plugin(PluginInstruction::Load( screen
.bus
.senders
.send_to_pty(PtyInstruction::FillPluginCwd(
should_float, should_float,
should_be_opened_in_place, should_be_opened_in_place,
pane_title, pane_title,
run_plugin, run_plugin,
*tab_index, *tab_index,
None, // pane it to replace None,
client_id, client_id,
size, size,
))?; ))?;
@ -3163,13 +3166,16 @@ pub(crate) fn screen_thread_main(
let size = Size::default(); let size = Size::default();
let should_float = Some(true); let should_float = Some(true);
let should_be_opened_in_place = false; let should_be_opened_in_place = false;
screen.bus.senders.send_to_plugin(PluginInstruction::Load( screen
.bus
.senders
.send_to_pty(PtyInstruction::FillPluginCwd(
should_float, should_float,
should_be_opened_in_place, should_be_opened_in_place,
pane_title, pane_title,
run_plugin, run_plugin,
*tab_index, *tab_index,
None, // pane id to replace None,
client_id, client_id,
size, size,
))?; ))?;
@ -3191,7 +3197,10 @@ pub(crate) fn screen_thread_main(
let size = Size::default(); let size = Size::default();
let should_float = None; let should_float = None;
let should_be_in_place = true; let should_be_in_place = true;
screen.bus.senders.send_to_plugin(PluginInstruction::Load( screen
.bus
.senders
.send_to_pty(PtyInstruction::FillPluginCwd(
should_float, should_float,
should_be_in_place, should_be_in_place,
pane_title, pane_title,
@ -3212,6 +3221,7 @@ pub(crate) fn screen_thread_main(
let tab_index = screen.active_tab_indices.values().next().unwrap_or(&1); let tab_index = screen.active_tab_indices.values().next().unwrap_or(&1);
let size = Size::default(); let size = Size::default();
let should_float = Some(false); let should_float = Some(false);
screen screen
.bus .bus
.senders .senders
@ -3320,12 +3330,14 @@ pub(crate) fn screen_thread_main(
should_open_in_place, should_open_in_place,
pane_id_to_replace, pane_id_to_replace,
client_id, client_id,
) => { ) => match pane_id_to_replace {
match pane_id_to_replace {
Some(pane_id_to_replace) => match screen.active_tab_indices.values().next() { Some(pane_id_to_replace) => match screen.active_tab_indices.values().next() {
Some(tab_index) => { Some(tab_index) => {
let size = Size::default(); let size = Size::default();
screen.bus.senders.send_to_plugin(PluginInstruction::Load( screen
.bus
.senders
.send_to_pty(PtyInstruction::FillPluginCwd(
Some(should_float), Some(should_float),
should_open_in_place, should_open_in_place,
None, None,
@ -3365,25 +3377,27 @@ pub(crate) fn screen_thread_main(
screen.render()?; screen.render()?;
screen.log_and_report_session_state()?; screen.log_and_report_session_state()?;
} else { } else {
screen.bus.senders.send_to_plugin(PluginInstruction::Load( screen
.bus
.senders
.send_to_pty(PtyInstruction::FillPluginCwd(
Some(should_float), Some(should_float),
should_open_in_place, should_open_in_place,
None, None,
run_plugin, run_plugin,
tab_index, tab_index,
None, // pane id to replace None,
client_id, client_id,
Size::default(), Size::default(),
))?; ))?;
} }
}, },
None => log::error!( None => {
"No connected clients found - cannot load or focus plugin" log::error!("No connected clients found - cannot load or focus plugin")
),
}
}, },
} }
}, },
},
ScreenInstruction::SuppressPane(pane_id, client_id) => { ScreenInstruction::SuppressPane(pane_id, client_id) => {
let all_tabs = screen.get_tabs_mut(); let all_tabs = screen.get_tabs_mut();
for tab in all_tabs.values_mut() { for tab in all_tabs.values_mut() {

View File

@ -2581,14 +2581,14 @@ pub fn send_cli_launch_or_focus_plugin_action() {
}; };
let client_id = 10; // fake client id should not appear in the screen's state let client_id = 10; // fake client id should not appear in the screen's state
let mut mock_screen = MockScreen::new(size); let mut mock_screen = MockScreen::new(size);
let plugin_receiver = mock_screen.plugin_receiver.take().unwrap(); let pty_receiver = mock_screen.pty_receiver.take().unwrap();
let session_metadata = mock_screen.clone_session_metadata(); let session_metadata = mock_screen.clone_session_metadata();
let screen_thread = mock_screen.run(None, vec![]); let screen_thread = mock_screen.run(None, vec![]);
let received_plugin_instructions = Arc::new(Mutex::new(vec![])); let received_pty_instructions = Arc::new(Mutex::new(vec![]));
let plugin_thread = log_actions_in_thread!( let pty_thread = log_actions_in_thread!(
received_plugin_instructions, received_pty_instructions,
PluginInstruction::Exit, PtyInstruction::Exit,
plugin_receiver pty_receiver
); );
let cli_action = CliAction::LaunchOrFocusPlugin { let cli_action = CliAction::LaunchOrFocusPlugin {
floating: true, floating: true,
@ -2599,19 +2599,19 @@ pub fn send_cli_launch_or_focus_plugin_action() {
}; };
send_cli_action_to_server(&session_metadata, cli_action, client_id); send_cli_action_to_server(&session_metadata, cli_action, client_id);
std::thread::sleep(std::time::Duration::from_millis(100)); // give time for actions to be std::thread::sleep(std::time::Duration::from_millis(100)); // give time for actions to be
mock_screen.teardown(vec![plugin_thread, screen_thread]); mock_screen.teardown(vec![pty_thread, screen_thread]);
let plugin_load_instruction = received_plugin_instructions let pty_fill_plugin_cwd_instruction = received_pty_instructions
.lock() .lock()
.unwrap() .unwrap()
.iter() .iter()
.find(|instruction| match instruction { .find(|instruction| match instruction {
PluginInstruction::Load(..) => true, PtyInstruction::FillPluginCwd(..) => true,
_ => false, _ => false,
}) })
.cloned(); .cloned();
assert_snapshot!(format!("{:#?}", plugin_load_instruction)); assert_snapshot!(format!("{:#?}", pty_fill_plugin_cwd_instruction));
} }
#[test] #[test]

View File

@ -1,10 +1,10 @@
--- ---
source: zellij-server/src/./unit/screen_tests.rs source: zellij-server/src/./unit/screen_tests.rs
assertion_line: 2596 assertion_line: 2614
expression: "format!(\"{:#?}\", plugin_load_instruction)" expression: "format!(\"{:#?}\", pty_fill_plugin_cwd_instruction)"
--- ---
Some( Some(
Load( FillPluginCwd(
Some( Some(
true, true,
), ),

View File

@ -367,6 +367,7 @@ pub enum PtyContext {
SpawnInPlaceTerminal, SpawnInPlaceTerminal,
DumpLayout, DumpLayout,
LogLayoutToHd, LogLayoutToHd,
FillPluginCwd,
Exit, Exit,
} }