settings: Show error notification when settings are invalid (#15905)

https://github.com/user-attachments/assets/07627142-e730-4446-a50b-7ef46f8e661c

We want to improve the design in the future, but it fixes a long
standing paper cut for now.

Release Notes:

- Added a popup that is displayed when the settings are invalid

---------

Co-authored-by: Thorsten <thorsten@zed.dev>
This commit is contained in:
Bennet Bo Fenner 2024-08-07 15:54:44 +02:00 committed by GitHub
parent 94028290cc
commit efbf7ada28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 42 additions and 9 deletions

View file

@ -19,7 +19,8 @@ use fs::{Fs, RealFs};
use futures::{future, StreamExt};
use git::GitHostingProviderRegistry;
use gpui::{
App, AppContext, AsyncAppContext, Context, Global, Task, UpdateGlobal as _, VisualContext,
Action, App, AppContext, AsyncAppContext, Context, DismissEvent, Global, Task,
UpdateGlobal as _, VisualContext,
};
use image_viewer;
use language::LanguageRegistry;
@ -46,7 +47,10 @@ use theme::{ActiveTheme, SystemAppearance, ThemeRegistry, ThemeSettings};
use util::{maybe, parse_env_output, ResultExt, TryFutureExt};
use uuid::Uuid;
use welcome::{show_welcome_view, BaseKeymap, FIRST_OPEN};
use workspace::{AppState, WorkspaceSettings, WorkspaceStore};
use workspace::{
notifications::{simple_message_notification::MessageNotification, NotificationId},
AppState, WorkspaceSettings, WorkspaceStore,
};
use zed::{
app_menus, build_window_options, handle_cli_connection, handle_keymap_file_changes,
initialize_workspace, open_paths_with_positions, OpenListener, OpenRequest,
@ -425,7 +429,7 @@ fn main() {
OpenListener::set_global(cx, open_listener.clone());
settings::init(cx);
handle_settings_file_changes(user_settings_file_rx, cx);
handle_settings_file_changes(user_settings_file_rx, cx, handle_settings_changed);
handle_keymap_file_changes(user_keymap_file_rx, cx);
client::init_settings(cx);
@ -539,6 +543,31 @@ fn main() {
});
}
fn handle_settings_changed(result: Result<()>, cx: &mut AppContext) {
struct SettingsParseErrorNotification;
let id = NotificationId::unique::<SettingsParseErrorNotification>();
for workspace in workspace::local_workspace_windows(cx) {
workspace
.update(cx, |workspace, cx| match &result {
Ok(()) => workspace.dismiss_notification(&id, cx),
Err(error) => {
workspace.show_notification(id.clone(), cx, |cx| {
cx.new_view(|_| {
MessageNotification::new(format!("Invalid settings file\n{error}"))
.with_click_message("Open settings file")
.on_click(|cx| {
cx.dispatch_action(zed_actions::OpenSettings.boxed_clone());
cx.emit(DismissEvent);
})
})
});
}
})
.log_err();
}
}
fn handle_open_request(
request: OpenRequest,
app_state: Arc<AppState>,