Fix unzipping clangd and codelldb on Windows (#31080)
Closes https://github.com/zed-industries/zed/pull/30454 Release Notes: - N/A
This commit is contained in:
parent
c8f56e38b1
commit
6e5996a815
19 changed files with 93 additions and 70 deletions
|
@ -7,9 +7,9 @@ pub use language::*;
|
|||
use lsp::{DiagnosticTag, InitializeParams, LanguageServerBinary, LanguageServerName};
|
||||
use project::lsp_store::clangd_ext;
|
||||
use serde_json::json;
|
||||
use smol::fs::{self, File};
|
||||
use smol::{fs, io::BufReader};
|
||||
use std::{any::Any, env::consts, path::PathBuf, sync::Arc};
|
||||
use util::{ResultExt, fs::remove_matching, maybe, merge_json_value_into};
|
||||
use util::{ResultExt, archive::extract_zip, fs::remove_matching, maybe, merge_json_value_into};
|
||||
|
||||
pub struct CLspAdapter;
|
||||
|
||||
|
@ -32,7 +32,7 @@ impl super::LspAdapter for CLspAdapter {
|
|||
let path = delegate.which(Self::SERVER_NAME.as_ref()).await?;
|
||||
Some(LanguageServerBinary {
|
||||
path,
|
||||
arguments: vec![],
|
||||
arguments: Vec::new(),
|
||||
env: None,
|
||||
})
|
||||
}
|
||||
|
@ -69,7 +69,6 @@ impl super::LspAdapter for CLspAdapter {
|
|||
delegate: &dyn LspAdapterDelegate,
|
||||
) -> Result<LanguageServerBinary> {
|
||||
let version = version.downcast::<GitHubLspBinaryVersion>().unwrap();
|
||||
let zip_path = container_dir.join(format!("clangd_{}.zip", version.name));
|
||||
let version_dir = container_dir.join(format!("clangd_{}", version.name));
|
||||
let binary_path = version_dir.join("bin/clangd");
|
||||
|
||||
|
@ -79,28 +78,31 @@ impl super::LspAdapter for CLspAdapter {
|
|||
.get(&version.url, Default::default(), true)
|
||||
.await
|
||||
.context("error downloading release")?;
|
||||
let mut file = File::create(&zip_path).await?;
|
||||
anyhow::ensure!(
|
||||
response.status().is_success(),
|
||||
"download failed with status {}",
|
||||
response.status().to_string()
|
||||
);
|
||||
futures::io::copy(response.body_mut(), &mut file).await?;
|
||||
|
||||
let unzip_status = util::command::new_smol_command("unzip")
|
||||
.current_dir(&container_dir)
|
||||
.arg(&zip_path)
|
||||
.output()
|
||||
.await?
|
||||
.status;
|
||||
anyhow::ensure!(unzip_status.success(), "failed to unzip clangd archive");
|
||||
extract_zip(&container_dir, BufReader::new(response.body_mut()))
|
||||
.await
|
||||
.with_context(|| format!("unzipping clangd archive to {container_dir:?}"))?;
|
||||
remove_matching(&container_dir, |entry| entry != version_dir).await;
|
||||
|
||||
// todo("windows")
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
fs::set_permissions(
|
||||
&binary_path,
|
||||
<fs::Permissions as fs::unix::PermissionsExt>::from_mode(0o755),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(LanguageServerBinary {
|
||||
path: binary_path,
|
||||
env: None,
|
||||
arguments: vec![],
|
||||
arguments: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -306,7 +308,7 @@ impl super::LspAdapter for CLspAdapter {
|
|||
.map(move |diag| {
|
||||
let range =
|
||||
language::range_to_lsp(diag.range.to_point_utf16(&snapshot)).unwrap();
|
||||
let mut tags = vec![];
|
||||
let mut tags = Vec::with_capacity(1);
|
||||
if diag.diagnostic.is_unnecessary {
|
||||
tags.push(DiagnosticTag::UNNECESSARY);
|
||||
}
|
||||
|
@ -344,7 +346,7 @@ async fn get_cached_server_binary(container_dir: PathBuf) -> Option<LanguageServ
|
|||
Ok(LanguageServerBinary {
|
||||
path: clangd_bin,
|
||||
env: None,
|
||||
arguments: vec![],
|
||||
arguments: Vec::new(),
|
||||
})
|
||||
})
|
||||
.await
|
||||
|
|
|
@ -26,7 +26,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
use task::{TaskTemplate, TaskTemplates, VariableName};
|
||||
use util::{ResultExt, fs::remove_matching, maybe, merge_json_value_into};
|
||||
use util::{ResultExt, archive::extract_zip, fs::remove_matching, maybe, merge_json_value_into};
|
||||
|
||||
const SERVER_PATH: &str =
|
||||
"node_modules/vscode-langservers-extracted/bin/vscode-json-language-server";
|
||||
|
@ -429,7 +429,7 @@ impl LspAdapter for NodeVersionAdapter {
|
|||
.await
|
||||
.context("downloading release")?;
|
||||
if version.url.ends_with(".zip") {
|
||||
node_runtime::extract_zip(
|
||||
extract_zip(
|
||||
&destination_container_path,
|
||||
BufReader::new(response.body_mut()),
|
||||
)
|
||||
|
|
|
@ -22,6 +22,7 @@ use std::{
|
|||
sync::{Arc, LazyLock},
|
||||
};
|
||||
use task::{TaskTemplate, TaskTemplates, TaskVariables, VariableName};
|
||||
use util::archive::extract_zip;
|
||||
use util::merge_json_value_into;
|
||||
use util::{ResultExt, fs::remove_matching, maybe};
|
||||
|
||||
|
@ -215,14 +216,11 @@ impl LspAdapter for RustLspAdapter {
|
|||
})?;
|
||||
}
|
||||
AssetKind::Zip => {
|
||||
node_runtime::extract_zip(
|
||||
&destination_path,
|
||||
BufReader::new(response.body_mut()),
|
||||
)
|
||||
.await
|
||||
.with_context(|| {
|
||||
format!("unzipping {} to {:?}", version.url, destination_path)
|
||||
})?;
|
||||
extract_zip(&destination_path, BufReader::new(response.body_mut()))
|
||||
.await
|
||||
.with_context(|| {
|
||||
format!("unzipping {} to {:?}", version.url, destination_path)
|
||||
})?;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
use task::{TaskTemplate, TaskTemplates, VariableName};
|
||||
use util::archive::extract_zip;
|
||||
use util::{ResultExt, fs::remove_matching, maybe};
|
||||
|
||||
pub(super) fn typescript_task_context() -> ContextProviderWithTasks {
|
||||
|
@ -514,14 +515,11 @@ impl LspAdapter for EsLintLspAdapter {
|
|||
})?;
|
||||
}
|
||||
AssetKind::Zip => {
|
||||
node_runtime::extract_zip(
|
||||
&destination_path,
|
||||
BufReader::new(response.body_mut()),
|
||||
)
|
||||
.await
|
||||
.with_context(|| {
|
||||
format!("unzipping {} to {:?}", version.url, destination_path)
|
||||
})?;
|
||||
extract_zip(&destination_path, BufReader::new(response.body_mut()))
|
||||
.await
|
||||
.with_context(|| {
|
||||
format!("unzipping {} to {:?}", version.url, destination_path)
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue