From 843a35a1a9e7d67a1bdff973faa6c75a811934ca Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 17 Dec 2025 16:25:07 -0800 Subject: [PATCH] extension api: Make server id types constructible, to ease writing tests (#45174) Currently, extensions cannot have tests that call methods like `label_for_symbol` and `label_for_completion`, because those methods take a `LanguageServerId`, and that type is opaque, and cannot be constructed outside of the `zed_extension_api` crate. This PR makes it possible to construct those types from strings, so that it's more straightforward to write unit tests for these LSP adapter methods. Release Notes: - N/A --- crates/extension_api/src/extension_api.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/extension_api/src/extension_api.rs b/crates/extension_api/src/extension_api.rs index 9418623224289f795fed061acbfc6035a4cc5cdf..acd1cba47b0150b85ddec8baafa8b5f341460a39 100644 --- a/crates/extension_api/src/extension_api.rs +++ b/crates/extension_api/src/extension_api.rs @@ -331,7 +331,6 @@ static mut EXTENSION: Option> = None; pub static ZED_API_VERSION: [u8; 6] = *include_bytes!(concat!(env!("OUT_DIR"), "/version_bytes")); mod wit { - wit_bindgen::generate!({ skip: ["init-extension"], path: "./wit/since_v0.8.0", @@ -524,6 +523,12 @@ impl wit::Guest for Component { #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] pub struct LanguageServerId(String); +impl LanguageServerId { + pub fn new(value: String) -> Self { + Self(value) + } +} + impl AsRef for LanguageServerId { fn as_ref(&self) -> &str { &self.0 @@ -540,6 +545,12 @@ impl fmt::Display for LanguageServerId { #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] pub struct ContextServerId(String); +impl ContextServerId { + pub fn new(value: String) -> Self { + Self(value) + } +} + impl AsRef for ContextServerId { fn as_ref(&self) -> &str { &self.0