settings: Auto-update JSON schemas for settings when extensions are un/installed (#26633)
Because of #26562, it is now possible to subscribe to extension update events within the LSP store, where we can then update the Schemas sent to the JSON LSP resulting in dynamic updates to the auto-complete suggestions and diagnostics in settings. Notably, this means newly installed languages and (icon) themes will auto-complete correctly as soon as the extension is installed. Closes #15436 Release Notes: - Fixed an issue where autocomplete suggestions and diagnostics for languages and (icon) themes in settings would not update when the extension with which they were added was installed or uninstalled
This commit is contained in:
parent
79874872cb
commit
25f407baab
10 changed files with 180 additions and 32 deletions
|
@ -3017,6 +3017,15 @@ impl LspStore {
|
|||
.detach();
|
||||
cx.subscribe(&toolchain_store, Self::on_toolchain_store_event)
|
||||
.detach();
|
||||
if let Some(extension_events) = extension::ExtensionEvents::try_global(cx).as_ref() {
|
||||
cx.subscribe(
|
||||
extension_events,
|
||||
Self::reload_zed_json_schemas_on_extensions_changed,
|
||||
)
|
||||
.detach();
|
||||
} else {
|
||||
log::info!("No extension events global found. Skipping JSON schema auto-reload setup");
|
||||
}
|
||||
cx.observe_global::<SettingsStore>(Self::on_settings_changed)
|
||||
.detach();
|
||||
|
||||
|
@ -3277,6 +3286,109 @@ impl LspStore {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reload_zed_json_schemas_on_extensions_changed(
|
||||
&mut self,
|
||||
_: Entity<extension::ExtensionEvents>,
|
||||
evt: &extension::Event,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
#[expect(
|
||||
irrefutable_let_patterns,
|
||||
reason = "Make sure to handle new event types in extension properly"
|
||||
)]
|
||||
let extension::Event::ExtensionsInstalledChanged = evt
|
||||
else {
|
||||
return;
|
||||
};
|
||||
if self.as_local().is_none() {
|
||||
return;
|
||||
}
|
||||
cx.spawn(async move |this, mut cx| {
|
||||
let weak_ref = this.clone();
|
||||
let servers = this
|
||||
.update(&mut cx, |this, cx| {
|
||||
let local = this.as_local()?;
|
||||
|
||||
let mut servers = Vec::new();
|
||||
for ((worktree_id, _), server_ids) in &local.language_server_ids {
|
||||
for server_id in server_ids {
|
||||
let Some(states) = local.language_servers.get(server_id) else {
|
||||
continue;
|
||||
};
|
||||
let (json_adapter, json_server) = match states {
|
||||
LanguageServerState::Running {
|
||||
adapter, server, ..
|
||||
} if adapter.adapter.is_primary_zed_json_schema_adapter() => {
|
||||
(adapter.adapter.clone(), server.clone())
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
let Some(worktree) = this
|
||||
.worktree_store
|
||||
.read(cx)
|
||||
.worktree_for_id(*worktree_id, cx)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let json_delegate: Arc<dyn LspAdapterDelegate> =
|
||||
LocalLspAdapterDelegate::new(
|
||||
local.languages.clone(),
|
||||
&local.environment,
|
||||
weak_ref.clone(),
|
||||
&worktree,
|
||||
local.http_client.clone(),
|
||||
local.fs.clone(),
|
||||
cx,
|
||||
);
|
||||
|
||||
servers.push((json_adapter, json_server, json_delegate));
|
||||
}
|
||||
}
|
||||
return Some(servers);
|
||||
})
|
||||
.ok()
|
||||
.flatten();
|
||||
|
||||
let Some(servers) = servers else {
|
||||
return;
|
||||
};
|
||||
|
||||
let Ok(Some((fs, toolchain_store))) = this.read_with(&cx, |this, cx| {
|
||||
let local = this.as_local()?;
|
||||
let toolchain_store = this.toolchain_store(cx);
|
||||
return Some((local.fs.clone(), toolchain_store));
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
for (adapter, server, delegate) in servers {
|
||||
adapter.clear_zed_json_schema_cache().await;
|
||||
|
||||
let Some(json_workspace_config) = adapter
|
||||
.workspace_configuration(
|
||||
fs.as_ref(),
|
||||
&delegate,
|
||||
toolchain_store.clone(),
|
||||
&mut cx,
|
||||
)
|
||||
.await
|
||||
.context("generate new workspace configuration for JSON language server while trying to refresh JSON Schemas")
|
||||
.ok()
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
server
|
||||
.notify::<lsp::notification::DidChangeConfiguration>(
|
||||
&lsp::DidChangeConfigurationParams {
|
||||
settings: json_workspace_config,
|
||||
},
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
pub(crate) fn register_buffer_with_language_servers(
|
||||
&mut self,
|
||||
buffer: &Entity<Buffer>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue