settings: Show notification when user/project settings fail to parse (#18122)

Closes #16876

We only ever showed parsing errors, but not if something failed to
deserialize.

Basically, if you had a stray `,` somewhere, we'd show a notification
for user errors, but only squiggly lines if you had a `[]` instead of a
`{}`.

The squiggly lines would only show up when there were schema errors.

In the case of `formatter` settings, for example, if someone put in a
`{}` instead of `[]`, we'd never show anything.

With this change we always show a notification if parsing user or
project settings fails.

(Right now, the error message might still be bad, but that's a separate
change)


Release Notes:

- Added a notification to warn users if their user settings or
project-local settings failed to deserialize.

Demo:


https://github.com/user-attachments/assets/e5c48165-f2f7-4b5c-9c6d-6ea74f678683
This commit is contained in:
Thorsten Ball 2024-09-20 10:53:06 +02:00 committed by GitHub
parent 93730983dd
commit ace4d5185d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 172 additions and 50 deletions

View file

@ -34,7 +34,9 @@ use parking_lot::Mutex;
use recent_projects::open_ssh_project;
use release_channel::{AppCommitSha, AppVersion};
use session::{AppSession, Session};
use settings::{handle_settings_file_changes, watch_config_file, Settings, SettingsStore};
use settings::{
handle_settings_file_changes, watch_config_file, InvalidSettingsError, Settings, SettingsStore,
};
use simplelog::ConfigBuilder;
use smol::process::Command;
use std::{
@ -626,20 +628,28 @@ fn handle_settings_changed(error: Option<anyhow::Error>, cx: &mut AppContext) {
for workspace in workspace::local_workspace_windows(cx) {
workspace
.update(cx, |workspace, cx| match &error {
Some(error) => {
workspace.show_notification(id.clone(), cx, |cx| {
cx.new_view(|_| {
MessageNotification::new(format!("Invalid settings file\n{error}"))
.update(cx, |workspace, cx| {
match error
.as_ref()
.and_then(|error| error.downcast_ref::<InvalidSettingsError>())
{
Some(InvalidSettingsError::UserSettings { message }) => {
workspace.show_notification(id.clone(), cx, |cx| {
cx.new_view(|_| {
MessageNotification::new(format!(
"Invalid user settings file\n{message}"
))
.with_click_message("Open settings file")
.on_click(|cx| {
cx.dispatch_action(zed_actions::OpenSettings.boxed_clone());
cx.emit(DismissEvent);
})
})
});
})
});
}
None => workspace.dismiss_notification(&id, cx),
_ => {}
}
None => workspace.dismiss_notification(&id, cx),
})
.log_err();
}