Skip to content

Cannot exectue system command #21841

Open
@Enaium

Description

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

I'm implementing a language server command builder.

use zed_extension_api::{self as zed, LanguageServerId, Result};

struct MyExtension {}

impl zed::Extension for MyExtension {
    fn new() -> Self {
        Self {}
    }

    fn language_server_command(
        &mut self,
        language_server_id: &LanguageServerId,
        worktree: &zed::Worktree,
    ) -> Result<zed::Command> {
        Ok(zed::Command {
            command: String::from("java"),
            args: vec![
                String::from("-cp"),
                String::from("C:/Users/enaium/my-language/server.jar"),
                String::from("cn.enaium.MainKt"),
            ],
            env: vec![(String::from(""), String::from(""))],
        })
    }
}

zed::register_extension!(MyExtension);

But Zed will use the work\my-extension as a Java path.

Environment

Windows 11

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log
2024-12-11T15:00:29.8650324+08:00 [INFO] starting language server process. binary path: "C:\\Users\\enaium\\AppData\\Local\\Zed\\extensions\\work\\my-extension\\java"
2024-12-11T15:00:29.8659378+08:00 [ERROR] Failed to start language server "my-language": failed to spawn command. path: "C:\\Users\\enaium\\AppData\\Local\\Zed\\extensions\\work\\my-extension\\java",
2024-12-11T15:00:29.8660027+08:00 [ERROR] server stderr: ""

Activity

added
admin readPending admin review
bug[core label]
triageMaintainer needs to classify the issue
on Dec 11, 2024
RemcoSmitsDev

RemcoSmitsDev commented on Dec 11, 2024

@RemcoSmitsDev
Contributor

I believe there is a method called which onworktree variable that you can use to find the binary path of java.

Enaium

Enaium commented on Dec 12, 2024

@Enaium
Author

command: worktree.which("java").unwrap()
command: format!("'{}'", worktree.which("java").unwrap())

My Java path has space and it still uses the work\my-extension path when I wrapper the Java path.

2024-12-12T09:11:15.879259+08:00 [ERROR] Failed to start language server "my-language": failed to spawn command. path: "C:\\Users\\enaium\\AppData\\Local\\Zed\\extensions\\work\\my-extension\\\'C:\\Program Files\\BellSoft\\LibericaJDK-21-Full\\bin\\java.exe\'",

Enaium

Enaium commented on Dec 12, 2024

@Enaium
Author

I tried execute Java command by PowerShell.

        Ok(zed::Command {
            command: worktree.which("powershell").unwrap(),
            args: vec![
                String::from("/c"),
                String::from("java"),
                String::from("-cp"),
                String::from("C:/Users/enaium/my-language/server.jar"),
                String::from("cn.enaium.MainKt"),
            ],
            env: vec![(String::from(""), String::from(""))],
        })
2024-12-12T09:24:33.0232512+08:00 [INFO] starting language server process. binary path: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", working directory: "C:\\Users\\enaium\\Desktop\\Projects\\test", args: ["/c", "java", "-cp", "C:/Users/enaium/my-language/server.jar", "cn.enaium.MainKt"]
2024-12-12T09:24:33.0240155+08:00 [ERROR] Failed to start language server "my-language": failed to spawn command. path: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", working directory: "C:\\Users\\enaium\\Desktop\\Projects\\test", args: ["/c", "java", "-cp", "C:/Users/enaium/my-language/server.jar", "cn.enaium.MainKt"]
2024-12-12T09:24:33.0240798+08:00 [ERROR] server stderr: ""
added
language serverAn umbrella label for all language servers
extension infrastructureFeedback for extensions APIs, creation, management, etc
and removed
triageMaintainer needs to classify the issue
admin readPending admin review
on Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bug[core label]extension infrastructureFeedback for extensions APIs, creation, management, etclanguage serverAn umbrella label for all language serverswindows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Cannot exectue system command · Issue #21841 · zed-industries/zed