mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-26 12:21:50 +00:00
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
This commit is contained in:
parent
b4659bb44e
commit
d489f96aef
5 changed files with 73 additions and 30 deletions
|
@ -6,7 +6,6 @@ pub mod wasm_host;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod extension_store_test;
|
mod extension_store_test;
|
||||||
|
|
||||||
use crate::extension_lsp_adapter::ExtensionLspAdapter;
|
|
||||||
use anyhow::{anyhow, bail, Context as _, Result};
|
use anyhow::{anyhow, bail, Context as _, Result};
|
||||||
use async_compression::futures::bufread::GzipDecoder;
|
use async_compression::futures::bufread::GzipDecoder;
|
||||||
use async_tar::Archive;
|
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<dyn Extension>,
|
||||||
|
_language_server_id: LanguageServerName,
|
||||||
|
_language: LanguageName,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
fn remove_lsp_adapter(&self, _language: &LanguageName, _server_name: &LanguageServerName) {}
|
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_server_id, language_server_config) in &manifest.language_servers {
|
||||||
for language in language_server_config.languages() {
|
for language in language_server_config.languages() {
|
||||||
this.registration_hooks.register_lsp_adapter(
|
this.registration_hooks.register_lsp_adapter(
|
||||||
|
extension.clone(),
|
||||||
|
language_server_id.clone(),
|
||||||
language.clone(),
|
language.clone(),
|
||||||
ExtensionLspAdapter {
|
|
||||||
extension: extension.clone(),
|
|
||||||
language_server_id: language_server_id.clone(),
|
|
||||||
language_name: language.clone(),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,23 @@ impl WorktreeDelegate for WorktreeDelegateAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ExtensionLspAdapter {
|
pub struct ExtensionLspAdapter {
|
||||||
pub(crate) extension: Arc<dyn Extension>,
|
extension: Arc<dyn Extension>,
|
||||||
pub(crate) language_server_id: LanguageServerName,
|
language_server_id: LanguageServerName,
|
||||||
pub(crate) language_name: LanguageName,
|
language_name: LanguageName,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ExtensionLspAdapter {
|
||||||
|
pub fn new(
|
||||||
|
extension: Arc<dyn Extension>,
|
||||||
|
language_server_id: LanguageServerName,
|
||||||
|
language_name: LanguageName,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
extension,
|
||||||
|
language_server_id,
|
||||||
|
language_name,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
|
|
|
@ -7,11 +7,14 @@ use crate::{
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use async_compression::futures::bufread::GzipEncoder;
|
use async_compression::futures::bufread::GzipEncoder;
|
||||||
use collections::BTreeMap;
|
use collections::BTreeMap;
|
||||||
|
use extension::Extension;
|
||||||
use fs::{FakeFs, Fs, RealFs};
|
use fs::{FakeFs, Fs, RealFs};
|
||||||
use futures::{io::BufReader, AsyncReadExt, StreamExt};
|
use futures::{io::BufReader, AsyncReadExt, StreamExt};
|
||||||
use gpui::{BackgroundExecutor, Context, SemanticVersion, SharedString, Task, TestAppContext};
|
use gpui::{BackgroundExecutor, Context, SemanticVersion, SharedString, Task, TestAppContext};
|
||||||
use http_client::{FakeHttpClient, Response};
|
use http_client::{FakeHttpClient, Response};
|
||||||
use language::{LanguageMatcher, LanguageRegistry, LanguageServerBinaryStatus, LoadedLanguage};
|
use language::{
|
||||||
|
LanguageMatcher, LanguageName, LanguageRegistry, LanguageServerBinaryStatus, LoadedLanguage,
|
||||||
|
};
|
||||||
use lsp::LanguageServerName;
|
use lsp::LanguageServerName;
|
||||||
use node_runtime::NodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
@ -80,11 +83,18 @@ impl ExtensionRegistrationHooks for TestExtensionRegistrationHooks {
|
||||||
|
|
||||||
fn register_lsp_adapter(
|
fn register_lsp_adapter(
|
||||||
&self,
|
&self,
|
||||||
language_name: language::LanguageName,
|
extension: Arc<dyn Extension>,
|
||||||
adapter: ExtensionLspAdapter,
|
language_server_id: LanguageServerName,
|
||||||
|
language: LanguageName,
|
||||||
) {
|
) {
|
||||||
self.language_registry
|
self.language_registry.register_lsp_adapter(
|
||||||
.register_lsp_adapter(language_name, Arc::new(adapter));
|
language.clone(),
|
||||||
|
Arc::new(ExtensionLspAdapter::new(
|
||||||
|
extension,
|
||||||
|
language_server_id,
|
||||||
|
language,
|
||||||
|
)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_lsp_status(
|
fn update_lsp_status(
|
||||||
|
|
|
@ -177,20 +177,17 @@ impl HeadlessExtensionStore {
|
||||||
let wasm_extension: Arc<dyn Extension> =
|
let wasm_extension: Arc<dyn Extension> =
|
||||||
Arc::new(WasmExtension::load(extension_dir, &manifest, wasm_host.clone(), &cx).await?);
|
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() {
|
for language in language_server_config.languages() {
|
||||||
this.update(cx, |this, _cx| {
|
this.update(cx, |this, _cx| {
|
||||||
this.loaded_language_servers
|
this.loaded_language_servers
|
||||||
.entry(manifest.id.clone())
|
.entry(manifest.id.clone())
|
||||||
.or_default()
|
.or_default()
|
||||||
.push((language_server_name.clone(), language.clone()));
|
.push((language_server_id.clone(), language.clone()));
|
||||||
this.registration_hooks.register_lsp_adapter(
|
this.registration_hooks.register_lsp_adapter(
|
||||||
|
wasm_extension.clone(),
|
||||||
|
language_server_id.clone(),
|
||||||
language.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
|
self.language_registry
|
||||||
.register_language(language, None, matcher, load)
|
.register_language(language, None, matcher, load)
|
||||||
}
|
}
|
||||||
fn register_lsp_adapter(&self, language: LanguageName, adapter: ExtensionLspAdapter) {
|
|
||||||
|
fn register_lsp_adapter(
|
||||||
|
&self,
|
||||||
|
extension: Arc<dyn Extension>,
|
||||||
|
language_server_id: LanguageServerName,
|
||||||
|
language: LanguageName,
|
||||||
|
) {
|
||||||
log::info!("registering lsp adapter {:?}", language);
|
log::info!("registering lsp adapter {:?}", language);
|
||||||
self.language_registry
|
self.language_registry.register_lsp_adapter(
|
||||||
.register_lsp_adapter(language, Arc::new(adapter) as _);
|
language.clone(),
|
||||||
|
Arc::new(ExtensionLspAdapter::new(
|
||||||
|
extension,
|
||||||
|
language_server_id,
|
||||||
|
language,
|
||||||
|
)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_wasm_grammars(&self, grammars: Vec<(Arc<str>, PathBuf)>) {
|
fn register_wasm_grammars(&self, grammars: Vec<(Arc<str>, PathBuf)>) {
|
||||||
|
|
|
@ -11,7 +11,8 @@ use extension_host::{extension_lsp_adapter::ExtensionLspAdapter, wasm_host};
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
use gpui::{AppContext, BackgroundExecutor, Model, Task};
|
use gpui::{AppContext, BackgroundExecutor, Model, Task};
|
||||||
use indexed_docs::{ExtensionIndexedDocsProvider, IndexedDocsRegistry, ProviderId};
|
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 snippet_provider::SnippetRegistry;
|
||||||
use theme::{ThemeRegistry, ThemeSettings};
|
use theme::{ThemeRegistry, ThemeSettings};
|
||||||
use ui::SharedString;
|
use ui::SharedString;
|
||||||
|
@ -159,11 +160,18 @@ impl extension_host::ExtensionRegistrationHooks for ConcreteExtensionRegistratio
|
||||||
|
|
||||||
fn register_lsp_adapter(
|
fn register_lsp_adapter(
|
||||||
&self,
|
&self,
|
||||||
language_name: language::LanguageName,
|
extension: Arc<dyn Extension>,
|
||||||
adapter: ExtensionLspAdapter,
|
language_server_id: LanguageServerName,
|
||||||
|
language: LanguageName,
|
||||||
) {
|
) {
|
||||||
self.language_registry
|
self.language_registry.register_lsp_adapter(
|
||||||
.register_lsp_adapter(language_name, Arc::new(adapter));
|
language.clone(),
|
||||||
|
Arc::new(ExtensionLspAdapter::new(
|
||||||
|
extension,
|
||||||
|
language_server_id,
|
||||||
|
language,
|
||||||
|
)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_lsp_adapter(
|
fn remove_lsp_adapter(
|
||||||
|
|
Loading…
Reference in a new issue