Skip to content
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

Closed
1 task done
Dave-Smith opened this issue Mar 25, 2024 · 34 comments · Fixed by #10202
Closed
1 task done

Could not install the Go language server 'gopls', because 'Go' was not found #9786

Dave-Smith opened this issue Mar 25, 2024 · 34 comments · Fixed by #10202
Labels
bug [core label] go Go programming language support language An umbrella label for all programming languages syntax behaviors

Comments

@Dave-Smith
Copy link
Contributor

Check for existing issues

  • Completed

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

image

I have Go go version go1.21.6 darwin/amd64 installed and in the path

Tagging @mrnugget from our conversation on Twitter

Environment

Zed: v0.127.4 (Zed)
OS: macOS 12.0.1
Memory: 16 GiB
Architecture: x86_64

Path:

echo $PATH
/usr/local/opt/openjdk/bin:/Users/dave/.bun/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/usr/local/share/dotnet:~/.dotnet/tools

Go:

which go
/usr/local/bin/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"

@Dave-Smith Dave-Smith added admin read bug [core label] labels Mar 25, 2024
@JosephTLyons JosephTLyons added language An umbrella label for all programming languages syntax behaviors go Go programming language support and removed triage labels Mar 25, 2024
@mrnugget
Copy link
Member

Hey! Thanks for the ticket. The interesting line is this one here:

2024-03-25T12:54:32-05:00 [INFO] set environment variables from shell:/bin/zsh, path:/usr/bin:/bin:/usr/sbin:/sbin

When we launch your $SHELL (which seems to be zsh), we can't detect your full $PATH and I wonder why. (What we do to detect is to essentially run $SHELL -i -l -c '/usr/bin/env')

How do you setup your $PATH when you launch your shell manually? Any .zprofile or .zshrc config that's special?

@Dave-Smith
Copy link
Contributor Author

I have the following in my .zshrc

export PATH="$BUN_INSTALL/bin:$PATH"
export PATH="/usr/local/opt/openjdk/bin:$PATH"

I ran the same command to detect the environment and have this for the PATH

PATH=/usr/local/opt/openjdk/bin:/Users/dave/.bun/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/usr/local/share/dotnet:~/.dotnet/tools:/usr/local/opt/openjdk/bin:/Users/dave/.bun/bin

@Dave-Smith
Copy link
Contributor Author

Dave-Smith commented Mar 26, 2024

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

@mrnugget
Copy link
Member

Where do you add /usr/local/bin to the $PATH? Do you have a .profile/.zprofile file too?

Also, what does echo $SHELL say?

In your macOS settings, when you right click on your username and open Advanced Options, what do you have set as the login shell?
screenshot-2024-03-27-06 37 04@2x

@Dave-Smith
Copy link
Contributor Author

$SHELL -> /bin/zsh
Login shell -> /bin/zsh
image

The usr/local/bin path is added to $PATH in /etc/paths
etc/paths:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

I do not have either ~/.profile or ~/.zprofile files. I set additional directories to $PATH in ~/.zshrc

export PATH="$BUN_INSTALL/bin:$PATH"
export PATH="/usr/local/opt/openjdk/bin:$PATH"

@mrnugget
Copy link
Member

mrnugget commented Apr 2, 2024

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?

env -i HOME="$HOME" /bin/zsh -i -l -c 'cd ~/; /usr/bin/env' | grep PATH

@mrnugget
Copy link
Member

mrnugget commented Apr 2, 2024

Another question: how do you launch Zed? Do you click on the icon in the Dock, do you use the zed CLI, Raycast, Alfred, ... anything?

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

@Dave-Smith
Copy link
Contributor Author

env -i HOME="$HOME" /bin/zsh -i -l -c 'cd ~/; /usr/bin/env' | grep PATH                                                                                 
PATH=/usr/local/opt/openjdk/bin:/Users/dave/.bun/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Users/dave/.dotnet/tools

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)?

@mrnugget
Copy link
Member

mrnugget commented Apr 3, 2024

I scheduled some time on Friday.

Great!

Is there anything I should prepare in advance (tools, clone zed source, etc)?

It'd be great if you could get Zed to a point where you can run from source with cargo run. The instructions in here should contain everything: https://github.com/zed-industries/zed/blob/main/docs/src/developing_zed__building_zed_macos.md

What we need to debug is this code here:

zed/crates/zed/src/main.rs

Lines 887 to 941 in 5a2a85a

async fn load_login_shell_environment() -> Result<()> {
let marker = "ZED_LOGIN_SHELL_START";
let shell = env::var("SHELL").context(
"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 = Command::new(&shell)
.args(["-l", "-i", "-c", &shell_cmd])
.output()
.await
.context("failed to spawn login shell to source login environment variables")?;
if !output.status.success() {
Err(anyhow!("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..];
env::set_var(key, value);
}
}
log::info!(
"set environment variables from shell:{}, path:{}",
shell,
env::var("PATH").unwrap_or_default(),
);
}
Ok(())
}

We can also already start debugging this by running a modified version:

  1. Install Rust/cargo
  2. cargo new --bin shell-env
  3. cd shell-env
  4. Open src/main.rs and put the following in:
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);
            }
        }
    }
}
  1. Build it: cargo build
  2. Run it only with $HOME and $SHELL set at start of process: env -i HOME="$HOME" SHELL="$SHELL" ./target/debug/shell-env
  3. That should print key-value env variables and I'm curious whether there's something that stands out.

@mrnugget
Copy link
Member

mrnugget commented Apr 3, 2024

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 \n that echo adds. Meaning that the first environment variable in the command's output will not be set correctly. Instead of, say, setting HOME, we'd set \nHOME.

It could be that in your setup the first variable was PATH and thus we never set PATH but \nPATH, which would explain the problem here.

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.

mrnugget added a commit that referenced this issue Apr 3, 2024
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`.
@Dave-Smith
Copy link
Contributor Author

Awesome. I'll clone the repo and debug locally with the version prior to your commit.

@Dave-Smith
Copy link
Contributor Author

I ran the sample shell-env code. I didn't get any output. Started playing with the code and found /usr/bin/env -0 doesn't output any environment variables. I changed the command to {}printf '%s' {marker}; /usr/bin/env; exit 0; and all the environment variable were in the output. I tried both echo and `printf '%s' and didn't immediately notice a difference

@mrnugget
Copy link
Member

mrnugget commented Apr 5, 2024

Started playing with the code and found /usr/bin/env -0

You mean as part of shell-env or when you run it on the CLI? The latter would be VERY surprising to me.

I changed the command to {}printf '%s' {marker}; /usr/bin/env; exit 0; and all the environment variable were in the output. I tried both echo and `printf '%s' and didn't immediately notice a difference

So with the code that's on main (which uses printf) it works and gives you the right output? Does that mean your problem disappears in the newest preview release?

@Dave-Smith
Copy link
Contributor Author

On the CLI /usr/bin/env -0 says -0 is not a valid option. Thats really not what I expected. I can show you what is happening.
I installed the latest preview version and still have the same issue.

mrnugget added a commit that referenced this issue Apr 5, 2024
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>
mrnugget added a commit that referenced this issue Apr 5, 2024
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>
@Dave-Smith
Copy link
Contributor Author

Upgrading from macOS 12 to 14 fixed the issue on my computer with env -0 not working. This makes the current version of Zed work on my computer. Thanks for your time @mrnugget. Appreciate it.

@nuke-web3
Copy link

nuke-web3 commented Dec 7, 2024

Strangely got go working just fine once withgo install golang.org/x/tools/gopls@latest and adding /home/<user>/go/bin to my PATH - on Pop!_OS.

Now I get the same error as in the OP, but I am using bash

$ 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

Zed 0.163.2


update: installed via https://github.com/zed-industries/zed/blob/1ddee089ed3fd6b1dd5c29ae0778d4035f1020d6/script/install-linux to 0.164.2 and again opening a go file worked once then it fails on restart of Zed every time

Any ideas would help me a lot 🙏

Opening from a terminal with zed . works to open the present working dir, but trying to open from a shortcut fails, likely an issue with the env of my OS.

@mrnugget
Copy link
Member

mrnugget commented Dec 9, 2024

Opening from a terminal with zed . works to open the present working dir, but trying to open from a shortcut fails, likely an issue with the env of my OS.

Hmmm, anything in the logs? When you launch Zed from a shortcut, we should launch a login shell internally and get the $PATH from that, which should include your /usr/local/go/bin/go.

@jnardiello
Copy link

This is SUPER weird. I'm experiencing the exact same behaviour as @nuke-web3 . When launching zed from terminal, it does get gopls and the go binary correctly, launching from dock fails.

I'm on macos 15.2. I've spent the last 4 hours debugging my env variables but no luck. Any suggestion @mrnugget ?

@dihedron
Copy link

+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.

@mrnugget
Copy link
Member

I'll just repeat the question: anything in the logs? I specifically put log statements in there to debug issues like this.

@jnardiello
Copy link

So, I managed to get zed working correctly for golang, but took quite some work.
I don't currently have logs at hand, but I can quickly summarize what was going on, and what I did to fix it.

System Versions:

  • Macos Sequoia 15.2
  • Terminal: Fish with config.fish launching by default tmux, on iTerm2

Issue:

  • When launching zed, shell would fail loading gopls and go
  • In Logs, you would find simply error while loading shell, with exit code 1 would fail loading shell with exit error (will post logs if useful once I get home)

How I fixed it:

  • Scouting across different issues, I found out that several of them are connected (with various side effects) to fish
  • I have disabled fish as the standard shell for my user, default to simple bash
  • Set fish as the shell on iterm

Doing so, ended up fixing the issue. I came to the conclusion that fish (and possibly tmux at launch) are causing issues to zed. Hope it help!
@mrnugget Let me know if the logs of my system would be of any help as well. Sorry for not providing them right away.

@mrnugget
Copy link
Member

Doing so, ended up fixing the issue. I came to the conclusion that fish (and possibly tmux at launch) are causing issues to zed. Hope it help!
@mrnugget Let me know if the logs of my system would be of any help as well. Sorry for not providing them right away.

Ah, fish might indeed be the issue. Will need to check whether our environment loading fails with fish. It should work, but maybe it stopped?

Logs would be helpful, yes!

@dihedron
Copy link

dihedron commented Dec 17, 2024

I'll just repeat the question: anything in the logs? I specifically put log statements in there to debug issues like this.

Yes, @mrnugget there is something relevant in the logs:

2024-12-17T17:31:49.808072157+01:00 [INFO] using project environment variables from CLI. 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" 2024-12-17T17:31:49.831817122+01:00 [INFO] attempting to start language server "gopls", path: "/data/workspaces/gomods/netcheck", id: 1 2024-12-17T17:31:49.839020958+01:00 [ERROR] no cached binary 2024-12-17T17:31:49.839075599+01:00 [ERROR] Failed to start language server "gopls": cannot install gopls 2024-12-17T17:31:49.839094464+01:00 [ERROR] server stderr: ""

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 .bashrc:

export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin:$HOME/.local/bin

It looks like when loading the environment (with the default shell on my Linux Mint box) it does not take into account .bashrc: is this by design and I missed it?

@mrnugget
Copy link
Member

Thanks for the logs!

This line is interesting:

2024-12-17T17:31:49.808072157+01:00 [INFO] using project environment variables from CLI.

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?

env -i HOME="$HOME" /bin/bash -i -l -c 'cd ~/; /usr/bin/env' | grep PATH

I assume $SHELL is bash, right?

@mrnugget
Copy link
Member

Also:

fails when launched from the shortcut in the system dock.

Can I see how that shortcut is configured?

@dihedron
Copy link

OK, @mrnugget here's (the first batch of) the requested info:

  1. This in a freshly installed Linux Mint on AMD64
  2. my login shell is bash
  3. the only modification to my RC files is the line I reported above that adds the go compiler and $GOROOT/bin to the PATH
  4. This is the result of running your command:
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)).
5. It's launched from the 'Panel", to which it was added by right clicking on the icon that was added to the Mint menu by your setup script and clicking on 'Add to Panel'. I have never delved deeply into how menus are managed by cinnamon but I'm writing a proxy to the zed app which dumps all the information I can about the environment and the command line args with which it is launched by the launcher. Give me a minute.

@dihedron
Copy link

So @mrnugget this is a dump of the environment, command line args, current directory and current user when launched via the Cinnamon Panel:

command line arguments:
     0. /home/user/.local/zed.app/bin/zed
environment variables:
   LANGUAGE = en_US
   USER = user
   XDG_SEAT = seat0
   XDG_SESSION_TYPE = x11
   SHLVL = 0
   HOME = /home/user
   DESKTOP_SESSION = cinnamon
   GTK_MODULES = gail:atk-bridge
   XDG_SEAT_PATH = /org/freedesktop/DisplayManager/Seat0
   LC_MONETARY = it_IT.UTF-8
   DBUS_SESSION_BUS_ADDRESS = unix:path=/run/user/1000/bus
   LOGNAME = user
   XDG_SESSION_CLASS = user
   XDG_SESSION_ID = c2
   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
   GDM_LANG = en_US
   GTK3_MODULES = xapp-gtk3-module
   XDG_SESSION_PATH = /org/freedesktop/DisplayManager/Session0
   LC_ADDRESS = it_IT.UTF-8
   XDG_RUNTIME_DIR = /run/user/1000
   DISPLAY = :0
   LANG = en_US.UTF-8
   LC_TELEPHONE = it_IT.UTF-8
   XDG_SESSION_DESKTOP = cinnamon
   XAUTHORITY = /home/user/.Xauthority
   XDG_GREETER_DATA_DIR = /var/lib/lightdm-data/user
   SHELL = /bin/bash
   LC_NAME = it_IT.UTF-8
   QT_ACCESSIBILITY = 1
   GDMSESSION = cinnamon
   LC_MEASUREMENT = it_IT.UTF-8
   GPG_AGENT_INFO = /run/user/1000/gnupg/S.gpg-agent:0:1
   LC_IDENTIFICATION = it_IT.UTF-8
   XDG_VTNR = 7
   PWD = /home/user
   XDG_CONFIG_DIRS = /etc/xdg/xdg-cinnamon:/etc/xdg
   XDG_DATA_DIRS = /usr/share/cinnamon:/usr/share/gnome:/home/user/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop
   LC_NUMERIC = it_IT.UTF-8
   LC_PAPER = it_IT.UTF-8
   GNOME_DESKTOP_SESSION_ID = this-is-deprecated
   SESSION_MANAGER = local/mypc:@/tmp/.ICE-unix/1611,unix/mypc:/tmp/.ICE-unix/1611
   XDG_CURRENT_DESKTOP = X-Cinnamon
   SSH_AUTH_SOCK = /run/user/1000/keyring/ssh
   GIO_LAUNCHED_DESKTOP_FILE = /home/user/.local/share/applications/dev.zed.Zed.desktop
   GIO_LAUNCHED_DESKTOP_FILE_PID = 79761
   GJS_DEBUG_OUTPUT = stderr
   GJS_DEBUG_TOPICS = JS ERROR;JS LOG
   CINNAMON_VERSION = 6.2.9
   DESKTOP_STARTUP_ID = cinnamon/Zed/1999-15-mypc_TIME9090529
   XDG_ACTIVATION_TOKEN = cinnamon/Zed/1999-15-mypc_TIME9090529
current working directory: /home/user
current user: user (1000 1000)

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.

@dihedron
Copy link

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.

Uh, and by the way:

  1. when launched from the "real CLI" with zed . it works like a charm since the PATH is correctly borrowed from the interactive shell.
  2. it looks like there is a long history of problems with GUI apps not honoring custom PATH entries in .bashrc but Mint forum is down right now (https://forums.linuxmint.com/viewtopic.php?t=341757)

@dihedron
Copy link

OK, so I fixed it by adding custom PATH entries in my .profile instead of .bashrc, as per this article in Mint's forum. If you agree this is the solution, maybe it could be convenient to document it.

@mrnugget
Copy link
Member

Thank you so much for the investigation and the help here! I really appreciate it.

OK, so I fixed it by adding custom PATH entries in my .profile instead of .bashrc, as per this article in Mint's forum. If you agree this is the solution, maybe it could be convenient to document 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: /home/user/.local/zed.app/libexec/zed-editor — I think that should then work.

Or maybe we should detect whether there's a GIO_LAUNCHED_DESKTOP_FILE env var set and then ignore the "CLI env"... Hmm.

@dihedron
Copy link

Hi @mrnugget I tried with your suggested approach, edited the ~/.local/share/applications/dev.zed.Zed.desktop file created by the setup process as suggested by you:

[Desktop Entry]
Version=1.0
Type=Application
Name=Zed
GenericName=Text Editor
Comment=A high-performance, multiplayer code editor.
#TryExec=/home/user/.local/zed.app/bin/zed
TryExec=/home/user/.local/zed.app/libexec/zed-editor
StartupNotify=true
#Exec=/home/user/.local/zed.app/bin/zed %U
Exec=/home/user/.local/zed.app/libexec/zed-editor %U
Icon=/home/user/.local/zed.app/share/icons/hicolor/512x512/apps/zed.png
Categories=Utility;TextEditor;Development;IDE;
Keywords=zed;
MimeType=text/plain;application/x-zerosize;x-scheme-handler/zed;
Actions=NewWorkspace;

[Desktop Action NewWorkspace]
Exec=/home/user/.local/zed.app/bin/zed --new %U
Name=Open a new workspace

then reverted my .bashrc so it exports the Go-related variables and removed them from .profile and this is what I get in the logs:

2024-12-20T19:41:59.4524344+01:00 [INFO] socket reader;
2024-12-20T19:41:59.452696924+01:00 [INFO] set environment variables from shell:/bin/bash, path:/home/user/.local/bin:/home/user/.local/bin:/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:/usr/local/go/bin:/home/user/go/bin:/home/user/.local/bin
2024-12-20T19:41:59.456118283+01:00 [INFO] new;
2024-12-20T19:41:59.456517009+01:00 [INFO] keep_updated;

Zed picks the correct shell (/bin/bash) and the proper environment from it, so it can now start the gopls language server properly.

Why did you create the .desktop file with zed instead of zed-editor in the first place, if only the latter is capable of setting up the environment correctly?

Hope this helps.

@mrnugget
Copy link
Member

mrnugget commented Jan 7, 2025

Why did you create the .desktop file with zed instead of zed-editor in the first place, if only the latter is capable of setting up the environment correctly?

I think there might have been some confusion and this might not have been intentional. Taking a look.

@mrnugget
Copy link
Member

mrnugget commented Jan 7, 2025

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 zed-editor does not. So we use the CLI in .desktop files, so users can drag/drop files onto it and so on.

@dihedron
Copy link

Hmmm, so it looks like there is no way out apart from setting the relevant env vars in .profile instead of .bashrc, and leave the .desktop file as is.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] go Go programming language support language An umbrella label for all programming languages syntax behaviors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants