Show settings file errors on startup (#23817)
Required using a global `LazyLock<Mutex<AppNotifications>>` instead of a context global because settings errors first occur before initialization of the notifications global. Release Notes: - Errors in settings file are now reported in UI on startup.
This commit is contained in:
parent
06936c69f6
commit
dbdf140ca1
5 changed files with 74 additions and 89 deletions
|
@ -18,7 +18,7 @@ use extension::ExtensionHostProxy;
|
|||
use fs::{Fs, RealFs};
|
||||
use futures::{future, StreamExt};
|
||||
use git::GitHostingProviderRegistry;
|
||||
use gpui::{Action, App, AppContext as _, Application, AsyncApp, DismissEvent, UpdateGlobal as _};
|
||||
use gpui::{App, AppContext as _, Application, AsyncApp, UpdateGlobal as _};
|
||||
|
||||
use http_client::{read_proxy_from_env, Uri};
|
||||
use language::LanguageRegistry;
|
||||
|
@ -33,9 +33,7 @@ use project::project_settings::ProjectSettings;
|
|||
use recent_projects::{open_ssh_project, SshSettings};
|
||||
use release_channel::{AppCommitSha, AppVersion, ReleaseChannel};
|
||||
use session::{AppSession, Session};
|
||||
use settings::{
|
||||
handle_settings_file_changes, watch_config_file, InvalidSettingsError, Settings, SettingsStore,
|
||||
};
|
||||
use settings::{handle_settings_file_changes, watch_config_file, Settings, SettingsStore};
|
||||
use simplelog::ConfigBuilder;
|
||||
use std::{
|
||||
env,
|
||||
|
@ -50,18 +48,13 @@ use time::UtcOffset;
|
|||
use util::{maybe, ResultExt, TryFutureExt};
|
||||
use uuid::Uuid;
|
||||
use welcome::{show_welcome_view, BaseKeymap, FIRST_OPEN};
|
||||
use workspace::{
|
||||
notifications::{simple_message_notification::MessageNotification, NotificationId},
|
||||
AppState, SerializedWorkspaceLocation, WorkspaceSettings, WorkspaceStore,
|
||||
};
|
||||
use workspace::{AppState, SerializedWorkspaceLocation, WorkspaceSettings, WorkspaceStore};
|
||||
use zed::{
|
||||
app_menus, build_window_options, derive_paths_with_position, handle_cli_connection,
|
||||
handle_keymap_file_changes, initialize_workspace, open_paths_with_positions, OpenListener,
|
||||
OpenRequest,
|
||||
handle_keymap_file_changes, handle_settings_changed, initialize_workspace,
|
||||
inline_completion_registry, open_paths_with_positions, OpenListener, OpenRequest,
|
||||
};
|
||||
|
||||
use crate::zed::inline_completion_registry;
|
||||
|
||||
#[cfg(unix)]
|
||||
use util::{load_login_shell_environment, load_shell_from_passwd};
|
||||
|
||||
|
@ -614,44 +607,6 @@ fn main() {
|
|||
});
|
||||
}
|
||||
|
||||
fn handle_settings_changed(error: Option<anyhow::Error>, cx: &mut App) {
|
||||
struct SettingsParseErrorNotification;
|
||||
let id = NotificationId::unique::<SettingsParseErrorNotification>();
|
||||
|
||||
for workspace in workspace::local_workspace_windows(cx) {
|
||||
workspace
|
||||
.update(cx, |workspace, _, cx| {
|
||||
match error.as_ref() {
|
||||
Some(error) => {
|
||||
if let Some(InvalidSettingsError::LocalSettings { .. }) =
|
||||
error.downcast_ref::<InvalidSettingsError>()
|
||||
{
|
||||
// Local settings will be displayed by the projects
|
||||
} else {
|
||||
workspace.show_notification(id.clone(), cx, |cx| {
|
||||
cx.new(|_cx| {
|
||||
MessageNotification::new(format!(
|
||||
"Invalid user settings file\n{error}"
|
||||
))
|
||||
.with_click_message("Open settings file")
|
||||
.on_click(|window, cx| {
|
||||
window.dispatch_action(
|
||||
zed_actions::OpenSettings.boxed_clone(),
|
||||
cx,
|
||||
);
|
||||
cx.emit(DismissEvent);
|
||||
})
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
None => workspace.dismiss_notification(&id, cx),
|
||||
}
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut App) {
|
||||
if let Some(connection) = request.cli_connection {
|
||||
let app_state = app_state.clone();
|
||||
|
|
|
@ -39,12 +39,12 @@ use release_channel::{AppCommitSha, ReleaseChannel};
|
|||
use rope::Rope;
|
||||
use search::project_search::ProjectSearchBar;
|
||||
use settings::{
|
||||
initial_project_settings_content, initial_tasks_content, update_settings_file, KeymapFile,
|
||||
KeymapFileLoadResult, Settings, SettingsStore, DEFAULT_KEYMAP_PATH, VIM_KEYMAP_PATH,
|
||||
initial_project_settings_content, initial_tasks_content, update_settings_file,
|
||||
InvalidSettingsError, KeymapFile, KeymapFileLoadResult, Settings, SettingsStore,
|
||||
DEFAULT_KEYMAP_PATH, VIM_KEYMAP_PATH,
|
||||
};
|
||||
use std::any::TypeId;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::{borrow::Cow, ops::Deref, path::Path, sync::Arc};
|
||||
use terminal_view::terminal_panel::{self, TerminalPanel};
|
||||
use theme::{ActiveTheme, ThemeSettings};
|
||||
|
@ -1220,7 +1220,7 @@ fn show_keymap_file_load_error(
|
|||
});
|
||||
|
||||
cx.spawn(move |cx| async move {
|
||||
let parsed_markdown = Rc::new(parsed_markdown.await);
|
||||
let parsed_markdown = Arc::new(parsed_markdown.await);
|
||||
cx.update(|cx| {
|
||||
show_app_notification(notification_id, cx, move |cx| {
|
||||
let workspace_handle = cx.entity().downgrade();
|
||||
|
@ -1274,6 +1274,33 @@ pub fn load_default_keymap(cx: &mut App) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn handle_settings_changed(error: Option<anyhow::Error>, cx: &mut App) {
|
||||
struct SettingsParseErrorNotification;
|
||||
let id = NotificationId::unique::<SettingsParseErrorNotification>();
|
||||
|
||||
match error {
|
||||
Some(error) => {
|
||||
if let Some(InvalidSettingsError::LocalSettings { .. }) =
|
||||
error.downcast_ref::<InvalidSettingsError>()
|
||||
{
|
||||
// Local settings errors are displayed by the projects
|
||||
return;
|
||||
}
|
||||
show_app_notification(id, cx, move |cx| {
|
||||
cx.new(|_cx| {
|
||||
MessageNotification::new(format!("Invalid user settings file\n{error}"))
|
||||
.with_click_message("Open settings file")
|
||||
.on_click(|window, cx| {
|
||||
window.dispatch_action(zed_actions::OpenSettings.boxed_clone(), cx);
|
||||
cx.emit(DismissEvent);
|
||||
})
|
||||
})
|
||||
});
|
||||
}
|
||||
None => dismiss_app_notification(&id, cx),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_new_ssh_project_from_project(
|
||||
workspace: &mut Workspace,
|
||||
paths: Vec<PathBuf>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue