docs: Validate JSON snippets (settings, keymap, tasks, etc) (#40043)
Closes #ISSUE Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -360,11 +360,10 @@ impl KeymapFile {
|
||||
}
|
||||
}
|
||||
|
||||
fn build_keymap_action(
|
||||
pub fn parse_action(
|
||||
action: &KeymapAction,
|
||||
cx: &App,
|
||||
) -> std::result::Result<(Box<dyn Action>, Option<String>), String> {
|
||||
let (build_result, action_input_string) = match &action.0 {
|
||||
) -> Result<Option<(&String, Option<&Value>)>, String> {
|
||||
let name_and_input = match &action.0 {
|
||||
Value::Array(items) => {
|
||||
if items.len() != 2 {
|
||||
return Err(format!(
|
||||
@@ -380,22 +379,10 @@ impl KeymapFile {
|
||||
MarkdownInlineCode(&action.0.to_string())
|
||||
));
|
||||
};
|
||||
let action_input = items[1].clone();
|
||||
if name.as_str() == ActionSequence::name_for_type() {
|
||||
(ActionSequence::build_sequence(action_input, cx), None)
|
||||
} else {
|
||||
let action_input_string = action_input.to_string();
|
||||
(
|
||||
cx.build_action(name, Some(action_input)),
|
||||
Some(action_input_string),
|
||||
)
|
||||
}
|
||||
Some((name, Some(&items[1])))
|
||||
}
|
||||
Value::String(name) if name.as_str() == ActionSequence::name_for_type() => {
|
||||
(Err(ActionSequence::expected_array_error()), None)
|
||||
}
|
||||
Value::String(name) => (cx.build_action(name, None), None),
|
||||
Value::Null => (Ok(NoAction.boxed_clone()), None),
|
||||
Value::String(name) => Some((name, None)),
|
||||
Value::Null => None,
|
||||
_ => {
|
||||
return Err(format!(
|
||||
"expected two-element array of `[name, input]`. \
|
||||
@@ -404,6 +391,33 @@ impl KeymapFile {
|
||||
));
|
||||
}
|
||||
};
|
||||
Ok(name_and_input)
|
||||
}
|
||||
|
||||
fn build_keymap_action(
|
||||
action: &KeymapAction,
|
||||
cx: &App,
|
||||
) -> std::result::Result<(Box<dyn Action>, Option<String>), String> {
|
||||
let (build_result, action_input_string) = match Self::parse_action(action)? {
|
||||
Some((name, action_input)) if name.as_str() == ActionSequence::name_for_type() => {
|
||||
match action_input {
|
||||
Some(action_input) => (
|
||||
ActionSequence::build_sequence(action_input.clone(), cx),
|
||||
None,
|
||||
),
|
||||
None => (Err(ActionSequence::expected_array_error()), None),
|
||||
}
|
||||
}
|
||||
Some((name, Some(action_input))) => {
|
||||
let action_input_string = action_input.to_string();
|
||||
(
|
||||
cx.build_action(name, Some(action_input.clone())),
|
||||
Some(action_input_string),
|
||||
)
|
||||
}
|
||||
Some((name, None)) => (cx.build_action(name, None), None),
|
||||
None => (Ok(NoAction.boxed_clone()), None),
|
||||
};
|
||||
|
||||
let action = match build_result {
|
||||
Ok(action) => action,
|
||||
|
||||
Reference in New Issue
Block a user