From 210f8ebfed660a1e0d952e98780ac29bf1ba7028 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Tue, 16 Apr 2024 19:05:11 +0200 Subject: [PATCH] zig: Do not cache user-installed `zls` (#10634) This was a bug introduced when moving to extensions: when we find a binary in the user's project environment, we shouldn't cache that globally since it might not work for other projects. See also: https://github.com/zed-industries/zed/pull/10559 Release Notes: - N/A --- extensions/zig/src/zig.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/extensions/zig/src/zig.rs b/extensions/zig/src/zig.rs index e10ff55c44d01477501ceef0776db65eab125c40..72bfa1faf929f44a87f244e09b5dead79967773b 100644 --- a/extensions/zig/src/zig.rs +++ b/extensions/zig/src/zig.rs @@ -3,7 +3,7 @@ use zed::LanguageServerId; use zed_extension_api::{self as zed, Result}; struct ZigExtension { - cached_binary: Option, + cached_binary: Option, } #[derive(Clone)] @@ -18,20 +18,21 @@ impl ZigExtension { language_server_id: &LanguageServerId, worktree: &zed::Worktree, ) -> Result { - if let Some(zls_binary) = &self.cached_binary { - if fs::metadata(&zls_binary.path).map_or(false, |stat| stat.is_file()) { - return Ok(zls_binary.clone()); - } - } - if let Some(path) = worktree.which("zls") { let environment = worktree.shell_env(); - let zls_binary = ZlsBinary { + return Ok(ZlsBinary { path, environment: Some(environment), - }; - self.cached_binary = Some(zls_binary.clone()); - return Ok(zls_binary); + }); + } + + if let Some(path) = &self.cached_binary { + if fs::metadata(&path).map_or(false, |stat| stat.is_file()) { + return Ok(ZlsBinary { + path: path.clone(), + environment: None, + }); + } } zed::set_language_server_installation_status( @@ -102,12 +103,11 @@ impl ZigExtension { } } - let zls_binary = ZlsBinary { + self.cached_binary = Some(binary_path.clone()); + Ok(ZlsBinary { path: binary_path, environment: None, - }; - self.cached_binary = Some(zls_binary.clone()); - Ok(zls_binary) + }) } }