Skip to content

Commit d896abe

Browse files
authored
129 fix debugger path (#130)
Fixes #129 Previously non-existing debugger path would error and not download the debugger due to remove_dir_all failing on nonexistent directory.
1 parent 68afc38 commit d896abe

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[package]
33
name = "zed_java"
4-
version = "6.7.0"
4+
version = "6.7.1"
55
edition = "2024"
66
publish = false
77
license = "Apache-2.0"

extension.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
id = "java"
22
name = "Java"
3-
version = "6.7.0"
3+
version = "6.7.1"
44
schema_version = 1
55
authors = [
66
"Valentine Briese <[email protected]>",

src/debugger.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use zed_extension_api::{
1111

1212
use crate::{
1313
lsp::LspWrapper,
14-
util::{get_curr_dir, path_to_string},
14+
util::{create_path_if_not_exists, get_curr_dir, path_to_string},
1515
};
1616

1717
#[derive(Serialize, Deserialize, Debug)]
@@ -104,8 +104,7 @@ impl Debugger {
104104
return Ok(path.clone());
105105
}
106106

107-
fs::remove_dir_all(prefix).map_err(|err| err.to_string())?;
108-
fs::create_dir(prefix).map_err(|err| err.to_string())?;
107+
create_path_if_not_exists(prefix)?;
109108

110109
download_file(
111110
JAVA_DEBUG_PLUGIN_FORK_URL,

src/util.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use std::{
55
path::{Path, PathBuf},
66
};
77
use zed_extension_api::{
8-
self as zed, Command, LanguageServerId, Os, Worktree, current_platform, serde_json::Value,
9-
http_client::{HttpMethod, HttpRequest, fetch}
8+
self as zed, Command, LanguageServerId, Os, Worktree, current_platform,
9+
http_client::{HttpMethod, HttpRequest, fetch},
10+
serde_json::Value,
1011
};
1112

1213
use crate::{
@@ -28,6 +29,33 @@ const TAG_RETRIEVAL_ERROR: &str = "Failed to fetch GitHub tags";
2829
const TAG_RESPONSE_ERROR: &str = "Failed to deserialize GitHub tags response";
2930
const TAG_UNEXPECTED_FORMAT_ERROR: &str = "Malformed GitHub tags response";
3031

32+
/// Create a Path if it does not exist
33+
///
34+
/// **Errors** if a file that is not a path exists at the location or read/write access failed for the location
35+
///
36+
///# Arguments
37+
/// * [`path`] the path to create
38+
///
39+
///# Returns
40+
///
41+
/// Ok(()) if the path exists or was created successfully
42+
pub fn create_path_if_not_exists<P: AsRef<Path>>(path: P) -> zed::Result<()> {
43+
let path_ref = path.as_ref();
44+
match fs::metadata(path_ref) {
45+
Ok(metadata) => {
46+
if metadata.is_dir() {
47+
Ok(())
48+
} else {
49+
Err(format!("File exists but is not a path: {:?}", path_ref))
50+
}
51+
}
52+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
53+
fs::create_dir_all(path_ref).map_err(|e| e.to_string())
54+
}
55+
Err(e) => Err(e.to_string()),
56+
}
57+
}
58+
3159
/// Expand ~ on Unix-like systems
3260
///
3361
/// # Arguments

0 commit comments

Comments
 (0)