keymap: Show error notification when keymap is invalid (#15977)

This adds an error notification that pops up when the user has an
invalid keymap, similar to what we added for settings in #15905.

Release Notes:

- Added a popup that is displayed when the keymap is invalid
This commit is contained in:
Bennet Bo Fenner 2024-08-08 14:11:46 +02:00 committed by GitHub
parent 92496f33e7
commit 793cd88792
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 14 deletions

View file

@ -733,6 +733,7 @@ fn open_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
pub fn handle_keymap_file_changes(
mut user_keymap_file_rx: mpsc::UnboundedReceiver<String>,
cx: &mut AppContext,
keymap_changed: impl Fn(Option<anyhow::Error>, &mut AppContext) + 'static,
) {
BaseKeymap::register(cx);
VimModeSetting::register(cx);
@ -761,10 +762,14 @@ pub fn handle_keymap_file_changes(
_ = base_keymap_rx.next() => {}
user_keymap_content = user_keymap_file_rx.next() => {
if let Some(user_keymap_content) = user_keymap_content {
if let Some(keymap_content) = KeymapFile::parse(&user_keymap_content).log_err() {
user_keymap = keymap_content;
} else {
continue
match KeymapFile::parse(&user_keymap_content) {
Ok(keymap_content) => {
cx.update(|cx| keymap_changed(None, cx)).log_err();
user_keymap = keymap_content;
}
Err(error) => {
cx.update(|cx| keymap_changed(Some(error), cx)).log_err();
}
}
}
}
@ -3097,7 +3102,7 @@ mod tests {
PathBuf::from("/keymap.json"),
);
handle_settings_file_changes(settings_rx, cx, |_, _| {});
handle_keymap_file_changes(keymap_rx, cx);
handle_keymap_file_changes(keymap_rx, cx, |_, _| {});
});
workspace
.update(cx, |workspace, cx| {
@ -3237,7 +3242,7 @@ mod tests {
);
handle_settings_file_changes(settings_rx, cx, |_, _| {});
handle_keymap_file_changes(keymap_rx, cx);
handle_keymap_file_changes(keymap_rx, cx, |_, _| {});
});
cx.background_executor.run_until_parked();