zed2: Actually find downloaded binary in Elixir cached binary method

This commit is contained in:
Julia 2023-11-06 11:31:31 -05:00
parent dbdb5f6519
commit 66b967532f

View file

@ -140,8 +140,8 @@ impl LspAdapter for ElixirLspAdapter {
) -> Result<LanguageServerBinary> { ) -> Result<LanguageServerBinary> {
let version = version.downcast::<GitHubLspBinaryVersion>().unwrap(); let version = version.downcast::<GitHubLspBinaryVersion>().unwrap();
let zip_path = container_dir.join(format!("elixir-ls_{}.zip", version.name)); let zip_path = container_dir.join(format!("elixir-ls_{}.zip", version.name));
let version_dir = container_dir.join(format!("elixir-ls_{}", version.name)); let folder_path = container_dir.join("elixir-ls");
let binary_path = version_dir.join("language_server.sh"); let binary_path = folder_path.join("language_server.sh");
if fs::metadata(&binary_path).await.is_err() { if fs::metadata(&binary_path).await.is_err() {
let mut response = delegate let mut response = delegate
@ -160,13 +160,13 @@ impl LspAdapter for ElixirLspAdapter {
} }
futures::io::copy(response.body_mut(), &mut file).await?; futures::io::copy(response.body_mut(), &mut file).await?;
fs::create_dir_all(&version_dir) fs::create_dir_all(&folder_path)
.await .await
.with_context(|| format!("failed to create directory {}", version_dir.display()))?; .with_context(|| format!("failed to create directory {}", folder_path.display()))?;
let unzip_status = smol::process::Command::new("unzip") let unzip_status = smol::process::Command::new("unzip")
.arg(&zip_path) .arg(&zip_path)
.arg("-d") .arg("-d")
.arg(&version_dir) .arg(&folder_path)
.output() .output()
.await? .await?
.status; .status;
@ -174,7 +174,7 @@ impl LspAdapter for ElixirLspAdapter {
Err(anyhow!("failed to unzip elixir-ls archive"))?; Err(anyhow!("failed to unzip elixir-ls archive"))?;
} }
remove_matching(&container_dir, |entry| entry != version_dir).await; remove_matching(&container_dir, |entry| entry != folder_path).await;
} }
Ok(LanguageServerBinary { Ok(LanguageServerBinary {
@ -285,20 +285,16 @@ impl LspAdapter for ElixirLspAdapter {
async fn get_cached_server_binary_elixir_ls( async fn get_cached_server_binary_elixir_ls(
container_dir: PathBuf, container_dir: PathBuf,
) -> Option<LanguageServerBinary> { ) -> Option<LanguageServerBinary> {
(|| async move { let server_path = container_dir.join("elixir-ls/language_server.sh");
let mut last = None; if server_path.exists() {
let mut entries = fs::read_dir(&container_dir).await?; Some(LanguageServerBinary {
while let Some(entry) = entries.next().await { path: server_path,
last = Some(entry?.path());
}
last.map(|path| LanguageServerBinary {
path,
arguments: vec![], arguments: vec![],
}) })
.ok_or_else(|| anyhow!("no cached binary")) } else {
})() log::error!("missing executable in directory {:?}", server_path);
.await None
.log_err() }
} }
pub struct NextLspAdapter; pub struct NextLspAdapter;