Load all key bindings that parse and use markdown in error notifications (#23113)

* Collects and reports all parse errors

* Shares parsed `KeyBindingContextPredicate` among the actions.

* Updates gpui keybinding and action parsing to return structured
errors.

* Renames "block" to "section" to match the docs, as types like
`KeymapSection` are shown in `json-language-server` hovers.

* Removes wrapping of `context` and `use_key_equivalents` fields so that
`json-language-server` auto-inserts `""` and `false` instead of `null`.

* Updates `add_to_cx` to take `&self`, so that the user keymap doesn't
get unnecessarily cloned.

In retrospect I wish I'd just switched to using TreeSitter to do the
parsing and provide proper diagnostics. This is tracked in #23333

Release Notes:

- Improved handling of errors within the user keymap file. Parse errors
within context, keystrokes, or actions no longer prevent loading the key
bindings that do parse.
This commit is contained in:
Michael Sloan 2025-01-18 15:27:08 -07:00 committed by GitHub
parent c929533e00
commit 711dc21eb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 552 additions and 196 deletions

View file

@ -15,7 +15,6 @@ use gpui::{
ParentElement, Render, Styled, Task, UpdateGlobal, View, ViewContext, VisualContext, WeakView,
};
use picker::{Picker, PickerDelegate};
use postage::{sink::Sink, stream::Stream};
use settings::Settings;
use ui::{h_flex, prelude::*, v_flex, HighlightedLabel, KeyBinding, ListItem, ListItemSpacing};
@ -635,7 +634,7 @@ mod tests {
workspace::init(app_state.clone(), cx);
init(cx);
Project::init_settings(cx);
KeymapFile::parse(
cx.bind_keys(KeymapFile::load_panic_on_failure(
r#"[
{
"bindings": {
@ -645,10 +644,8 @@ mod tests {
}
}
]"#,
)
.unwrap()
.add_to_cx(cx)
.unwrap();
cx,
));
app_state
})
}