diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index c423d966c0..331c8c3987 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -74,7 +74,7 @@ pub struct CachedLspAdapter { pub initialization_options: Option, pub disk_based_diagnostic_sources: Vec, pub disk_based_diagnostics_progress_token: Option, - pub id_for_language: Option, + pub language_ids: HashMap, pub adapter: Box, } @@ -87,7 +87,7 @@ impl CachedLspAdapter { let disk_based_diagnostic_sources = adapter.disk_based_diagnostic_sources().await; let disk_based_diagnostics_progress_token = adapter.disk_based_diagnostics_progress_token().await; - let id_for_language = adapter.id_for_language(name.0.as_ref()).await; + let language_ids = adapter.language_ids().await; Arc::new(CachedLspAdapter { name, @@ -95,7 +95,7 @@ impl CachedLspAdapter { initialization_options, disk_based_diagnostic_sources, disk_based_diagnostics_progress_token, - id_for_language, + language_ids, adapter, }) } @@ -199,8 +199,8 @@ pub trait LspAdapter: 'static + Send + Sync { None } - async fn id_for_language(&self, _name: &str) -> Option { - None + async fn language_ids(&self) -> HashMap { + Default::default() } } diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 36d2c9ac92..759eb90194 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1821,7 +1821,7 @@ impl Project { if let Some(language) = buffer.language() { let worktree_id = file.worktree_id(cx); if let Some(adapter) = language.lsp_adapter() { - language_id = adapter.id_for_language.clone(); + language_id = adapter.language_ids.get(language.name().as_ref()).cloned(); language_server = self .language_server_ids .get(&(worktree_id, adapter.name.clone())) @@ -2320,8 +2320,9 @@ impl Project { text_document: lsp::TextDocumentItem::new( uri, adapter - .id_for_language - .clone() + .language_ids + .get(language.name().as_ref()) + .cloned() .unwrap_or_default(), *version, initial_snapshot.text(), diff --git a/crates/zed/src/languages/language_plugin.rs b/crates/zed/src/languages/language_plugin.rs index ac649c425d..773cc16b97 100644 --- a/crates/zed/src/languages/language_plugin.rs +++ b/crates/zed/src/languages/language_plugin.rs @@ -1,6 +1,7 @@ use anyhow::{anyhow, Result}; use async_trait::async_trait; use client::http::HttpClient; +use collections::HashMap; use futures::lock::Mutex; use gpui::executor::Background; use language::{LanguageServerName, LspAdapter}; @@ -35,6 +36,7 @@ pub struct PluginLspAdapter { fetch_server_binary: WasiFn<(PathBuf, String), Result>, cached_server_binary: WasiFn>, initialization_options: WasiFn<(), String>, + language_ids: WasiFn<(), Vec<(String, String)>>, executor: Arc, runtime: Arc>, } @@ -48,6 +50,7 @@ impl PluginLspAdapter { fetch_server_binary: plugin.function("fetch_server_binary")?, cached_server_binary: plugin.function("cached_server_binary")?, initialization_options: plugin.function("initialization_options")?, + language_ids: plugin.function("language_ids")?, executor, runtime: Arc::new(Mutex::new(plugin)), }) @@ -142,4 +145,16 @@ impl LspAdapter for PluginLspAdapter { serde_json::from_str(&string).ok() } + + async fn language_ids(&self) -> HashMap { + self.runtime + .lock() + .await + .call(&self.language_ids, ()) + .await + .log_err() + .unwrap_or_default() + .into_iter() + .collect() + } } diff --git a/plugins/json_language/src/lib.rs b/plugins/json_language/src/lib.rs index b3ee55b261..1503f9f8b2 100644 --- a/plugins/json_language/src/lib.rs +++ b/plugins/json_language/src/lib.rs @@ -94,10 +94,6 @@ pub fn initialization_options() -> Option { } #[export] -pub fn id_for_language(name: String) -> Option { - if name == "JSON" { - Some("jsonc".into()) - } else { - None - } +pub fn language_ids() -> Vec<(String, String)> { + vec![("JSON".into(), "jsonc".into())] }