@@ -2714,13 +2714,12 @@ impl Project {
})?;
for (adapter, server) in servers {
- let workspace_config =
+ let settings =
cx.update(|cx| adapter.workspace_configuration(server.root_path(), cx))?;
+
server
.notify::<lsp::notification::DidChangeConfiguration>(
- lsp::DidChangeConfigurationParams {
- settings: workspace_config.clone(),
- },
+ lsp::DidChangeConfigurationParams { settings },
)
.ok();
}
@@ -161,14 +161,14 @@ impl settings::Settings for TerminalSettings {
}
fn json_schema(
generator: &mut SchemaGenerator,
- _: &SettingsJsonSchemaParams,
- cx: &AppContext,
+ params: &SettingsJsonSchemaParams,
+ _: &AppContext,
) -> RootSchema {
let mut root_schema = generator.root_schema_for::<Self::FileContent>();
- let available_fonts = cx
- .text_system()
- .all_font_names()
- .into_iter()
+ let available_fonts = params
+ .font_names
+ .iter()
+ .cloned()
.map(Value::String)
.collect();
let fonts_schema = SchemaObject {
@@ -7,14 +7,14 @@ use gpui::AppContext;
use language::{LanguageRegistry, LanguageServerName, LspAdapter, LspAdapterDelegate};
use lsp::LanguageServerBinary;
use node_runtime::NodeRuntime;
-use serde_json::json;
+use serde_json::{json, Value};
use settings::{KeymapFile, SettingsJsonSchemaParams, SettingsStore};
use smol::fs;
use std::{
any::Any,
ffi::OsString,
path::{Path, PathBuf},
- sync::Arc,
+ sync::{Arc, OnceLock},
};
use util::{paths, ResultExt};
@@ -28,11 +28,52 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
pub struct JsonLspAdapter {
node: Arc<dyn NodeRuntime>,
languages: Arc<LanguageRegistry>,
+ workspace_config: OnceLock<Value>,
}
impl JsonLspAdapter {
pub fn new(node: Arc<dyn NodeRuntime>, languages: Arc<LanguageRegistry>) -> Self {
- JsonLspAdapter { node, languages }
+ Self {
+ node,
+ languages,
+ workspace_config: Default::default(),
+ }
+ }
+
+ fn get_workspace_config(language_names: Vec<String>, cx: &mut AppContext) -> Value {
+ let action_names = cx.all_action_names();
+ let staff_mode = cx.is_staff();
+
+ let font_names = &cx.text_system().all_font_names();
+ let settings_schema = cx.global::<SettingsStore>().json_schema(
+ &SettingsJsonSchemaParams {
+ language_names: &language_names,
+ staff_mode,
+ font_names,
+ },
+ cx,
+ );
+
+ serde_json::json!({
+ "json": {
+ "format": {
+ "enable": true,
+ },
+ "schemas": [
+ {
+ "fileMatch": [
+ schema_file_match(&paths::SETTINGS),
+ &*paths::LOCAL_SETTINGS_RELATIVE_PATH,
+ ],
+ "schema": settings_schema,
+ },
+ {
+ "fileMatch": [schema_file_match(&paths::KEYMAP)],
+ "schema": KeymapFile::generate_json_schema(&action_names),
+ }
+ ]
+ }
+ })
}
}
@@ -102,42 +143,10 @@ impl LspAdapter for JsonLspAdapter {
}))
}
- fn workspace_configuration(
- &self,
- _workspace_root: &Path,
- cx: &mut AppContext,
- ) -> serde_json::Value {
- let action_names = cx.all_action_names();
- let staff_mode = cx.is_staff();
- let language_names = &self.languages.language_names();
- let settings_schema = cx.global::<SettingsStore>().json_schema(
- &SettingsJsonSchemaParams {
- language_names,
- staff_mode,
- },
- cx,
- );
-
- serde_json::json!({
- "json": {
- "format": {
- "enable": true,
- },
- "schemas": [
- {
- "fileMatch": [
- schema_file_match(&paths::SETTINGS),
- &*paths::LOCAL_SETTINGS_RELATIVE_PATH,
- ],
- "schema": settings_schema,
- },
- {
- "fileMatch": [schema_file_match(&paths::KEYMAP)],
- "schema": KeymapFile::generate_json_schema(&action_names),
- }
- ]
- }
- })
+ fn workspace_configuration(&self, _workspace_root: &Path, cx: &mut AppContext) -> Value {
+ self.workspace_config
+ .get_or_init(|| Self::get_workspace_config(self.languages.language_names(), cx))
+ .clone()
}
fn language_ids(&self) -> HashMap<String, String> {