Skip to content

Commit

Permalink
Get debugpy version to work
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony-Eid committed Oct 20, 2024
1 parent 6735cfa commit 8674f10
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 37 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/dap_adapters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fs.workspace = true
futures.workspace = true
gpui.workspace = true
http_client.workspace = true
util.workspace = true
task.workspace = true
smol.workspace = true
serde.workspace = true
Expand Down
65 changes: 29 additions & 36 deletions crates/dap_adapters/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ impl DebugAdapter for PythonDebugAdapter {
) -> Result<DebugAdapterBinary> {
let adapter_path = paths::debug_adapters_dir().join(self.name());

let debugpy_dir = util::fs::find_file_name_in_dir(adapter_path.as_path(), |file_name| {
file_name.starts_with("debugpy_")
})
.await
.ok_or_else(|| anyhow!("Debugpy directory not found"))?;

Ok(DebugAdapterBinary {
command: "python3".to_string(),
arguments: Some(vec![adapter_path.join(Self::ADAPTER_PATH).into()]),
arguments: Some(vec![debugpy_dir.join(Self::ADAPTER_PATH).into()]),
envs: None,
})
}
Expand All @@ -58,7 +64,7 @@ impl DebugAdapter for PythonDebugAdapter {
let release =
latest_github_release("microsoft/debugpy", false, false, http_client.clone())
.await?;
let asset_name = format!("{}.zip", release.tag_name);
let asset_name = format!("{}_{}.zip", self.name(), release.tag_name);

let zip_path = debugpy_dir.join(asset_name);

Expand All @@ -78,42 +84,29 @@ impl DebugAdapter for PythonDebugAdapter {
.await?
.status;

let mut ls = process::Command::new("ls")
.current_dir(&debugpy_dir)
.stdout(Stdio::piped())
.spawn()?;

let std = ls
.stdout
.take()
.ok_or(anyhow!("Failed to list directories"))?
.into_stdio()
.await?;

let file_name = String::from_utf8(
process::Command::new("grep")
.arg("microsoft-debugpy")
.stdin(std)
.output()
.await?
.stdout,
)?;

let file_name = file_name.trim_end();
process::Command::new("sh")
.current_dir(&debugpy_dir)
.arg("-c")
.arg(format!("mv {file_name}/* ."))
.output()
let file_name =
util::fs::find_file_name_in_dir(&debugpy_dir.as_path(), |file_name| {
file_name.starts_with("microsoft-debugpy-")
})
.await
.ok_or_else(|| anyhow!("Debugpy unzipped directory not found"))?;

fs.rename(
file_name.as_path(),
debugpy_dir
.join(format!("{}_{}", self.name(), release.tag_name))
.as_path(),
Default::default(),
)
.await?;

fs.remove_file(&zip_path.as_path(), Default::default())
.await?;

process::Command::new("rm")
.current_dir(&debugpy_dir)
.arg("-rf")
.arg(file_name)
.arg(zip_path)
.output()
.await?;
// if !unzip_status.success() {
// dbg!(unzip_status);
// Err(anyhow!("failed to unzip debugpy archive"))?;
// }

return Ok(());
}
Expand Down
23 changes: 22 additions & 1 deletion crates/util/src/fs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::Path;
use std::path::{Path, PathBuf};

use crate::ResultExt;
use async_fs as fs;
Expand Down Expand Up @@ -26,3 +26,24 @@ where
}
}
}

pub async fn find_file_name_in_dir<F>(dir: &Path, predicate: F) -> Option<PathBuf>
where
F: Fn(&str) -> bool,
{
if let Some(mut entries) = fs::read_dir(dir).await.log_err() {
while let Some(entry) = entries.next().await {
if let Some(entry) = entry.log_err() {
let entry_path = entry.path();

if let Some(file_name) = entry_path.file_name() {
if predicate(file_name.to_str().unwrap_or("")) {
return Some(entry_path);
}
}
}
}
}

None
}

0 comments on commit 8674f10

Please sign in to comment.