Initial running of servers on downloaded Node

This commit is contained in:
Julia 2023-03-23 17:32:13 -04:00
parent b579211861
commit edd6c85af7
8 changed files with 97 additions and 26 deletions

View file

@ -18,6 +18,8 @@ mod rust;
mod typescript;
mod yaml;
pub use installation::ensure_node_installation_dir;
// 1. Add tree-sitter-{language} parser to zed crate
// 2. Create a language directory in zed/crates/zed/src/languages and add the language to init function below
// 3. Add config.toml to the newly created language directory using existing languages as a template

View file

@ -1,9 +1,15 @@
use anyhow::{anyhow, Context, Result};
use async_compression::futures::bufread::GzipDecoder;
use async_tar::Archive;
use client::http::HttpClient;
use futures::{io::BufReader, StreamExt};
use serde::Deserialize;
use smol::fs::{self, File};
use smol::io::AsyncReadExt;
use std::{path::Path, sync::Arc};
use std::{
path::{Path, PathBuf},
sync::Arc,
};
pub struct GitHubLspBinaryVersion {
pub name: String,
@ -35,6 +41,40 @@ pub(crate) struct GithubReleaseAsset {
pub browser_download_url: String,
}
pub async fn ensure_node_installation_dir(http: Arc<dyn HttpClient>) -> Result<PathBuf> {
eprintln!("ensure_node_installation_dir");
let version = "v18.15.0";
let arch = "arm64";
let folder_name = format!("node-{version}-darwin-{arch}");
let node_containing_dir = dbg!(util::paths::SUPPORT_DIR.join("node"));
let node_dir = dbg!(node_containing_dir.join(folder_name));
let node_binary = node_dir.join("bin/node");
if fs::metadata(&node_binary).await.is_err() {
_ = fs::remove_dir_all(&node_containing_dir).await;
fs::create_dir(&node_containing_dir)
.await
.context("error creating node containing dir")?;
let url = format!("https://nodejs.org/dist/{version}/node-{version}-darwin-{arch}.tar.gz");
dbg!(&url);
let mut response = http
.get(&url, Default::default(), true)
.await
.context("error downloading Node binary tarball")?;
let decompressed_bytes = GzipDecoder::new(BufReader::new(response.body_mut()));
let archive = Archive::new(decompressed_bytes);
archive.unpack(&node_containing_dir).await?;
eprintln!("unpacked");
}
eprintln!("returning");
Ok(dbg!(node_dir))
}
pub async fn npm_package_latest_version(name: &str) -> Result<String> {
let output = smol::process::Command::new("npm")
.args(["-fetch-retry-mintimeout", "2000"])

View file

@ -81,6 +81,15 @@ fn main() {
})
};
let node_path = {
let http = http.clone();
app.background().spawn(async move {
languages::ensure_node_installation_dir(http.clone())
.await
.log_err()
})
};
let (cli_connections_tx, mut cli_connections_rx) = mpsc::unbounded();
let (open_paths_tx, mut open_paths_rx) = mpsc::unbounded();
app.on_open_urls(move |urls, _| {
@ -135,7 +144,7 @@ fn main() {
}
let client = client::Client::new(http.clone(), cx);
let mut languages = LanguageRegistry::new(login_shell_env_loaded);
let mut languages = LanguageRegistry::new(login_shell_env_loaded, node_path);
languages.set_executor(cx.background().clone());
languages.set_language_server_download_dir(paths::LANGUAGES_DIR.clone());
let languages = Arc::new(languages);

View file

@ -1846,7 +1846,7 @@ mod tests {
#[gpui::test]
fn test_bundled_languages(cx: &mut MutableAppContext) {
let mut languages = LanguageRegistry::new(Task::ready(()));
let mut languages = LanguageRegistry::test();
languages.set_executor(cx.background().clone());
let languages = Arc::new(languages);
let themes = ThemeRegistry::new((), cx.font_cache().clone());