gpui: Store action documentation (#33809)

Closes #ISSUE

Adds a new `documentation` method to actions, that is extracted from doc
comments when using the `actions!` or derive macros.

Additionally, this PR adds doc comments to as many action definitions in
Zed as possible.

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Ben Kunkle 2025-07-02 20:14:33 -05:00 committed by GitHub
parent def8bab5a8
commit 6cd4dbdea1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
96 changed files with 1467 additions and 78 deletions

View file

@ -9,6 +9,7 @@ use crate::{Vim, state::Mode};
const BOOLEAN_PAIRS: &[(&str, &str)] = &[("true", "false"), ("yes", "no"), ("on", "off")];
/// Increments the number under the cursor or toggles boolean values.
#[derive(Clone, Deserialize, JsonSchema, PartialEq, Action)]
#[action(namespace = vim)]
#[serde(deny_unknown_fields)]
@ -17,6 +18,7 @@ struct Increment {
step: bool,
}
/// Decrements the number under the cursor or toggles boolean values.
#[derive(Clone, Deserialize, JsonSchema, PartialEq, Action)]
#[action(namespace = vim)]
#[serde(deny_unknown_fields)]

View file

@ -14,6 +14,7 @@ use crate::{
state::{Mode, Register},
};
/// Pastes text from the specified register at the cursor position.
#[derive(Clone, Deserialize, JsonSchema, PartialEq, Action)]
#[action(namespace = vim)]
#[serde(deny_unknown_fields)]

View file

@ -11,7 +11,19 @@ use editor::Editor;
use gpui::{Action, App, Context, Window, actions};
use workspace::Workspace;
actions!(vim, [Repeat, EndRepeat, ToggleRecord, ReplayLastRecording]);
actions!(
vim,
[
/// Repeats the last change.
Repeat,
/// Ends the repeat recording.
EndRepeat,
/// Toggles macro recording.
ToggleRecord,
/// Replays the last recorded macro.
ReplayLastRecording
]
);
fn should_replay(action: &dyn Action) -> bool {
// skip so that we don't leave the character palette open

View file

@ -11,13 +11,21 @@ use settings::Settings;
actions!(
vim,
[
/// Scrolls up by one line.
LineUp,
/// Scrolls down by one line.
LineDown,
/// Scrolls right by one column.
ColumnRight,
/// Scrolls left by one column.
ColumnLeft,
/// Scrolls up by half a page.
ScrollUp,
/// Scrolls down by half a page.
ScrollDown,
/// Scrolls up by one page.
PageUp,
/// Scrolls down by one page.
PageDown
]
);

View file

@ -16,6 +16,7 @@ use crate::{
state::{Mode, SearchState},
};
/// Moves to the next search match.
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Action)]
#[action(namespace = vim)]
#[serde(deny_unknown_fields)]
@ -28,6 +29,7 @@ pub(crate) struct MoveToNext {
regex: bool,
}
/// Moves to the previous search match.
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Action)]
#[action(namespace = vim)]
#[serde(deny_unknown_fields)]
@ -40,6 +42,7 @@ pub(crate) struct MoveToPrevious {
regex: bool,
}
/// Initiates a search operation with the specified parameters.
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Action)]
#[action(namespace = vim)]
#[serde(deny_unknown_fields)]
@ -50,6 +53,7 @@ pub(crate) struct Search {
regex: bool,
}
/// Executes a find command to search for patterns in the buffer.
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Action)]
#[action(namespace = vim)]
#[serde(deny_unknown_fields)]
@ -58,6 +62,7 @@ pub struct FindCommand {
pub backwards: bool,
}
/// Executes a search and replace command within the specified range.
#[derive(Clone, Debug, PartialEq, Action)]
#[action(namespace = vim, no_json, no_register)]
pub struct ReplaceCommand {
@ -73,7 +78,17 @@ pub(crate) struct Replacement {
is_case_sensitive: bool,
}
actions!(vim, [SearchSubmit, MoveToNextMatch, MoveToPreviousMatch]);
actions!(
vim,
[
/// Submits the current search query.
SearchSubmit,
/// Moves to the next search match.
MoveToNextMatch,
/// Moves to the previous search match.
MoveToPreviousMatch
]
);
pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
Vim::action(editor, cx, Vim::move_to_next);

View file

@ -7,7 +7,15 @@ use crate::{
motion::{Motion, MotionKind},
};
actions!(vim, [Substitute, SubstituteLine]);
actions!(
vim,
[
/// Substitutes characters in the current selection.
Substitute,
/// Substitutes the entire line.
SubstituteLine
]
);
pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
Vim::action(editor, cx, |vim, _: &Substitute, window, cx| {