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,6 +1,3 @@
use std::borrow::BorrowMut;
use std::{fmt::Display, ops::Range, sync::Arc};
use crate::command::command_interceptor;
use crate::normal::repeat::Replayer;
use crate::surrounds::SurroundsType;
@ -13,12 +10,15 @@ use gpui::{
Action, AppContext, BorrowAppContext, ClipboardEntry, ClipboardItem, Global, View, WeakView,
};
use language::Point;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsStore};
use std::borrow::BorrowMut;
use std::{fmt::Display, ops::Range, sync::Arc};
use ui::{SharedString, ViewContext};
use workspace::searchable::Direction;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, JsonSchema, Serialize)]
pub enum Mode {
Normal,
Insert,
@ -59,22 +59,39 @@ impl Default for Mode {
}
}
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, JsonSchema)]
pub enum Operator {
Change,
Delete,
Yank,
Replace,
Object { around: bool },
FindForward { before: bool },
FindBackward { after: bool },
Sneak { first_char: Option<char> },
SneakBackward { first_char: Option<char> },
AddSurrounds { target: Option<SurroundsType> },
ChangeSurrounds { target: Option<Object> },
Object {
around: bool,
},
FindForward {
before: bool,
},
FindBackward {
after: bool,
},
Sneak {
first_char: Option<char>,
},
SneakBackward {
first_char: Option<char>,
},
AddSurrounds {
#[serde(skip)]
target: Option<SurroundsType>,
},
ChangeSurrounds {
target: Option<Object>,
},
DeleteSurrounds,
Mark,
Jump { line: bool },
Jump {
line: bool,
},
Indent,
Outdent,
AutoIndent,
@ -82,8 +99,12 @@ pub enum Operator {
Lowercase,
Uppercase,
OppositeCase,
Digraph { first_char: Option<char> },
Literal { prefix: Option<String> },
Digraph {
first_char: Option<char>,
},
Literal {
prefix: Option<String>,
},
Register,
RecordRegister,
ReplayRegister,