gleam: Check for gleam on the PATH before installing the latest version (#9882)

This PR updates the Gleam extension to give priority to the `gleam`
binary that is already on the PATH before downloading/installing a
separate Gleam version.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-03-27 14:25:18 -04:00 committed by GitHub
parent 894b39a918
commit 95699a07f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,13 +6,22 @@ struct GleamExtension {
}
impl GleamExtension {
fn language_server_binary_path(&mut self, config: zed::LanguageServerConfig) -> Result<String> {
fn language_server_binary_path(
&mut self,
config: zed::LanguageServerConfig,
worktree: &zed::Worktree,
) -> Result<String> {
if let Some(path) = &self.cached_binary_path {
if fs::metadata(path).map_or(false, |stat| stat.is_file()) {
return Ok(path.clone());
}
}
if let Some(path) = worktree.which("gleam") {
self.cached_binary_path = Some(path.clone());
return Ok(path);
}
zed::set_language_server_installation_status(
&config.name,
&zed::LanguageServerInstallationStatus::CheckingForUpdate,
@ -88,10 +97,10 @@ impl zed::Extension for GleamExtension {
fn language_server_command(
&mut self,
config: zed::LanguageServerConfig,
_worktree: &zed::Worktree,
worktree: &zed::Worktree,
) -> Result<zed::Command> {
Ok(zed::Command {
command: self.language_server_binary_path(config)?,
command: self.language_server_binary_path(config, worktree)?,
args: vec!["lsp".to_string()],
env: Default::default(),
})