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,11 +1,3 @@
use std::{
iter::Peekable,
ops::{Deref, Range},
str::Chars,
sync::OnceLock,
time::Instant,
};
use anyhow::{anyhow, Result};
use command_palette_hooks::CommandInterceptResult;
use editor::{
@ -13,12 +5,22 @@ use editor::{
display_map::ToDisplayPoint,
Bias, Editor, ToPoint,
};
use gpui::{actions, impl_actions, Action, AppContext, Global, ViewContext, WindowContext};
use gpui::{
actions, impl_internal_actions, Action, AppContext, Global, ViewContext, WindowContext,
};
use language::Point;
use multi_buffer::MultiBufferRow;
use regex::Regex;
use schemars::JsonSchema;
use search::{BufferSearchBar, SearchOptions};
use serde::Deserialize;
use std::{
iter::Peekable,
ops::{Deref, Range},
str::Chars,
sync::OnceLock,
time::Instant,
};
use util::ResultExt;
use workspace::{notifications::NotifyResultExt, SaveIntent};
@ -33,24 +35,24 @@ use crate::{
Vim,
};
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[derive(Clone, Debug, PartialEq)]
pub struct GoToLine {
range: CommandRange,
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[derive(Clone, Debug, PartialEq)]
pub struct YankCommand {
range: CommandRange,
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[derive(Clone, Debug, PartialEq)]
pub struct WithRange {
restore_selection: bool,
range: CommandRange,
action: WrappedAction,
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[derive(Clone, Debug, PartialEq)]
pub struct WithCount {
count: u32,
action: WrappedAction,
@ -60,20 +62,11 @@ pub struct WithCount {
struct WrappedAction(Box<dyn Action>);
actions!(vim, [VisualCommand, CountCommand]);
impl_actions!(
impl_internal_actions!(
vim,
[GoToLine, YankCommand, WithRange, WithCount, OnMatchingLines]
);
impl<'de> Deserialize<'de> for WrappedAction {
fn deserialize<D>(_: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
Err(serde::de::Error::custom("Cannot deserialize WrappedAction"))
}
}
impl PartialEq for WrappedAction {
fn eq(&self, other: &Self) -> bool {
self.0.partial_eq(&*other.0)
@ -423,7 +416,7 @@ impl VimCommand {
}
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq)]
enum Position {
Line { row: u32, offset: i32 },
Mark { name: char, offset: i32 },
@ -467,7 +460,7 @@ impl Position {
}
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct CommandRange {
start: Position,
end: Option<Position>,
@ -877,7 +870,7 @@ fn generate_positions(string: &str, query: &str) -> Vec<usize> {
positions
}
#[derive(Debug, PartialEq, Deserialize, Clone)]
#[derive(Debug, PartialEq, Clone)]
pub(crate) struct OnMatchingLines {
range: CommandRange,
search: String,