Skip to content

Commit

Permalink
Improve keymap json schema (#23044)
Browse files Browse the repository at this point in the history
Also:

* Adds `impl_internal_actions!` for deriving the `Action` trait without
registering.

* Removes some deserializers that immediately fail in favor of
`#[serde(skip)]` on fields where they were used. This also omits them
from the schema.

Release Notes:

- Keymap settings file now has more JSON schema information to inform
`json-language-server` completions and info, particularly for actions
that take input.
  • Loading branch information
mgsloan authored Jan 13, 2025
1 parent 4c50201 commit 6aba395
Show file tree
Hide file tree
Showing 37 changed files with 499 additions and 276 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions crates/assistant/src/assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use context::*;
pub use context_store::*;
use feature_flags::FeatureFlagAppExt;
use fs::Fs;
use gpui::impl_actions;
use gpui::impl_internal_actions;
use gpui::{actions, AppContext, Global, SharedString, UpdateGlobal};
pub(crate) use inline_assistant::*;
use language_model::{
Expand Down Expand Up @@ -74,13 +74,13 @@ actions!(
]
);

#[derive(PartialEq, Clone, Deserialize)]
#[derive(PartialEq, Clone)]
pub enum InsertDraggedFiles {
ProjectPaths(Vec<PathBuf>),
ExternalFiles(Vec<PathBuf>),
}

impl_actions!(assistant, [InsertDraggedFiles]);
impl_internal_actions!(assistant, [InsertDraggedFiles]);

const DEFAULT_CONTEXT_LINES: usize = 50;

Expand Down
61 changes: 33 additions & 28 deletions crates/editor/src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,167 +1,172 @@
//! This module contains all actions supported by [`Editor`].
use super::*;
use gpui::{action_aliases, action_as};
use schemars::JsonSchema;
use util::serde::default_true;

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct SelectNext {
#[serde(default)]
pub replace_newest: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct SelectPrevious {
#[serde(default)]
pub replace_newest: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct MoveToBeginningOfLine {
#[serde(default = "default_true")]
pub stop_at_soft_wraps: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct SelectToBeginningOfLine {
#[serde(default)]
pub(super) stop_at_soft_wraps: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct MovePageUp {
#[serde(default)]
pub(super) center_cursor: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct MovePageDown {
#[serde(default)]
pub(super) center_cursor: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct MoveToEndOfLine {
#[serde(default = "default_true")]
pub stop_at_soft_wraps: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct SelectToEndOfLine {
#[serde(default)]
pub(super) stop_at_soft_wraps: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct ToggleCodeActions {
// Display row from which the action was deployed.
#[serde(default)]
#[serde(skip)]
pub deployed_from_indicator: Option<DisplayRow>,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct ConfirmCompletion {
#[serde(default)]
pub item_ix: Option<usize>,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct ComposeCompletion {
#[serde(default)]
pub item_ix: Option<usize>,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct ConfirmCodeAction {
#[serde(default)]
pub item_ix: Option<usize>,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct ToggleComments {
#[serde(default)]
pub advance_downwards: bool,
#[serde(default)]
pub ignore_indent: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct FoldAt {
#[serde(skip)]
pub buffer_row: MultiBufferRow,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct UnfoldAt {
#[serde(skip)]
pub buffer_row: MultiBufferRow,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct MoveUpByLines {
#[serde(default)]
pub(super) lines: u32,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct MoveDownByLines {
#[serde(default)]
pub(super) lines: u32,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct SelectUpByLines {
#[serde(default)]
pub(super) lines: u32,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct SelectDownByLines {
#[serde(default)]
pub(super) lines: u32,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct ExpandExcerpts {
#[serde(default)]
pub(super) lines: u32,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct ExpandExcerptsUp {
#[serde(default)]
pub(super) lines: u32,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct ExpandExcerptsDown {
#[serde(default)]
pub(super) lines: u32,
}
#[derive(PartialEq, Clone, Deserialize, Default)]

#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct ShowCompletions {
#[serde(default)]
pub(super) trigger: Option<String>,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct HandleInput(pub String);

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct DeleteToNextWordEnd {
#[serde(default)]
pub ignore_newlines: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct DeleteToPreviousWordStart {
#[serde(default)]
pub ignore_newlines: bool,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct FoldAtLevel {
pub level: u32,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
pub struct SpawnNearestTask {
#[serde(default)]
pub reveal: task::RevealStrategy,
Expand Down
Loading

0 comments on commit 6aba395

Please sign in to comment.