From 4616d66e1d72b608c2d77423e04c90aa107c8b3d Mon Sep 17 00:00:00 2001 From: bbb651 <53972231+bbb651@users.noreply.github.com> Date: Mon, 19 Feb 2024 23:53:03 -0800 Subject: [PATCH] Download right language server binary for OS (#8040) Release Notes: - Download right language server binary for OS --- crates/node_runtime/src/node_runtime.rs | 13 ++++++++++--- crates/zed/src/languages/clojure.rs | 8 +++++++- crates/zed/src/languages/deno.rs | 10 ++++++++-- crates/zed/src/languages/gleam.rs | 14 ++++++++++---- crates/zed/src/languages/lua.rs | 8 +++++++- crates/zed/src/languages/rust.rs | 10 ++++++++-- crates/zed/src/languages/toml.rs | 13 +++++++++++-- crates/zed/src/languages/zig.rs | 4 ++-- 8 files changed, 63 insertions(+), 17 deletions(-) diff --git a/crates/node_runtime/src/node_runtime.rs b/crates/node_runtime/src/node_runtime.rs index e40f83fae0..7317635dd1 100644 --- a/crates/node_runtime/src/node_runtime.rs +++ b/crates/node_runtime/src/node_runtime.rs @@ -60,13 +60,20 @@ impl RealNodeRuntime { let _lock = self.installation_lock.lock().await; log::info!("Node runtime install_if_needed"); + let os = match consts::OS { + "macos" => "darwin", + "linux" => "linux", + "windows" => "win", + other => bail!("Running on unsupported os: {other}"), + }; + let arch = match consts::ARCH { "x86_64" => "x64", "aarch64" => "arm64", - other => bail!("Running on unsupported platform: {other}"), + other => bail!("Running on unsupported architecture: {other}"), }; - let folder_name = format!("node-{VERSION}-darwin-{arch}"); + let folder_name = format!("node-{VERSION}-{os}-{arch}"); let node_containing_dir = util::paths::SUPPORT_DIR.join("node"); let node_dir = node_containing_dir.join(folder_name); let node_binary = node_dir.join("bin/node"); @@ -92,7 +99,7 @@ impl RealNodeRuntime { .await .context("error creating node containing dir")?; - let file_name = format!("node-{VERSION}-darwin-{arch}.tar.gz"); + let file_name = format!("node-{VERSION}-{os}-{arch}.tar.gz"); let url = format!("https://nodejs.org/dist/{VERSION}/{file_name}"); let mut response = self .http diff --git a/crates/zed/src/languages/clojure.rs b/crates/zed/src/languages/clojure.rs index e200b9c6a0..4362d2f3f1 100644 --- a/crates/zed/src/languages/clojure.rs +++ b/crates/zed/src/languages/clojure.rs @@ -33,12 +33,18 @@ impl super::LspAdapter for ClojureLspAdapter { delegate.http_client(), ) .await?; + let os = match consts::OS { + "macos" => "macos", + "linux" => "linux", + "windows" => "windows", + other => bail!("Running on unsupported os: {other}"), + }; let platform = match consts::ARCH { "x86_64" => "amd64", "aarch64" => "aarch64", other => bail!("Running on unsupported platform: {other}"), }; - let asset_name = format!("clojure-lsp-native-macos-{platform}.zip"); + let asset_name = format!("clojure-lsp-native-{os}-{platform}.zip"); let asset = release .assets .iter() diff --git a/crates/zed/src/languages/deno.rs b/crates/zed/src/languages/deno.rs index a06c6e42d5..3e7b8754e1 100644 --- a/crates/zed/src/languages/deno.rs +++ b/crates/zed/src/languages/deno.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Context, Result}; +use anyhow::{anyhow, bail, Context, Result}; use async_trait::async_trait; use collections::HashMap; use futures::StreamExt; @@ -72,7 +72,13 @@ impl LspAdapter for DenoLspAdapter { ) -> Result> { let release = latest_github_release("denoland/deno", true, false, delegate.http_client()).await?; - let asset_name = format!("deno-{}-apple-darwin.zip", consts::ARCH); + let os = match consts::OS { + "macos" => "apple-darwin", + "linux" => "unknown-linux-gnu", + "windows" => "pc-windows-msvc", + other => bail!("Running on unsupported os: {other}"), + }; + let asset_name = format!("deno-{}-{os}.zip", consts::ARCH); let asset = release .assets .iter() diff --git a/crates/zed/src/languages/gleam.rs b/crates/zed/src/languages/gleam.rs index 508956b099..2ff959655c 100644 --- a/crates/zed/src/languages/gleam.rs +++ b/crates/zed/src/languages/gleam.rs @@ -1,8 +1,9 @@ use std::any::Any; +use std::env::consts; use std::ffi::OsString; use std::path::PathBuf; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, bail, Result}; use async_compression::futures::bufread::GzipDecoder; use async_tar::Archive; use async_trait::async_trait; @@ -36,11 +37,16 @@ impl LspAdapter for GleamLspAdapter { ) -> Result> { let release = latest_github_release("gleam-lang/gleam", true, false, delegate.http_client()).await?; - let asset_name = format!( - "gleam-{version}-{arch}-apple-darwin.tar.gz", + "gleam-{version}-{arch}-{os}.tar.gz", version = release.tag_name, - arch = std::env::consts::ARCH + arch = std::env::consts::ARCH, + os = match consts::OS { + "macos" => "apple-darwin", + "linux" => "unknown-linux-musl", + "windows" => "pc-windows-msvc", + other => bail!("Running on unsupported os: {other}"), + }, ); let asset = release .assets diff --git a/crates/zed/src/languages/lua.rs b/crates/zed/src/languages/lua.rs index 7476ab37ea..24cbafb50f 100644 --- a/crates/zed/src/languages/lua.rs +++ b/crates/zed/src/languages/lua.rs @@ -30,6 +30,12 @@ impl super::LspAdapter for LuaLspAdapter { &self, delegate: &dyn LspAdapterDelegate, ) -> Result> { + let os = match consts::OS { + "macos" => "darwin", + "linux" => "linux", + "windows" => "win32", + other => bail!("Running on unsupported os: {other}"), + }; let platform = match consts::ARCH { "x86_64" => "x64", "aarch64" => "arm64", @@ -43,7 +49,7 @@ impl super::LspAdapter for LuaLspAdapter { ) .await?; let version = &release.tag_name; - let asset_name = format!("lua-language-server-{version}-darwin-{platform}.tar.gz"); + let asset_name = format!("lua-language-server-{version}-{os}-{platform}.tar.gz"); let asset = release .assets .iter() diff --git a/crates/zed/src/languages/rust.rs b/crates/zed/src/languages/rust.rs index 7a95e26d9b..8bcda93949 100644 --- a/crates/zed/src/languages/rust.rs +++ b/crates/zed/src/languages/rust.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, bail, Result}; use async_compression::futures::bufread::GzipDecoder; use async_trait::async_trait; use futures::{io::BufReader, StreamExt}; @@ -38,7 +38,13 @@ impl LspAdapter for RustLspAdapter { delegate.http_client(), ) .await?; - let asset_name = format!("rust-analyzer-{}-apple-darwin.gz", consts::ARCH); + let os = match consts::OS { + "macos" => "apple-darwin", + "linux" => "unknown-linux-gnu", + "windows" => "pc-windows-msvc", + other => bail!("Running on unsupported os: {other}"), + }; + let asset_name = format!("rust-analyzer-{}-{os}.gz", consts::ARCH); let asset = release .assets .iter() diff --git a/crates/zed/src/languages/toml.rs b/crates/zed/src/languages/toml.rs index 9393fa691e..e6f933d707 100644 --- a/crates/zed/src/languages/toml.rs +++ b/crates/zed/src/languages/toml.rs @@ -1,4 +1,4 @@ -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; use async_compression::futures::bufread::GzipDecoder; use async_trait::async_trait; use futures::{io::BufReader, StreamExt}; @@ -28,7 +28,16 @@ impl LspAdapter for TaploLspAdapter { ) -> Result> { let release = latest_github_release("tamasfe/taplo", true, false, delegate.http_client()).await?; - let asset_name = format!("taplo-full-darwin-{arch}.gz", arch = std::env::consts::ARCH); + let asset_name = format!( + "taplo-full-{os}-{arch}.gz", + os = match std::env::consts::OS { + "macos" => "darwin", + "linux" => "linux", + "windows" => "windows", + other => bail!("Running on unsupported os: {other}"), + }, + arch = std::env::consts::ARCH + ); let asset = release .assets diff --git a/crates/zed/src/languages/zig.rs b/crates/zed/src/languages/zig.rs index 12268c2e14..6c12f129c5 100644 --- a/crates/zed/src/languages/zig.rs +++ b/crates/zed/src/languages/zig.rs @@ -6,7 +6,7 @@ use futures::{io::BufReader, StreamExt}; use language::{LanguageServerName, LspAdapter, LspAdapterDelegate}; use lsp::LanguageServerBinary; use smol::fs; -use std::env::consts::ARCH; +use std::env::consts::{ARCH, OS}; use std::{any::Any, path::PathBuf}; use util::async_maybe; use util::github::latest_github_release; @@ -30,7 +30,7 @@ impl LspAdapter for ZlsAdapter { ) -> Result> { let release = latest_github_release("zigtools/zls", true, false, delegate.http_client()).await?; - let asset_name = format!("zls-{ARCH}-macos.tar.gz"); + let asset_name = format!("zls-{ARCH}-{OS}.tar.gz"); let asset = release .assets .iter()