Improve keymap json schema (#23044)

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.
This commit is contained in:
Michael Sloan 2025-01-12 19:34:35 -07:00 committed by GitHub
parent 4c50201036
commit 6aba3950d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 506 additions and 283 deletions

View file

@ -1,10 +1,10 @@
use std::{iter::Peekable, str::Chars, time::Duration};
use editor::Editor;
use gpui::{actions, impl_actions, ViewContext};
use gpui::{actions, impl_actions, impl_internal_actions, ViewContext};
use language::Point;
use schemars::JsonSchema;
use search::{buffer_search, BufferSearchBar, SearchOptions};
use serde_derive::Deserialize;
use std::{iter::Peekable, str::Chars, time::Duration};
use util::serde::default_true;
use workspace::{notifications::NotifyResultExt, searchable::Direction};
@ -15,7 +15,7 @@ use crate::{
Vim,
};
#[derive(Clone, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq)]
#[serde(rename_all = "camelCase")]
pub(crate) struct MoveToNext {
#[serde(default = "default_true")]
@ -26,7 +26,7 @@ pub(crate) struct MoveToNext {
regex: bool,
}
#[derive(Clone, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq)]
#[serde(rename_all = "camelCase")]
pub(crate) struct MoveToPrev {
#[serde(default = "default_true")]
@ -37,7 +37,7 @@ pub(crate) struct MoveToPrev {
regex: bool,
}
#[derive(Clone, Deserialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq)]
pub(crate) struct Search {
#[serde(default)]
backwards: bool,
@ -45,19 +45,19 @@ pub(crate) struct Search {
regex: bool,
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq)]
pub struct FindCommand {
pub query: String,
pub backwards: bool,
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[derive(Clone, Debug, PartialEq)]
pub struct ReplaceCommand {
pub(crate) range: CommandRange,
pub(crate) replacement: Replacement,
}
#[derive(Debug, Default, PartialEq, Deserialize, Clone)]
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct Replacement {
search: String,
replacement: String,
@ -66,10 +66,8 @@ pub(crate) struct Replacement {
}
actions!(vim, [SearchSubmit, MoveToNextMatch, MoveToPrevMatch]);
impl_actions!(
vim,
[FindCommand, ReplaceCommand, Search, MoveToPrev, MoveToNext]
);
impl_actions!(vim, [FindCommand, Search, MoveToPrev, MoveToNext]);
impl_internal_actions!(vim, [ReplaceCommand]);
pub(crate) fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
Vim::action(editor, cx, Vim::move_to_next);