Skip to content

Commit 9a97f29

Browse files
committed
Resolve conflicts
1 parent 583e3b0 commit 9a97f29

File tree

6 files changed

+33
-85
lines changed

6 files changed

+33
-85
lines changed

src/debugger.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
config::get_java_debug_jar,
1414
lsp::LspWrapper,
1515
util::{
16-
create_path_if_not_exists, get_curr_dir, mark_checked_once, path_to_quoted_string,
16+
create_path_if_not_exists, get_curr_dir, mark_checked_once, path_to_string,
1717
should_use_local_or_download,
1818
},
1919
};
@@ -157,7 +157,7 @@ impl Debugger {
157157

158158
download_file(
159159
JAVA_DEBUG_PLUGIN_FORK_URL,
160-
&path_to_quoted_string(jar_path.clone())?,
160+
&path_to_string(jar_path.clone())?,
161161
DownloadedFileType::Uncompressed,
162162
)
163163
.map_err(|err| {
@@ -264,7 +264,7 @@ impl Debugger {
264264

265265
download_file(
266266
url.as_str(),
267-
&path_to_quoted_string(&jar_path)?,
267+
&path_to_string(&jar_path)?,
268268
DownloadedFileType::Uncompressed,
269269
)
270270
.map_err(|err| format!("Failed to download {url} {err}"))?;

src/java.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::{
3232
try_to_fetch_and_install_latest_lombok,
3333
},
3434
lsp::LspWrapper,
35-
util::path_to_quoted_string,
35+
util::path_to_string,
3636
};
3737

3838
const PROXY_FILE: &str = include_str!("proxy.mjs");
@@ -279,17 +279,16 @@ impl Extension for Java {
279279
"--input-type=module".to_string(),
280280
"-e".to_string(),
281281
PROXY_FILE.to_string(),
282-
path_to_quoted_string(current_dir.clone())?,
282+
path_to_string(current_dir.clone())?,
283283
];
284284

285285
// Add lombok as javaagent if settings.java.jdt.ls.lombokSupport.enabled is true
286286
let lombok_jvm_arg = if is_lombok_enabled(&configuration) {
287287
let lombok_jar_path =
288288
self.lombok_jar_path(language_server_id, &configuration, worktree)?;
289-
let canonical_lombok_jar_path =
290-
path_to_quoted_string(current_dir.join(lombok_jar_path))?;
289+
let canonical_lombok_jar_path = path_to_string(current_dir.join(lombok_jar_path))?;
291290

292-
Some(format!("-javaagent:{canonical_lombok_jar_path}"))
291+
Some(format!("-javaagent:{}", canonical_lombok_jar_path))
293292
} else {
294293
None
295294
};

src/jdk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use zed_extension_api::{
77
};
88

99
use crate::util::{
10-
get_curr_dir, mark_checked_once, path_to_quoted_string, remove_all_files_except,
10+
get_curr_dir, mark_checked_once, path_to_string, remove_all_files_except,
1111
should_use_local_or_download,
1212
};
1313

@@ -108,7 +108,7 @@ pub fn try_to_fetch_and_install_latest_jdk(
108108

109109
download_file(
110110
build_corretto_url(&version, &platform, &arch).as_str(),
111-
path_to_quoted_string(install_path.clone())?.as_str(),
111+
path_to_string(install_path.clone())?.as_str(),
112112
match zed::current_platform().0 {
113113
Os::Windows => DownloadedFileType::Zip,
114114
_ => DownloadedFileType::GzipTar,

src/jdtls.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::{
1919
jdk::try_to_fetch_and_install_latest_jdk,
2020
util::{
2121
create_path_if_not_exists, get_curr_dir, get_java_exec_name, get_java_executable,
22-
get_java_major_version, get_latest_versions_from_tag, mark_checked_once,
23-
path_to_quoted_string, remove_all_files_except, should_use_local_or_download,
22+
get_java_major_version, get_latest_versions_from_tag, mark_checked_once, path_to_string,
23+
remove_all_files_except, should_use_local_or_download,
2424
},
2525
};
2626

@@ -66,14 +66,14 @@ pub fn build_jdtls_launch_args(
6666
let jdtls_data_path = get_jdtls_data_path(worktree)?;
6767

6868
let mut args = vec![
69-
path_to_quoted_string(java_executable)?,
69+
path_to_string(java_executable)?,
7070
"-Declipse.application=org.eclipse.jdt.ls.core.id1".to_string(),
7171
"-Dosgi.bundles.defaultStartLevel=4".to_string(),
7272
"-Declipse.product=org.eclipse.jdt.ls.core.product".to_string(),
7373
"-Dosgi.checkConfiguration=true".to_string(),
7474
format!(
7575
"-Dosgi.sharedConfiguration.area={}",
76-
path_to_quoted_string(shared_config_path)?
76+
path_to_string(shared_config_path)?
7777
),
7878
"-Dosgi.sharedConfiguration.area.readOnly=true".to_string(),
7979
"-Dosgi.configuration.cascaded=true".to_string(),
@@ -87,9 +87,9 @@ pub fn build_jdtls_launch_args(
8787
args.extend(jvm_args);
8888
args.extend(vec![
8989
"-jar".to_string(),
90-
path_to_quoted_string(jar_path)?,
90+
path_to_string(jar_path)?,
9191
"-data".to_string(),
92-
path_to_quoted_string(jdtls_data_path)?,
92+
path_to_string(jdtls_data_path)?,
9393
]);
9494
if java_major_version >= 24 {
9595
args.push("-Djdk.xml.maxGeneralEntitySizeLimit=0".to_string());
@@ -201,10 +201,10 @@ pub fn try_to_fetch_and_install_latest_jdtls(
201201
&format!(
202202
"https://www.eclipse.org/downloads/download.php?file=/jdtls/milestones/{latest_version}/{latest_version_build}"
203203
),
204-
path_to_quoted_string(build_path.clone())?.as_str(),
204+
path_to_string(build_path.clone())?.as_str(),
205205
DownloadedFileType::GzipTar,
206206
)?;
207-
make_file_executable(path_to_quoted_string(binary_path)?.as_str())?;
207+
make_file_executable(path_to_string(binary_path)?.as_str())?;
208208

209209
// ...and delete other versions
210210
let _ = remove_all_files_except(prefix, build_directory.as_str());
@@ -252,7 +252,7 @@ pub fn try_to_fetch_and_install_latest_lombok(
252252
create_path_if_not_exists(prefix)?;
253253
download_file(
254254
&format!("https://projectlombok.org/downloads/{jar_name}"),
255-
path_to_quoted_string(jar_path.clone())?.as_str(),
255+
path_to_string(jar_path.clone())?.as_str(),
256256
DownloadedFileType::Uncompressed,
257257
)?;
258258

src/proxy.mjs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ const args = process.argv.slice(3);
2828
const PROXY_ID = Buffer.from(process.cwd().replace(/\/+$/, "")).toString("hex");
2929
const PROXY_HTTP_PORT_FILE = join(workdir, "proxy", PROXY_ID);
3030
const isWindows = process.platform === "win32";
31-
const command = isWindows ? `"${bin}"` : bin;
31+
const command = (isWindows && bin.endsWith(".bat")) ? `"${bin}"` : bin;
3232

3333
const lsp = spawn(command, args, {
34-
shell: isWindows,
35-
detached: false
34+
shell: (isWindows && bin.endsWith(".bat")),
35+
detached: false,
3636
});
3737

3838
function cleanup() {
@@ -44,19 +44,18 @@ function cleanup() {
4444
// Windows: Use taskkill to kill the process tree (cmd.exe + the child)
4545
// /T = Tree kill (child processes), /F = Force
4646
exec(`taskkill /pid ${lsp.pid} /T /F`);
47-
}
48-
else {
49-
lsp.kill('SIGTERM');
47+
} else {
48+
lsp.kill("SIGTERM");
5049
setTimeout(() => {
5150
if (!lsp.killed && lsp.exitCode === null) {
52-
lsp.kill('SIGKILL');
51+
lsp.kill("SIGKILL");
5352
}
5453
}, 1000);
5554
}
5655
}
5756

5857
// Handle graceful IDE shutdown via stdin close
59-
process.stdin.on('end', () => {
58+
process.stdin.on("end", () => {
6059
cleanup();
6160
process.exit(0);
6261
});
@@ -71,7 +70,7 @@ setInterval(() => {
7170
} catch (e) {
7271
// On Windows, checking a process you don't own might throw EPERM.
7372
// We only want to kill if the error is ESRCH (No Such Process).
74-
if (e.code === 'ESRCH') {
73+
if (e.code === "ESRCH") {
7574
cleanup();
7675
process.exit(0);
7776
}

src/util.rs

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ pub fn get_java_exec_name() -> String {
216216
/// * [`java_executable`] can't be converted into a String
217217
/// * No major version can be determined
218218
pub fn get_java_major_version(java_executable: &PathBuf) -> zed::Result<u32> {
219-
let program =
220-
path_to_quoted_string(java_executable).map_err(|_| JAVA_EXEC_ERROR.to_string())?;
219+
let program = path_to_string(java_executable).map_err(|_| JAVA_EXEC_ERROR.to_string())?;
221220
let output_bytes = Command::new(program).arg("-version").output()?.stderr;
222221
let output = String::from_utf8(output_bytes).map_err(|e| e.to_string())?;
223222

@@ -287,45 +286,25 @@ fn get_tag_at(github_tags: &Value, index: usize) -> Option<&str> {
287286
})
288287
}
289288

290-
/// Formats a path string with platform-specific quoting.
291-
///
292-
/// On Windows, wraps the path in double quotes for shell mode compatibility.
293-
/// On Unix, returns the path unquoted since spawn() treats quotes as literals.
294-
fn format_path_for_os(path_str: String, os: Os) -> String {
295-
if os == Os::Windows {
296-
format!("\"{path_str}\"")
297-
} else {
298-
path_str
299-
}
300-
}
301-
302-
/// Converts a [`Path`] into a [`String`], with platform-specific quoting.
303-
///
304-
/// On Windows, the path is wrapped in double quotes (e.g., `"C:\path\to\file"`)
305-
/// for compatibility with shell mode. On Unix-like systems, the path is returned
306-
/// unquoted, as the proxy uses `spawn()` with `shell: false` which treats quotes
307-
/// as literal filename characters, causing "No such file or directory" errors.
289+
/// Converts a [`Path`] into a [`String`].
308290
///
309291
/// # Arguments
310292
///
311293
/// * `path` - The path of type `AsRef<Path>` to be converted.
312294
///
313295
/// # Returns
314296
///
315-
/// Returns a `String` representing the path, quoted on Windows, unquoted on Unix.
297+
/// Returns a `String` representing the path.
316298
///
317299
/// # Errors
318300
///
319-
/// This function will return an error when the string conversion fails
320-
pub fn path_to_quoted_string<P: AsRef<Path>>(path: P) -> zed::Result<String> {
321-
let path_str = path
322-
.as_ref()
301+
/// This function will return an error when the string conversion fails.
302+
pub fn path_to_string<P: AsRef<Path>>(path: P) -> zed::Result<String> {
303+
path.as_ref()
323304
.to_path_buf()
324305
.into_os_string()
325306
.into_string()
326-
.map_err(|_| PATH_TO_STR_ERROR.to_string())?;
327-
328-
Ok(format_path_for_os(path_str, current_platform().0))
307+
.map_err(|_| PATH_TO_STR_ERROR.to_string())
329308
}
330309

331310
/// Remove all files or directories that aren't equal to [`filename`].
@@ -422,32 +401,3 @@ pub fn should_use_local_or_download(
422401
CheckUpdates::Always => Ok(None),
423402
}
424403
}
425-
426-
#[cfg(test)]
427-
mod tests {
428-
use super::*;
429-
430-
#[test]
431-
fn test_format_path_for_os_windows() {
432-
let path = "C:\\Users\\User Name\\Projects\\zed-extension-java".to_string();
433-
let result = format_path_for_os(path, Os::Windows);
434-
assert_eq!(
435-
result,
436-
"\"C:\\Users\\User Name\\Projects\\zed-extension-java\""
437-
);
438-
}
439-
440-
#[test]
441-
fn test_format_path_for_os_unix() {
442-
let path = "/home/username/Projects/zed extension java".to_string();
443-
let result = format_path_for_os(path, Os::Mac);
444-
assert_eq!(result, "/home/username/Projects/zed extension java");
445-
}
446-
447-
#[test]
448-
fn test_format_path_for_os_linux() {
449-
let path = "/home/username/Projects/zed extension java".to_string();
450-
let result = format_path_for_os(path, Os::Linux);
451-
assert_eq!(result, "/home/username/Projects/zed extension java");
452-
}
453-
}

0 commit comments

Comments
 (0)