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

@ -59,12 +59,14 @@ use node_runtime::NodeRuntime;
use parking_lot::{Mutex, RwLock};
use paths::{local_tasks_file_relative_path, local_vscode_tasks_file_relative_path};
pub use prettier_store::PrettierStore;
use project_settings::{ProjectSettings, SettingsObserver};
use project_settings::{ProjectSettings, SettingsObserver, SettingsObserverEvent};
use remote::SshSession;
use rpc::{proto::SSH_PROJECT_ID, AnyProtoClient, ErrorCode};
use search::{SearchInputKind, SearchQuery, SearchResult};
use search_history::SearchHistory;
use settings::{watch_config_file, Settings, SettingsLocation, SettingsStore};
use settings::{
watch_config_file, InvalidSettingsError, Settings, SettingsLocation, SettingsStore,
};
use smol::channel::Receiver;
use snippet::Snippet;
use snippet_provider::SnippetProvider;
@ -230,6 +232,7 @@ pub enum Event {
LanguageServerRemoved(LanguageServerId),
LanguageServerLog(LanguageServerId, LanguageServerLogType, String),
Notification(String),
LocalSettingsUpdated(Result<(), InvalidSettingsError>),
LanguageServerPrompt(LanguageServerPromptRequest),
LanguageNotFound(Model<Buffer>),
ActiveEntryChanged(Option<ProjectEntryId>),
@ -644,6 +647,8 @@ impl Project {
let settings_observer = cx.new_model(|cx| {
SettingsObserver::new_local(fs.clone(), worktree_store.clone(), cx)
});
cx.subscribe(&settings_observer, Self::on_settings_observer_event)
.detach();
let environment = ProjectEnvironment::new(&worktree_store, env, cx);
let lsp_store = cx.new_model(|cx| {
@ -729,6 +734,8 @@ impl Project {
let settings_observer = cx.new_model(|cx| {
SettingsObserver::new_ssh(ssh.clone().into(), worktree_store.clone(), cx)
});
cx.subscribe(&settings_observer, Self::on_settings_observer_event)
.detach();
let environment = ProjectEnvironment::new(&worktree_store, None, cx);
let lsp_store = cx.new_model(|cx| {
@ -913,6 +920,8 @@ impl Project {
cx.subscribe(&buffer_store, Self::on_buffer_store_event)
.detach();
cx.subscribe(&lsp_store, Self::on_lsp_store_event).detach();
cx.subscribe(&settings_observer, Self::on_settings_observer_event)
.detach();
let mut this = Self {
buffer_ordered_messages_tx: tx,
@ -2058,6 +2067,19 @@ impl Project {
}
}
fn on_settings_observer_event(
&mut self,
_: Model<SettingsObserver>,
event: &SettingsObserverEvent,
cx: &mut ModelContext<Self>,
) {
match event {
SettingsObserverEvent::LocalSettingsUpdated(error) => {
cx.emit(Event::LocalSettingsUpdated(error.clone()))
}
}
}
fn on_worktree_store_event(
&mut self,
_: Model<WorktreeStore>,