schema for agent mode

This commit is contained in:
Smit Barmase 2025-08-22 17:21:48 +05:30
parent d3e1730b72
commit 96523f0d77
No known key found for this signature in database
5 changed files with 57 additions and 53 deletions

1
Cargo.lock generated
View file

@ -18000,6 +18000,7 @@ dependencies = [
"gpui", "gpui",
"schemars", "schemars",
"serde", "serde",
"serde_json",
"settings", "settings",
"workspace-hack", "workspace-hack",
] ]

View file

@ -19,6 +19,7 @@ gpui.workspace = true
language_model.workspace = true language_model.workspace = true
schemars.workspace = true schemars.workspace = true
serde.workspace = true serde.workspace = true
serde_json.workspace = true
settings.workspace = true settings.workspace = true
workspace-hack.workspace = true workspace-hack.workspace = true
vim_mode_setting.workspace = true vim_mode_setting.workspace = true

View file

@ -90,23 +90,19 @@ impl JsonSchema for AgentEditorMode {
"AgentEditorMode".into() "AgentEditorMode".into()
} }
fn json_schema(schema_gen: &mut schemars::SchemaGenerator) -> schemars::Schema { fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
let editor_mode_schema = EditorMode::json_schema(schema_gen); use vim_mode_setting::EditorMode;
// TODO: This schema is incorrect. Need to extend editor_mode_schema with `inherit` let mut options = vec![serde_json::json!({
let result = json_schema!({ "const": "inherit",
"oneOf": [ "description": "Inherit editor mode from global settings"
{ })];
"const": "inherit", options.extend(EditorMode::get_schema_options());
"description": "Inherit editor mode from global settings"
}, json_schema!({
editor_mode_schema "oneOf": options,
],
"description": "Agent editor mode - either inherit from global settings or override with a specific mode" "description": "Agent editor mode - either inherit from global settings or override with a specific mode"
}); })
dbg!(&result);
result
} }
} }

View file

@ -18,3 +18,4 @@ schemars.workspace = true
settings.workspace = true settings.workspace = true
workspace-hack.workspace = true workspace-hack.workspace = true
serde.workspace = true serde.workspace = true
serde_json.workspace = true

View file

@ -38,45 +38,9 @@ impl JsonSchema for EditorMode {
} }
fn json_schema(_gen: &mut schemars::SchemaGenerator) -> Schema { fn json_schema(_gen: &mut schemars::SchemaGenerator) -> Schema {
let options = Self::get_schema_options();
json_schema!({ json_schema!({
"oneOf": [ "oneOf": options,
{
"const": "default",
"description": "Standard editing mode"
},
{
"const": "vim",
"description": "Vim normal mode"
},
{
"const": "vim_normal",
"description": "Vim normal mode"
},
{
"const": "vim_insert",
"description": "Vim insert mode"
},
{
"const": "vim_replace",
"description": "Vim replace mode"
},
{
"const": "vim_visual",
"description": "Vim visual mode"
},
{
"const": "vim_visual_line",
"description": "Vim visual line mode"
},
{
"const": "vim_visual_block",
"description": "Vim visual block mode"
},
{
"const": "helix_experimental",
"description": "Helix mode (experimental)"
}
],
"description": "Editor mode" "description": "Editor mode"
}) })
} }
@ -192,4 +156,45 @@ impl EditorMode {
pub fn vim() -> EditorMode { pub fn vim() -> EditorMode {
EditorMode::Vim(ModalMode::default()) EditorMode::Vim(ModalMode::default())
} }
pub fn get_schema_options() -> Vec<serde_json::Value> {
vec![
serde_json::json!({
"const": "default",
"description": "Standard editing mode"
}),
serde_json::json!({
"const": "vim",
"description": "Vim normal mode"
}),
serde_json::json!({
"const": "vim_normal",
"description": "Vim normal mode"
}),
serde_json::json!({
"const": "vim_insert",
"description": "Vim insert mode"
}),
serde_json::json!({
"const": "vim_replace",
"description": "Vim replace mode"
}),
serde_json::json!({
"const": "vim_visual",
"description": "Vim visual mode"
}),
serde_json::json!({
"const": "vim_visual_line",
"description": "Vim visual line mode"
}),
serde_json::json!({
"const": "vim_visual_block",
"description": "Vim visual block mode"
}),
serde_json::json!({
"const": "helix_experimental",
"description": "Helix mode (experimental)"
}),
]
}
} }