-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could not install the Go language server 'gopls', because 'Go' was not found #9786
Comments
Hey! Thanks for the ticket. The interesting line is this one here:
When we launch your How do you setup your |
I have the following in my .zshrc
I ran the same command to detect the environment and have this for the PATH
|
I also tried changing my default shell to bash, but that didn't make a difference. Logs below 2024-03-26T13:15:22-05:00 [INFO] set environment variables from shell:/bin/bash, path:/usr/bin:/bin:/usr/sbin:/sbin |
Huh. Okay, this is very interesting. I don't understand why that PATH is not picked up. What do you get when you run the following?
|
Another question: how do you launch Zed? Do you click on the icon in the Dock, do you use the Also, if you want, feel free to book some time in my Zed office hour, if you want to debug this together: https://calendly.com/thorsten-ball-zed/zed-office-hour |
I launch Zed from the icon in the dock. I scheduled some time on Friday. Is there anything I should prepare in advance (tools, clone zed source, etc)? |
Great!
It'd be great if you could get Zed to a point where you can run from source with What we need to debug is this code here: Lines 887 to 941 in 5a2a85a
We can also already start debugging this by running a modified version:
fn main() {
let marker = "ZED_LOGIN_SHELL_START";
let shell = std::env::var("SHELL").expect(
"SHELL environment variable is not assigned so we can't source login environment variables",
);
// If possible, we want to `cd` in the user's `$HOME` to trigger programs
// such as direnv, asdf, mise, ... to adjust the PATH. These tools often hook
// into shell's `cd` command (and hooks) to manipulate env.
// We do this so that we get the env a user would have when spawning a shell
// in home directory.
let shell_cmd_prefix = std::env::var_os("HOME")
.and_then(|home| home.into_string().ok())
.map(|home| format!("cd '{home}';"));
// The `exit 0` is the result of hours of debugging, trying to find out
// why running this command here, without `exit 0`, would mess
// up signal process for our process so that `ctrl-c` doesn't work
// anymore.
// We still don't know why `$SHELL -l -i -c '/usr/bin/env -0'` would
// do that, but it does, and `exit 0` helps.
let shell_cmd = format!(
"{}echo {marker}; /usr/bin/env -0; exit 0;",
shell_cmd_prefix.as_deref().unwrap_or("")
);
let output = std::process::Command::new(&shell)
.args(["-l", "-i", "-c", &shell_cmd])
.output()
.expect("failed to start process");
if !output.status.success() {
panic!("login shell exited with error");
}
let stdout = String::from_utf8_lossy(&output.stdout);
if let Some(env_output_start) = stdout.find(marker) {
let env_output = &stdout[env_output_start + marker.len()..];
for line in env_output.split_terminator('\0') {
if let Some(separator_index) = line.find('=') {
let key = &line[..separator_index];
let value = &line[separator_index + 1..];
println!("key={:?}, value={:?}", key, value);
}
}
}
}
|
After writing my comment up here (which is still valid! and I'm still curious about your results), I realized that there is a bug in the code: it does not remove the It could be that in your setup the first variable was I opened a PR with a fix that should go in regardless: #10105 Maybe it fixes the issue for you, maybe it doesn't. Preview release goes out today, so we can confirm after that. |
Previously this code would run the changed commend, take its output, remove the `marker` from the front and then split on `0` byte. Problem was that `echo` adds a newline, which we did *NOT* skip. So whatever `env` printed as the first environment variable would have a `\n` in front of it. Instead of setting, say, `HOME`, Zed would set `\nHOME`. This change fixes the issue by switching to `printf '%s' marker`, which is more portable than using `echo -n`. This is related to #9786 but I'm not sure yet whether that fixes it. Release Notes: - Fixed Zed sometimes missing environment variables from shell in case they were the first environment variable listed by `/usr/bin/env`.
Awesome. I'll clone the repo and debug locally with the version prior to your commit. |
I ran the sample |
You mean as part of
So with the code that's on |
On the CLI |
This fixes #9786 by using an invocation of `/usr/bin/env` that's supported by macOS 12. As it turns out, on macOS 12 (and maybe 13?) `/usr/bin/env` doesn't support the `-0` flag. In our case it would silently fail, since we `exit 0` in our shell invocation and because the program we run and whose exit code we check is the `$SHELL` and not `/usr/bin/env`. What this change does is to drop the `-0` and instead split the environment on `\n`. This works even if an environment variable contains a newline character because that would then be escaped. Co-authored-by: Dave Smith <davesmithsemail@gmail.com>
This fixes #9786 by using an invocation of `/usr/bin/env` that's supported by macOS 12. As it turns out, on macOS 12 (and maybe 13?) `/usr/bin/env` doesn't support the `-0` flag. In our case it would silently fail, since we `exit 0` in our shell invocation and because the program we run and whose exit code we check is the `$SHELL` and not `/usr/bin/env`. What this change does is to drop the `-0` and instead split the environment on `\n`. This works even if an environment variable contains a newline character because that would then be escaped. Release Notes: - Fixed Zed not picking up shell environments correctly when running on macOS 12. ([#9786](#9786)). Co-authored-by: Dave Smith <davesmithsemail@gmail.com>
Upgrading from macOS 12 to 14 fixed the issue on my computer with |
Strangely got go working just fine once with Now I get the same error as in the OP, but I am using $ which go
/usr/local/go/bin/go
$ env -i HOME="$HOME" /bin/bash -i -l -c 'cd ~/; /usr/bin/env' | grep PATH
PATH=/home/<user>/.local/bin:/home/<user>/.bun/bin:/home/<user>/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/home/<user>/go/bin:/home/<user>/.foundry/bin
Opening from a terminal with |
Hmmm, anything in the logs? When you launch Zed from a shortcut, we should launch a login shell internally and get the |
This is SUPER weird. I'm experiencing the exact same behaviour as @nuke-web3 . When launching zed from terminal, it does get I'm on macos 15.2. I've spent the last 4 hours debugging my env variables but no luck. Any suggestion @mrnugget ? |
+1 Fresh install Linux Mint with bash; go and gopls installed and in path (via export in .bashrc). It works when launched from the terminal (zed .), fails when launched from the shortcut in the system dock. |
I'll just repeat the question: anything in the logs? I specifically put log statements in there to debug issues like this. |
So, I managed to get zed working correctly for golang, but took quite some work. System Versions:
Issue:
How I fixed it:
Doing so, ended up fixing the issue. I came to the conclusion that |
Ah, Logs would be helpful, yes! |
Yes, @mrnugget there is something relevant in the logs:
which shows that gopls is not in the path because the $PATH is not the same as the one I have in bash. > echo $PATH
/home/user/.cargo/bin:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/home/user/go/bin:/home/user/.local/bin The last three entries are injected by my
It looks like when loading the environment (with the default shell on my Linux Mint box) it does not take into account |
Thanks for the logs! This line is interesting:
You're on Linux, right? I think on Linux, we always treat the environment we get when the app launches as immutable and use that. How do you launch the app? I assume it wasn't from the "real" CLI. If you run this, what do you get?
I assume |
Also:
Can I see how that shortcut is configured? |
OK, @mrnugget here's (the first batch of) the requested info:
user@mypc:~$ env -i HOME="$HOME" /bin/bash -i -l -c 'cd ~/; /usr/bin/env' | grep PATH
PATH=/home/user/.local/bin:/home/user/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/usr/local/go/bin:/home/user/go/bin:/home/user/.local/bin (mildly edited to hide my PC name (mypc) and my username (user)). |
So @mrnugget this is a dump of the environment, command line args, current directory and current user when launched via the Cinnamon Panel:
The path does not contain the Golang directories, so Zed is working correctly. I'm checking if and how to let graphical application see custom PATH entries. |
Uh, and by the way:
|
OK, so I fixed it by adding custom PATH entries in my |
Thank you so much for the investigation and the help here! I really appreciate it.
I'm not sure yet. Ideally we could detect whether Zed was launched via the CLI or the desktop launcher. I'm also not sure why we launch our Zed CLI binary from the desktop launcher, I think that's been recently changed. If you change the panel entry to launch this binary instead: Or maybe we should detect whether there's a |
Hi @mrnugget I tried with your suggested approach, edited the
then reverted my
Zed picks the correct shell ( Why did you create the Hope this helps. |
I think there might have been some confusion and this might not have been intentional. Taking a look. |
Ah, the reason we have that is because the CLI handles URLs and accepts args, whereas |
Hmmm, so it looks like there is no way out apart from setting the relevant env vars in |
Check for existing issues
Describe the bug / provide steps to reproduce it
When opening Zed with an existing Go project, I get the error message
Could not install the Go language server 'gopls', because 'Go' was not found
I have Go
go version go1.21.6 darwin/amd64
installed and in the pathTagging @mrnugget from our conversation on Twitter
Environment
Zed: v0.127.4 (Zed)
OS: macOS 12.0.1
Memory: 16 GiB
Architecture: x86_64
Path:
Go:
If applicable, add mockups / screenshots to help explain present your vision of the feature
No response
If applicable, attach your
~/Library/Logs/Zed/Zed.log
file to this issue.2024-03-25T12:54:31-05:00 [INFO] ========== starting zed ==========
2024-03-25T12:54:31-05:00 [INFO] Opening main db
2024-03-25T12:54:31-05:00 [ERROR] crates/zed/src/zed.rs:615: EOF while parsing a value at line 1 column 0
2024-03-25T12:54:31-05:00 [INFO] Opening main db
2024-03-25T12:54:31-05:00 [INFO] building git repository,
.git
path in the worktree: ".git"2024-03-25T12:54:31-05:00 [INFO] Opening main db
2024-03-25T12:54:31-05:00 [INFO] Opening main db
2024-03-25T12:54:31-05:00 [INFO] set status on client 0: Authenticating
2024-03-25T12:54:31-05:00 [INFO] set status on client 143999: Connecting
2024-03-25T12:54:31-05:00 [INFO] starting language server "gopls", path: "/Users/dave/git/1brc-go", id: 1
2024-03-25T12:54:31-05:00 [INFO] Node runtime install_if_needed
2024-03-25T12:54:31-05:00 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-03-25T12:54:32-05:00 [INFO] set environment variables from shell:/bin/zsh, path:/usr/bin:/bin:/usr/sbin:/sbin
2024-03-25T12:54:32-05:00 [INFO] add connection to peer
2024-03-25T12:54:32-05:00 [INFO] waiting for server hello
2024-03-25T12:54:32-05:00 [INFO] got server hello
2024-03-25T12:54:32-05:00 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 378, id: 943380 })
2024-03-25T12:54:32-05:00 [INFO] set status on client 143999: Connected { peer_id: PeerId { owner_id: 378, id: 943380 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-03-25T12:54:32-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:32-05:00 [INFO] starting language server. binary path: "/Users/dave/Library/Application Support/Zed/node/node-v18.15.0-darwin-x64/bin/node", working directory: "/", args: ["/Users/dave/Library/Application Support/Zed/copilot/copilot-v0.5.0/dist/agent.js", "--stdio"]
2024-03-25T12:54:32-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:32-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:33-05:00 [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
"level": 0,
"message": "[DEBUG] [agent] [2024-03-25T17:54:33.012Z] Agent service starting",
"metadataStr": "[DEBUG] [agent] [2024-03-25T17:54:33.012Z]",
"extra": [
"Agent service starting"
]
}
2024-03-25T12:54:33-05:00 [INFO] Language server with id 0 sent unhandled notification client/registerCapability:
{
"registrations": [
{
"id": "5d57184d-3a6e-462b-952c-10c13f0f5659",
"method": "workspace/didChangeWorkspaceFolders",
"registerOptions": {}
}
]
}
2024-03-25T12:54:33-05:00 [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
"level": 0,
"message": "[DEBUG] [agent] [2024-03-25T17:54:33.045Z] Telemetry initialized",
"metadataStr": "[DEBUG] [agent] [2024-03-25T17:54:33.045Z]",
"extra": [
"Telemetry initialized"
]
}
2024-03-25T12:54:33-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:33-05:00 [ERROR] failed to start language server "gopls": cannot install gopls
2024-03-25T12:54:33-05:00 [ERROR] server stderr: Some("")
2024-03-25T12:54:33-05:00 [INFO] retrying installation of language server "gopls" in 1s
2024-03-25T12:54:33-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:34-05:00 [ERROR] crates/languages/src/go.rs:393: no cached binary
2024-03-25T12:54:34-05:00 [INFO] About to spawn test binary
2024-03-25T12:54:34-05:00 [WARN] test binary failed to launch
2024-03-25T12:54:34-05:00 [WARN] test binary check failed
2024-03-25T12:54:34-05:00 [INFO] beginning to reinstall server
2024-03-25T12:54:34-05:00 [INFO] deleting server container
2024-03-25T12:54:34-05:00 [INFO] starting language server "gopls", path: "/Users/dave/git/1brc-go", id: 2
2024-03-25T12:54:35-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:35-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:35-05:00 [ERROR] failed to start language server "gopls": cannot install gopls
2024-03-25T12:54:35-05:00 [ERROR] server stderr: Some("")
2024-03-25T12:54:35-05:00 [INFO] retrying installation of language server "gopls" in 1s
2024-03-25T12:54:36-05:00 [ERROR] crates/languages/src/go.rs:393: no cached binary
2024-03-25T12:54:36-05:00 [INFO] About to spawn test binary
2024-03-25T12:54:36-05:00 [WARN] test binary failed to launch
2024-03-25T12:54:36-05:00 [WARN] test binary check failed
2024-03-25T12:54:36-05:00 [INFO] beginning to reinstall server
2024-03-25T12:54:36-05:00 [INFO] deleting server container
2024-03-25T12:54:36-05:00 [INFO] starting language server "gopls", path: "/Users/dave/git/1brc-go", id: 3
2024-03-25T12:54:37-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:38-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:38-05:00 [ERROR] failed to start language server "gopls": cannot install gopls
2024-03-25T12:54:38-05:00 [ERROR] server stderr: Some("")
2024-03-25T12:54:38-05:00 [INFO] retrying installation of language server "gopls" in 1s
2024-03-25T12:54:39-05:00 [ERROR] crates/languages/src/go.rs:393: no cached binary
2024-03-25T12:54:39-05:00 [INFO] About to spawn test binary
2024-03-25T12:54:39-05:00 [WARN] test binary failed to launch
2024-03-25T12:54:39-05:00 [WARN] test binary check failed
2024-03-25T12:54:39-05:00 [INFO] beginning to reinstall server
2024-03-25T12:54:39-05:00 [INFO] deleting server container
2024-03-25T12:54:39-05:00 [INFO] starting language server "gopls", path: "/Users/dave/git/1brc-go", id: 4
2024-03-25T12:54:39-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:40-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:40-05:00 [ERROR] failed to start language server "gopls": cannot install gopls
2024-03-25T12:54:40-05:00 [ERROR] server stderr: Some("")
2024-03-25T12:54:40-05:00 [INFO] retrying installation of language server "gopls" in 1s
2024-03-25T12:54:41-05:00 [ERROR] crates/languages/src/go.rs:393: no cached binary
2024-03-25T12:54:41-05:00 [INFO] About to spawn test binary
2024-03-25T12:54:41-05:00 [WARN] test binary failed to launch
2024-03-25T12:54:41-05:00 [WARN] test binary check failed
2024-03-25T12:54:41-05:00 [INFO] beginning to reinstall server
2024-03-25T12:54:41-05:00 [INFO] deleting server container
2024-03-25T12:54:41-05:00 [INFO] starting language server "gopls", path: "/Users/dave/git/1brc-go", id: 5
2024-03-25T12:54:42-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:42-05:00 [INFO] reload git repository ".git"
2024-03-25T12:54:42-05:00 [ERROR] failed to start language server "gopls": cannot install gopls
2024-03-25T12:54:42-05:00 [ERROR] server stderr: Some("")
2024-03-25T12:54:42-05:00 [ERROR] Hit 4 reinstallation attempts for "gopls"
The text was updated successfully, but these errors were encountered: