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:
Ben Kunkle 2025-03-13 11:50:07 -05:00 committed by GitHub
parent 79874872cb
commit 25f407baab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 180 additions and 32 deletions

View file

@ -15,6 +15,7 @@ use settings::{KeymapFile, SettingsJsonSchemaParams, SettingsStore};
use smol::{
fs::{self},
io::BufReader,
lock::RwLock,
};
use std::{
any::Any,
@ -22,7 +23,7 @@ use std::{
ffi::OsString,
path::{Path, PathBuf},
str::FromStr,
sync::{Arc, OnceLock},
sync::Arc,
};
use task::{TaskTemplate, TaskTemplates, VariableName};
use util::{fs::remove_matching, maybe, merge_json_value_into, ResultExt};
@ -60,7 +61,7 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
pub struct JsonLspAdapter {
node: NodeRuntime,
languages: Arc<LanguageRegistry>,
workspace_config: OnceLock<Value>,
workspace_config: RwLock<Option<Value>>,
}
impl JsonLspAdapter {
@ -141,6 +142,20 @@ impl JsonLspAdapter {
}
})
}
async fn get_or_init_workspace_config(&self, cx: &mut AsyncApp) -> Result<Value> {
{
let reader = self.workspace_config.read().await;
if let Some(config) = reader.as_ref() {
return Ok(config.clone());
}
}
let mut writer = self.workspace_config.write().await;
let config =
cx.update(|cx| Self::get_workspace_config(self.languages.language_names(), cx))?;
writer.replace(config.clone());
return Ok(config);
}
}
#[async_trait(?Send)]
@ -251,11 +266,7 @@ impl LspAdapter for JsonLspAdapter {
_: Arc<dyn LanguageToolchainStore>,
cx: &mut AsyncApp,
) -> Result<Value> {
let mut config = cx.update(|cx| {
self.workspace_config
.get_or_init(|| Self::get_workspace_config(self.languages.language_names(), cx))
.clone()
})?;
let mut config = self.get_or_init_workspace_config(cx).await?;
let project_options = cx.update(|cx| {
language_server_settings(delegate.as_ref(), &self.name(), cx)
@ -277,6 +288,14 @@ impl LspAdapter for JsonLspAdapter {
.into_iter()
.collect()
}
fn is_primary_zed_json_schema_adapter(&self) -> bool {
true
}
async fn clear_zed_json_schema_cache(&self) {
self.workspace_config.write().await.take();
}
}
async fn get_cached_server_binary(