From d489f96aefb6166f42fcdd9cd40f1c765244b66d Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Fri, 22 Nov 2024 10:58:11 -0500 Subject: [PATCH] Don't name `ExtensionLspAdapter` in `ExtensionRegistrationHooks` (#21064) This PR updates the `ExtensionRegistrationHooks` trait to not name the `ExtensionLspAdapter` type. This helps decouple the two. Release Notes: - N/A --- crates/extension_host/src/extension_host.rs | 16 +++++----- .../src/extension_lsp_adapter.rs | 20 +++++++++++-- .../src/extension_store_test.rs | 20 +++++++++---- crates/extension_host/src/headless_host.rs | 29 ++++++++++++------- .../src/extension_registration_hooks.rs | 18 ++++++++---- 5 files changed, 73 insertions(+), 30 deletions(-) diff --git a/crates/extension_host/src/extension_host.rs b/crates/extension_host/src/extension_host.rs index 4a832faeff..236c8091b4 100644 --- a/crates/extension_host/src/extension_host.rs +++ b/crates/extension_host/src/extension_host.rs @@ -6,7 +6,6 @@ pub mod wasm_host; #[cfg(test)] mod extension_store_test; -use crate::extension_lsp_adapter::ExtensionLspAdapter; use anyhow::{anyhow, bail, Context as _, Result}; use async_compression::futures::bufread::GzipDecoder; use async_tar::Archive; @@ -122,7 +121,13 @@ pub trait ExtensionRegistrationHooks: Send + Sync + 'static { ) { } - fn register_lsp_adapter(&self, _language: LanguageName, _adapter: ExtensionLspAdapter) {} + fn register_lsp_adapter( + &self, + _extension: Arc, + _language_server_id: LanguageServerName, + _language: LanguageName, + ) { + } fn remove_lsp_adapter(&self, _language: &LanguageName, _server_name: &LanguageServerName) {} @@ -1255,12 +1260,9 @@ impl ExtensionStore { for (language_server_id, language_server_config) in &manifest.language_servers { for language in language_server_config.languages() { this.registration_hooks.register_lsp_adapter( + extension.clone(), + language_server_id.clone(), language.clone(), - ExtensionLspAdapter { - extension: extension.clone(), - language_server_id: language_server_id.clone(), - language_name: language.clone(), - }, ); } } diff --git a/crates/extension_host/src/extension_lsp_adapter.rs b/crates/extension_host/src/extension_lsp_adapter.rs index 8f83c68e31..069eddba57 100644 --- a/crates/extension_host/src/extension_lsp_adapter.rs +++ b/crates/extension_host/src/extension_lsp_adapter.rs @@ -45,9 +45,23 @@ impl WorktreeDelegate for WorktreeDelegateAdapter { } pub struct ExtensionLspAdapter { - pub(crate) extension: Arc, - pub(crate) language_server_id: LanguageServerName, - pub(crate) language_name: LanguageName, + extension: Arc, + language_server_id: LanguageServerName, + language_name: LanguageName, +} + +impl ExtensionLspAdapter { + pub fn new( + extension: Arc, + language_server_id: LanguageServerName, + language_name: LanguageName, + ) -> Self { + Self { + extension, + language_server_id, + language_name, + } + } } #[async_trait(?Send)] diff --git a/crates/extension_host/src/extension_store_test.rs b/crates/extension_host/src/extension_store_test.rs index 23004e9d7f..5d78539617 100644 --- a/crates/extension_host/src/extension_store_test.rs +++ b/crates/extension_host/src/extension_store_test.rs @@ -7,11 +7,14 @@ use crate::{ use anyhow::Result; use async_compression::futures::bufread::GzipEncoder; use collections::BTreeMap; +use extension::Extension; use fs::{FakeFs, Fs, RealFs}; use futures::{io::BufReader, AsyncReadExt, StreamExt}; use gpui::{BackgroundExecutor, Context, SemanticVersion, SharedString, Task, TestAppContext}; use http_client::{FakeHttpClient, Response}; -use language::{LanguageMatcher, LanguageRegistry, LanguageServerBinaryStatus, LoadedLanguage}; +use language::{ + LanguageMatcher, LanguageName, LanguageRegistry, LanguageServerBinaryStatus, LoadedLanguage, +}; use lsp::LanguageServerName; use node_runtime::NodeRuntime; use parking_lot::Mutex; @@ -80,11 +83,18 @@ impl ExtensionRegistrationHooks for TestExtensionRegistrationHooks { fn register_lsp_adapter( &self, - language_name: language::LanguageName, - adapter: ExtensionLspAdapter, + extension: Arc, + language_server_id: LanguageServerName, + language: LanguageName, ) { - self.language_registry - .register_lsp_adapter(language_name, Arc::new(adapter)); + self.language_registry.register_lsp_adapter( + language.clone(), + Arc::new(ExtensionLspAdapter::new( + extension, + language_server_id, + language, + )), + ); } fn update_lsp_status( diff --git a/crates/extension_host/src/headless_host.rs b/crates/extension_host/src/headless_host.rs index e297794bf1..6ad8b71aa3 100644 --- a/crates/extension_host/src/headless_host.rs +++ b/crates/extension_host/src/headless_host.rs @@ -177,20 +177,17 @@ impl HeadlessExtensionStore { let wasm_extension: Arc = Arc::new(WasmExtension::load(extension_dir, &manifest, wasm_host.clone(), &cx).await?); - for (language_server_name, language_server_config) in &manifest.language_servers { + for (language_server_id, language_server_config) in &manifest.language_servers { for language in language_server_config.languages() { this.update(cx, |this, _cx| { this.loaded_language_servers .entry(manifest.id.clone()) .or_default() - .push((language_server_name.clone(), language.clone())); + .push((language_server_id.clone(), language.clone())); this.registration_hooks.register_lsp_adapter( + wasm_extension.clone(), + language_server_id.clone(), language.clone(), - ExtensionLspAdapter { - extension: wasm_extension.clone(), - language_server_id: language_server_name.clone(), - language_name: language, - }, ); })?; } @@ -344,10 +341,22 @@ impl ExtensionRegistrationHooks for HeadlessRegistrationHooks { self.language_registry .register_language(language, None, matcher, load) } - fn register_lsp_adapter(&self, language: LanguageName, adapter: ExtensionLspAdapter) { + + fn register_lsp_adapter( + &self, + extension: Arc, + language_server_id: LanguageServerName, + language: LanguageName, + ) { log::info!("registering lsp adapter {:?}", language); - self.language_registry - .register_lsp_adapter(language, Arc::new(adapter) as _); + self.language_registry.register_lsp_adapter( + language.clone(), + Arc::new(ExtensionLspAdapter::new( + extension, + language_server_id, + language, + )), + ); } fn register_wasm_grammars(&self, grammars: Vec<(Arc, PathBuf)>) { diff --git a/crates/extensions_ui/src/extension_registration_hooks.rs b/crates/extensions_ui/src/extension_registration_hooks.rs index f8cd9a3429..07a4c1455c 100644 --- a/crates/extensions_ui/src/extension_registration_hooks.rs +++ b/crates/extensions_ui/src/extension_registration_hooks.rs @@ -11,7 +11,8 @@ use extension_host::{extension_lsp_adapter::ExtensionLspAdapter, wasm_host}; use fs::Fs; use gpui::{AppContext, BackgroundExecutor, Model, Task}; use indexed_docs::{ExtensionIndexedDocsProvider, IndexedDocsRegistry, ProviderId}; -use language::{LanguageRegistry, LanguageServerBinaryStatus, LoadedLanguage}; +use language::{LanguageName, LanguageRegistry, LanguageServerBinaryStatus, LoadedLanguage}; +use lsp::LanguageServerName; use snippet_provider::SnippetRegistry; use theme::{ThemeRegistry, ThemeSettings}; use ui::SharedString; @@ -159,11 +160,18 @@ impl extension_host::ExtensionRegistrationHooks for ConcreteExtensionRegistratio fn register_lsp_adapter( &self, - language_name: language::LanguageName, - adapter: ExtensionLspAdapter, + extension: Arc, + language_server_id: LanguageServerName, + language: LanguageName, ) { - self.language_registry - .register_lsp_adapter(language_name, Arc::new(adapter)); + self.language_registry.register_lsp_adapter( + language.clone(), + Arc::new(ExtensionLspAdapter::new( + extension, + language_server_id, + language, + )), + ); } fn remove_lsp_adapter(