Skip to content

Commit

Permalink
fix(plugins): make sure configuration is also part of the plugin keys (
Browse files Browse the repository at this point in the history
…#2727)

* fix(plugins): make sure configuration is also part of the plugin keys

* no thanks clippy
  • Loading branch information
imsnif authored Aug 25, 2023
1 parent 759ab91 commit 8c2a4e8
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 66 deletions.
5 changes: 5 additions & 0 deletions zellij-server/src/panes/floating_panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,11 @@ impl FloatingPanes {
}
pub fn get_plugin_pane_id(&self, run_plugin: &RunPlugin) -> Option<PaneId> {
let run = Some(Run::Plugin(run_plugin.clone()));
let currently_running_invoked_with: Vec<Option<Run>> = self
.panes
.iter()
.map(|(_, p)| p.invoked_with().clone())
.collect();
self.panes
.iter()
.find(|(_id, s_p)| s_p.invoked_with() == &run)
Expand Down
15 changes: 12 additions & 3 deletions zellij-server/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ use zellij_utils::{
errors::{prelude::*, ContextType, PluginContext},
input::{
command::TerminalAction,
layout::{FloatingPaneLayout, Layout, Run, RunPlugin, RunPluginLocation, TiledPaneLayout},
layout::{
FloatingPaneLayout, Layout, PluginUserConfiguration, Run, RunPlugin, RunPluginLocation,
TiledPaneLayout,
},
plugins::PluginsConfig,
},
ipc::ClientAttributes,
Expand Down Expand Up @@ -225,7 +228,10 @@ pub(crate) fn plugin_thread_main(
tab_index,
client_id,
) => {
let mut plugin_ids: HashMap<RunPluginLocation, Vec<PluginId>> = HashMap::new();
let mut plugin_ids: HashMap<
(RunPluginLocation, PluginUserConfiguration),
Vec<PluginId>,
> = HashMap::new();
let mut extracted_run_instructions = tab_layout
.clone()
.unwrap_or_else(|| layout.new_tab().0)
Expand All @@ -246,7 +252,10 @@ pub(crate) fn plugin_thread_main(
if let Some(Run::Plugin(run)) = run_instruction {
let plugin_id =
wasm_bridge.load_plugin(&run, tab_index, size, Some(client_id))?;
plugin_ids.entry(run.location).or_default().push(plugin_id);
plugin_ids
.entry((run.location, run.configuration))
.or_default()
.push(plugin_id);
}
}
drop(bus.senders.send_to_pty(PtyInstruction::NewTab(
Expand Down
11 changes: 7 additions & 4 deletions zellij-server/src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use zellij_utils::{
errors::{ContextType, PtyContext},
input::{
command::{RunCommand, TerminalAction},
layout::{FloatingPaneLayout, Layout, Run, RunPluginLocation, TiledPaneLayout},
layout::{
FloatingPaneLayout, Layout, PluginUserConfiguration, Run, RunPluginLocation,
TiledPaneLayout,
},
},
};

Expand Down Expand Up @@ -52,8 +55,8 @@ pub enum PtyInstruction {
Option<TerminalAction>,
Option<TiledPaneLayout>,
Vec<FloatingPaneLayout>,
usize, // tab_index
HashMap<RunPluginLocation, Vec<u32>>, // plugin_ids
usize, // tab_index
HashMap<(RunPluginLocation, PluginUserConfiguration), Vec<u32>>, // plugin_ids
ClientId,
), // the String is the tab name
ClosePane(PaneId),
Expand Down Expand Up @@ -595,7 +598,7 @@ impl Pty {
layout: TiledPaneLayout,
floating_panes_layout: Vec<FloatingPaneLayout>,
default_shell: Option<TerminalAction>,
plugin_ids: HashMap<RunPluginLocation, Vec<u32>>,
plugin_ids: HashMap<(RunPluginLocation, PluginUserConfiguration), Vec<u32>>,
tab_index: usize,
client_id: ClientId,
) -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use zellij_utils::pane_size::{Size, SizeInPixels};
use zellij_utils::{
input::command::TerminalAction,
input::layout::{
FloatingPaneLayout, Layout, Run, RunPlugin, RunPluginLocation, SwapFloatingLayout,
SwapTiledLayout, TiledPaneLayout,
FloatingPaneLayout, Layout, PluginUserConfiguration, Run, RunPlugin, RunPluginLocation,
SwapFloatingLayout, SwapTiledLayout, TiledPaneLayout,
},
position::Position,
};
Expand Down Expand Up @@ -208,7 +208,7 @@ pub enum ScreenInstruction {
Vec<FloatingPaneLayout>,
Vec<(u32, HoldForCommand)>, // new pane pids
Vec<(u32, HoldForCommand)>, // new floating pane pids
HashMap<RunPluginLocation, Vec<u32>>,
HashMap<(RunPluginLocation, PluginUserConfiguration), Vec<u32>>,
usize, // tab_index
ClientId,
),
Expand Down Expand Up @@ -1125,7 +1125,7 @@ impl Screen {
floating_panes_layout: Vec<FloatingPaneLayout>,
new_terminal_ids: Vec<(u32, HoldForCommand)>,
new_floating_terminal_ids: Vec<(u32, HoldForCommand)>,
new_plugin_ids: HashMap<RunPluginLocation, Vec<u32>>,
new_plugin_ids: HashMap<(RunPluginLocation, PluginUserConfiguration), Vec<u32>>,
tab_index: usize,
client_id: ClientId,
) -> Result<()> {
Expand Down
14 changes: 8 additions & 6 deletions zellij-server/src/tab/layout_applier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use std::collections::{BTreeMap, HashMap, HashSet};
use std::rc::Rc;
use zellij_utils::{
data::{Palette, Style},
input::layout::{FloatingPaneLayout, Run, RunPluginLocation, TiledPaneLayout},
input::layout::{
FloatingPaneLayout, PluginUserConfiguration, Run, RunPluginLocation, TiledPaneLayout,
},
pane_size::{Offset, PaneGeom, Size, SizeInPixels, Viewport},
};

Expand Down Expand Up @@ -96,7 +98,7 @@ impl<'a> LayoutApplier<'a> {
floating_panes_layout: Vec<FloatingPaneLayout>,
new_terminal_ids: Vec<(u32, HoldForCommand)>,
new_floating_terminal_ids: Vec<(u32, HoldForCommand)>,
mut new_plugin_ids: HashMap<RunPluginLocation, Vec<u32>>,
mut new_plugin_ids: HashMap<(RunPluginLocation, PluginUserConfiguration), Vec<u32>>,
client_id: ClientId,
) -> Result<bool> {
// true => layout has floating panes
Expand Down Expand Up @@ -198,7 +200,7 @@ impl<'a> LayoutApplier<'a> {
&mut self,
layout: TiledPaneLayout,
new_terminal_ids: Vec<(u32, HoldForCommand)>,
new_plugin_ids: &mut HashMap<RunPluginLocation, Vec<u32>>,
new_plugin_ids: &mut HashMap<(RunPluginLocation, PluginUserConfiguration), Vec<u32>>,
client_id: ClientId,
) -> Result<()> {
let err_context = || format!("failed to apply tiled panes layout");
Expand Down Expand Up @@ -230,7 +232,7 @@ impl<'a> LayoutApplier<'a> {
} else if let Some(Run::Plugin(run)) = layout.run.clone() {
let pane_title = run.location.to_string();
let pid = new_plugin_ids
.get_mut(&run.location)
.get_mut(&(run.location, run.configuration))
.and_then(|ids| ids.pop())
.with_context(err_context)?;
let mut new_plugin = PluginPane::new(
Expand Down Expand Up @@ -324,7 +326,7 @@ impl<'a> LayoutApplier<'a> {
&mut self,
floating_panes_layout: Vec<FloatingPaneLayout>,
new_floating_terminal_ids: Vec<(u32, HoldForCommand)>,
new_plugin_ids: &mut HashMap<RunPluginLocation, Vec<u32>>,
new_plugin_ids: &mut HashMap<(RunPluginLocation, PluginUserConfiguration), Vec<u32>>,
layout_name: Option<String>,
) -> Result<bool> {
// true => has floating panes
Expand All @@ -346,7 +348,7 @@ impl<'a> LayoutApplier<'a> {
} else if let Some(Run::Plugin(run)) = floating_pane_layout.run.clone() {
let pane_title = run.location.to_string();
let pid = new_plugin_ids
.get_mut(&run.location)
.get_mut(&(run.location, run.configuration))
.and_then(|ids| ids.pop())
.with_context(err_context)?;
let mut new_pane = PluginPane::new(
Expand Down
6 changes: 3 additions & 3 deletions zellij-server/src/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ use zellij_utils::{
input::{
command::TerminalAction,
layout::{
FloatingPaneLayout, Run, RunPlugin, RunPluginLocation, SwapFloatingLayout,
SwapTiledLayout, TiledPaneLayout,
FloatingPaneLayout, PluginUserConfiguration, Run, RunPlugin, RunPluginLocation,
SwapFloatingLayout, SwapTiledLayout, TiledPaneLayout,
},
parse_keys,
},
Expand Down Expand Up @@ -621,7 +621,7 @@ impl Tab {
floating_panes_layout: Vec<FloatingPaneLayout>,
new_terminal_ids: Vec<(u32, HoldForCommand)>,
new_floating_terminal_ids: Vec<(u32, HoldForCommand)>,
new_plugin_ids: HashMap<RunPluginLocation, Vec<u32>>,
new_plugin_ids: HashMap<(RunPluginLocation, PluginUserConfiguration), Vec<u32>>,
client_id: ClientId,
) -> Result<()> {
self.swap_layouts
Expand Down
Loading

0 comments on commit 8c2a4e8

Please sign in to comment.