Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/sheprd-gpui/locales/en-US/error-plugin-actions.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Why a plugin action from a pane, tab, or workspace menu did not run.

error-plugin-actions-unsupported-host = Plugin actions need a local session or SSH host; custom socket endpoints are unsupported.
error-plugin-actions-development-session = Plugin actions are not available for development (--dev) sessions.
error-plugin-actions-missing-cli = Could not run the plugin action: the herdr CLI was not found on this host.
error-plugin-actions-script = Could not run the plugin action: { $error }
# $error is Herdr's own message.
error-plugin-actions-refused = Herdr refused the plugin action: { $error }
error-plugin-actions-decode = Could not run the plugin action: herdr returned unexpected output.
error-plugin-actions-unanswered = Could not run the plugin action: herdr did not answer.
error-plugin-actions-target-gone = The plugin action's pane, tab, or workspace no longer exists.
5 changes: 5 additions & 0 deletions crates/sheprd-gpui/locales/en-US/plugin-actions.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Plugin actions in the pane, tab, and workspace menus.

# Shown on the window when an action chosen from a menu did not run.
# $action is the plugin's title for the action; $error says why.
plugin-actions-failed = { $action }: { $error }
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use super::*;
use crate::terminal::Selection;
use serde_json::{Value, json};

// Plugin actions run through POSIX host scripts.
#[cfg(any(target_os = "linux", target_os = "macos"))]
mod menus;

const PLUGIN: &str = "plugin-annotate";
const SHELL: &str = "shell-build";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
//! The pane menu's plugin rows and a highlight: only the menu of the pane
//! that holds the highlight lists the actions that take one, only those
//! actions are sent it, and it is fenced by the frame on screen when the
//! row runs.

use super::*;
use crate::plugin_actions::{Target, tests::fake};
use sheprd_client::scrollback::{SelectionReadParams, TextPoint};

/// Opens the menu of the pane under grid cell `(column, row)` and lets the
/// stand-in host's answer land.
fn open_at(
view: &gpui::Entity<SheprdWindow>,
cx: &mut gpui::VisualTestContext,
column: f32,
row: f32,
) {
cx.update(|window, cx| {
view.update(cx, |view, cx| {
view.dismiss_menu(window, cx);
let position = mouse_position(view, column, row);
view.open_pane_menu_at(position, window, cx);
assert!(view.menu.page.is_some());
})
});
cx.run_until_parked();
}

/// Presses Up `ups` times from no selection, so the `ups`th plugin row from
/// the end, then Enter; returns the action run, its pane, and its selection.
fn run_from_end(
view: &gpui::Entity<SheprdWindow>,
cx: &mut gpui::VisualTestContext,
ups: usize,
) -> (String, Target, Option<SelectionReadParams>) {
let key = |key: &str| gpui::KeyDownEvent {
keystroke: crate::keymap::parse_keystroke(key).unwrap(),
is_held: false,
prefer_character_input: false,
};
cx.update(|window, cx| {
view.update(cx, |view, cx| {
for _ in 0..ups {
view.pane_menu_key(&key("up"), window, cx);
}
view.pane_menu_key(&key("enter"), window, cx);
})
});
cx.run_until_parked();
let mut run = fake::take_invocations();
assert_eq!(run.len(), 1);
let invocation = run.remove(0);
(
format!("{}/{}", invocation.plugin_id, invocation.action_id),
invocation.target,
invocation.selection,
)
}

#[gpui::test]
fn only_the_highlighted_panes_menu_offers_and_sends_its_selection(cx: &mut gpui::TestAppContext) {
let (fixture, cx) = cx.add_window_view(|window, cx| {
Fixture(cx.new(|cx| crate::sidebar::layout_tests::fixture_window(window, cx)))
});
let view = fixture.update(cx, |fixture, _| fixture.0.clone());
let (endpoint, _server) = connected_endpoint("plugin-menu-selection");
cx.update(|_, cx| {
view.update(cx, |view, cx| {
prepare(view, endpoint, cx);
// A highlight in the focused pane, w1:p1.
select(view, (3., 2.), (7., 3.), true);
fake::install(view);
fake::answer(fake::hunk_and_notes());
})
});
let other = Target::Pane("w1:p2".into());
let highlighted = Target::Pane("w1:p1".into());

// The other pane's menu lists Hunk's review and Notes' append only: no
// selection rows, and no selection sent even to an action that takes one.
open_at(&view, cx, 50., 5.);
assert_eq!(
run_from_end(&view, cx, 1),
("notes/append".into(), other.clone(), None)
);
open_at(&view, cx, 50., 5.);
assert_eq!(
run_from_end(&view, cx, 2),
("hunk/review-pane".into(), other, None)
);

// The highlighted pane's menu adds Hunk's selection action. Output while
// it is open moves the pane to revision 9; the action is fenced with it.
open_at(&view, cx, 10., 5.);
cx.update(|_, cx| {
view.update(cx, |view, _| {
Arc::make_mut(view.live.surface.as_mut().unwrap()).panes[0].content_revision = 9;
})
});
let selection = SelectionReadParams {
pane_id: "w1:p1".into(),
anchor: TextPoint { row: 1, col: 2 },
cursor: TextPoint { row: 2, col: 6 },
content_revision: Some(9),
};
assert_eq!(
run_from_end(&view, cx, 2),
(
"hunk/send-selection".into(),
highlighted.clone(),
Some(selection.clone())
)
);
open_at(&view, cx, 10., 5.);
assert_eq!(
run_from_end(&view, cx, 1),
("notes/append".into(), highlighted.clone(), Some(selection))
);
// An action that takes no selection is not sent one.
open_at(&view, cx, 10., 5.);
assert_eq!(
run_from_end(&view, cx, 3),
("hunk/review-pane".into(), highlighted, None)
);
}
2 changes: 2 additions & 0 deletions crates/sheprd-gpui/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ pub enum Error {
#[source]
source: Box<Error>,
},
#[error(transparent)]
PluginActions(#[from] crate::plugin_actions::Error),
#[cfg(target_os = "macos")]
#[error("The page that opened a popup is no longer in a window")]
PopupOpener,
Expand Down
1 change: 1 addition & 0 deletions crates/sheprd-gpui/src/i18n/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mod overview;
mod palette;
mod pane_carry;
mod pane_move;
mod plugin_actions;
mod port_forward;
mod processes;
mod protocol;
Expand Down
22 changes: 22 additions & 0 deletions crates/sheprd-gpui/src/i18n/errors/plugin_actions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! Why a plugin action did not run, from `error-plugin-actions.ftl`.

use super::Localize;
use crate::{i18n::fl, plugin_actions::Error};

impl Localize for Error {
fn localize(&self) -> String {
match self {
Self::UnsupportedHost => fl!("error-plugin-actions-unsupported-host"),
Self::DevelopmentSession => fl!("error-plugin-actions-development-session"),
Self::MissingCli(_) => fl!("error-plugin-actions-missing-cli"),
Self::Script(error) => fl!("error-plugin-actions-script", error = error.localize()),
// Herdr's own message, as it wrote it.
Self::Refused { message, .. } => {
fl!("error-plugin-actions-refused", error = message.as_str())
}
Self::Decode(_) => fl!("error-plugin-actions-decode"),
Self::Unanswered => fl!("error-plugin-actions-unanswered"),
Self::TargetGone => fl!("error-plugin-actions-target-gone"),
}
}
}
1 change: 1 addition & 0 deletions crates/sheprd-gpui/src/i18n/errors/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl Localize for Error {
Self::Path { path: file, source } => {
fl!("error-path", path = path(file), error = source.localize())
}
Self::PluginActions(error) => error.localize(),
#[cfg(target_os = "macos")]
Self::PopupOpener => fl!("error-popup-opener"),
Self::PortForward(error) => error.localize(),
Expand Down
1 change: 1 addition & 0 deletions crates/sheprd-gpui/src/i18n/errors/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ mod overview;
mod palette;
mod pane_carry;
mod pane_move;
mod plugin_actions;
mod port_forward;
mod processes;
mod protocol;
Expand Down
50 changes: 50 additions & 0 deletions crates/sheprd-gpui/src/i18n/errors/tests/plugin_actions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use super::*;
use crate::plugin_actions::Error;
use sheprd_i18n::{Locale, Pseudo};

fn every_variant() -> Vec<Error> {
vec![
Error::UnsupportedHost,
Error::DevelopmentSession,
Error::MissingCli(sheprd_client::Error::ResponseType),
Error::Script(sheprd_client::Error::ScriptOutputLimit),
Error::Refused {
code: "plugin_disabled".into(),
message: "plugin hunk is disabled".into(),
},
Error::Decode(serde_json::from_str::<u8>("x").unwrap_err()),
Error::Unanswered,
Error::TargetGone,
]
}

#[test]
fn every_plugin_action_variant_has_a_message() {
assert_localized(&every_variant());
}

/// The app's own error shows the feature's message, in every language.
#[test]
fn the_app_error_shows_the_plugin_action_message() {
let wrapped: Vec<crate::Error> = every_variant().into_iter().map(Into::into).collect();
assert_localized(&wrapped);
for (error, inner) in wrapped.iter().zip(every_variant()) {
assert_eq!(error.to_string(), inner.to_string());
}
}

/// Herdr's refusal is shown as Herdr wrote it, untranslated.
#[test]
fn herdrs_refusal_keeps_its_words() {
let refused = Error::Refused {
code: "action_not_found".into(),
message: "action review-pane not found in plugin hunk".into(),
};
crate::i18n::show(&Pseudo::Accented.locale());
let shown = refused.localize();
crate::i18n::show(&Locale::FALLBACK);
assert!(
shown.contains("action review-pane not found in plugin hunk"),
"{shown}"
);
}
1 change: 1 addition & 0 deletions crates/sheprd-gpui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ mod palette;
mod pane_menu;
mod pane_move;
mod panel_resize;
mod plugin_actions;
mod plugin_values;
mod port_forward;
mod preferences;
Expand Down
6 changes: 5 additions & 1 deletion crates/sheprd-gpui/src/menu/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,15 +737,19 @@ impl SheprdWindow {
panel = panel.child(self.render_host_menu(cx));
} else if page == Page::MoveTab {
panel = self.render_tab_move_picker(panel, cx);
} else if page == Page::Tab {
panel = self.render_tab_actions(panel, cx);
} else if page.is_tab_menu() {
panel = panel.child(self.render_tab_menu(cx));
} else if page == Page::Group {
panel = self.render_group_menu(panel, cx);
} else if page == Page::MovePane {
panel = self.render_move_picker(panel, cx);
} else if page == Page::Pane {
panel = self.render_pane_actions(panel, cx);
} else if matches!(
page,
Page::Pane | Page::RenamePane | Page::PaneProcesses | Page::KillProcesses
Page::RenamePane | Page::PaneProcesses | Page::KillProcesses
) {
panel = panel.child(self.render_pane_menu(cx));
} else if page == Page::Keybinds {
Expand Down
5 changes: 4 additions & 1 deletion crates/sheprd-gpui/src/menu/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ pub(crate) enum WorkspaceMenuAction {
/// applied at once: the mute belongs to this client, never the daemon.
Mute,
Unmute,
/// Run the plugin action at this index among the popover's plugin rows.
Plugin(usize),
}

impl Page {
Expand Down Expand Up @@ -308,7 +310,8 @@ impl WorkspaceMenuAction {
Self::Script(_) => "icons/play.svg",
Self::Mute => crate::icons::MUTED,
Self::Unmute => "icons/bell.svg",
Self::PullRequest => return None,
// Its plugin's heading names it instead.
Self::PullRequest | Self::Plugin(_) => return None,
})
}
}
12 changes: 12 additions & 0 deletions crates/sheprd-gpui/src/menu/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
mod dispatch;
mod kept;
mod kept_worktrees;
mod plugins;
pub(super) mod popover;
mod render;
mod requests;
Expand Down Expand Up @@ -50,6 +51,9 @@ pub(crate) struct WorkspaceTarget {
/// Whether the user muted the workspace's notifications when the menu
/// opened, which picks what the toggle in its header does.
pub(super) muted: bool,
/// The plugin actions listed below the menu's own rows; none for a
/// workspace the app keeps, as Herdr 2 has no plugins.
pub(super) plugins: Vec<crate::plugin_actions::Row>,
}

/// How a worktree request tells the daemon which repository it is for.
Expand Down Expand Up @@ -95,6 +99,7 @@ impl WorkspaceTarget {
source: Source::of(workspace),
keeper: sheprd_session::Keeper::Herdr1,
muted: false,
plugins: Vec::new(),
}
}

Expand Down Expand Up @@ -520,6 +525,8 @@ impl SheprdWindow {
});
self.menu.anchor = anchor;
self.menu.page = Some(Page::Workspace);
self.sync_workspace_plugin_rows();
self.refresh_plugin_actions(window, cx);
self.refresh_workspace_pr();
self.discard_composition(cx);
window.focus(&self.menu.focus, cx);
Expand Down Expand Up @@ -901,6 +908,10 @@ impl SheprdWindow {
.into_iter()
.map(|(action, _)| action)
.collect();
// Plugin rows follow the popover's own, before its pull request.
if let Some(target) = &self.menu.target {
actions.extend((0..target.plugins.len()).map(WorkspaceMenuAction::Plugin));
}
if self.pr_profile().is_some() && self.menu.pr.value.is_some() {
actions.push(WorkspaceMenuAction::PullRequest);
}
Expand Down Expand Up @@ -939,6 +950,7 @@ impl SheprdWindow {
WorkspaceMenuAction::Checkpoints => self.open_checkpoints(window, cx),
WorkspaceMenuAction::FanOut => self.open_fan_out(window, cx),
WorkspaceMenuAction::Script(kind) => self.run_workspace_script(kind, window, cx),
WorkspaceMenuAction::Plugin(index) => self.activate_workspace_plugin(index, window, cx),
#[cfg(feature = "cloud")]
WorkspaceMenuAction::SandboxImages => self.build_workspace_sandbox_images(window, cx),
WorkspaceMenuAction::Orchestrator => {
Expand Down
1 change: 1 addition & 0 deletions crates/sheprd-gpui/src/menu/workspace/kept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl WorkspaceTarget {
},
keeper: Keeper::App,
muted: false,
plugins: Vec::new(),
}
}
}
Expand Down
Loading
Loading