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

Linux cannot install gopls when starting zed from .desktop file #21406

Closed
1 task done
mosenturm opened this issue Dec 2, 2024 · 8 comments · Fixed by #22335
Closed
1 task done

Linux cannot install gopls when starting zed from .desktop file #21406

mosenturm opened this issue Dec 2, 2024 · 8 comments · Fixed by #22335
Labels
bug [core label] go Go programming language support language server failure Language server doesn't work as expected language server An umbrella label for all language servers

Comments

@mosenturm
Copy link

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

See also #18908

When you launch from the desktop file it seems the .profile or .bashrc or whatever is read too late:

   Compiling zed v0.165.0 (/home/andreas/dev-local/zed/crates/zed)
warning: [email protected]: Info: using '2300f40cd987bdb3602769d312786eb4118d711c' hash for ZED_COMMIT_SHA env var

zed.log:
2024-12-02T14:07:48.272176936+01:00 [INFO] attempting to start language server "gopls", path: "/home/andreas/dev-local/tp2_0/goecho", id: 2
2024-12-02T14:07:48.272911954+01:00 [ERROR] no cached binary
2024-12-02T14:07:48.273066864+01:00 [ERROR] Failed to start language server "gopls": cannot install gopls
2024-12-02T14:07:48.273149627+01:00 [ERROR] server stderr: ""

If I start from a project directory with zed . then no error appears.

Environment

Linux Ubuntu 24.04
Wayland

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-02T14:41:39.357107114+01:00 [INFO] attempting to start language server "gopls", path: "/home/andreas/dev-local/tp2_0/goecho", id: 1
2024-12-02T14:41:39.378764362+01:00 [ERROR] no cached binary
2024-12-02T14:41:39.378921506+01:00 [ERROR] Failed to start language server "gopls": cannot install gopls
2024-12-02T14:41:39.378961386+01:00 [ERROR] server stderr: ""
2024-12-02T14:41:39.403664095+01:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-12-02T14:41:39.436875451+01:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-12-02T14:41:39.796752609+01:00 [INFO] Creating a descriptor pool for at most 256 sets
2024-12-02T14:41:39.801446203+01:00 [INFO] add_connection;
2024-12-02T14:41:39.803007591+01:00 [INFO] set status on client 153500: Connected { peer_id: PeerId { owner_id: 616, id: 6302373 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-12-02T14:41:39.83864463+01:00 [INFO] Creating a descriptor pool for at most 256 sets
2024-12-02T14:41:39.929652227+01:00 [WARN] unhandled message: TaskStatus(SupermavenTaskUpdateMessage { task: "Initializing", status: Complete, percent_complete: None })
2024-12-02T14:41:39.929763834+01:00 [WARN] unhandled message: ActiveRepo(SupermavenActiveRepoMessage { repo_simple_name: None })
2024-12-02T14:41:39.981521742+01:00 [INFO] set environment variables from shell:/bin/bash, path:/home/andreas/.cargo/bin:/home/andreas/.local/bin:/home/andreas/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/local/go/bin:/home/andreas/go/bin
@mosenturm mosenturm added admin read bug [core label] labels Dec 2, 2024
@smitbarmase
Copy link
Member

smitbarmase commented Dec 2, 2024

Can you let me know which version of Zed you're using?

The recent Preview release fixed an issue on Linux where the .desktop file was opening a different binary (zed-editor) instead of the usual one (zed) that the terminal runs.

Could you try latest Preview release?

@jansol
Copy link
Contributor

jansol commented Dec 2, 2024

When you launch from the desktop file it seems the .profile or .bashrc or whatever is read too late

This was diagnosed on Discord based on the zed log showing PATH shortly after the gopls errors, and the go directories are present there:

2024-12-02T14:41:39.981521742+01:00 [INFO] set environment variables from shell:/bin/bash, path:[snip]:/usr/local/go/bin:/home/xxxx/go/bin

@mosenturm
Copy link
Author

Already wrote:

   Compiling zed v0.165.0 (/home/andreas/dev-local/zed/crates/zed)
warning: [email protected]: Info: using '2300f40cd987bdb3602769d312786eb4118d711c' hash for ZED_COMMIT_SHA env var

No, did not try the preview.

@jansol jansol added language server failure Language server doesn't work as expected language server An umbrella label for all language servers and removed triage labels Dec 2, 2024
@notpeter

This comment was marked as off-topic.

@Moshyfawn Moshyfawn added the awaiting info Issue that needs more information from the user label Dec 2, 2024
@mosenturm
Copy link
Author

Again: Self compiled from git. Pls. read all text from issue!

Curious whether you are using the official binaries or via something else (unofficial flatpak, etc).

@notpeter notpeter added go Go programming language support and removed awaiting info Issue that needs more information from the user admin read labels Dec 2, 2024
@MonstraG
Copy link

MonstraG commented Dec 4, 2024

Same here, but different setup:
Linux, Nobara 40
Wayland 6
zsh
zed 0.163.3

Installed via

curl -f https://zed.dev/install.sh | sh

$ zed does zed: command not found (I didn't bother adding to Path yet)
launching zed from desktop gives this error if "restore_on_startup" opens previous project.

If "restore_on_startup": "none" and I manually open the project from recent projects, everything is fine.

P.S. would be nice to be able to copy zed version/commit from About Zed, but both version and commit are neither mouse-selectable nor copyable in any other way. (turns out there is a separate issue about that #21305)

@jansol
Copy link
Contributor

jansol commented Dec 4, 2024

P.S. would be nice to be able to copy zed version/commit from About Zed, but both version and commit are neither mouse-selectable nor copyable in any other way. (turns out there is a separate issue about that #21305)

This is already on the way via #21405

However most of the time the interesting info is in zed: copy system specs into clipboard. (Zed version + OS + GPU driver)

@strowk
Copy link
Contributor

strowk commented Dec 16, 2024

The same issue happens for me.

Zed: v0.165.4 (Zed)
OS: Linux X11 ubuntu 24.04
Memory: 60.6 GiB
Architecture: x86_64
GPU: AMD Radeon Graphics (RADV GFX1103_R1) || radv || Mesa 24.0.9-0ubuntu0.2

For now I try to run zed from terminal, but this has other usability problems (since I use tmux, whenever I start terminal inside zed, it would see that tmux env is already set and not start itself.. so either I have tmux or Golang).

My version does not log "set environment variables from shell", though, so I have no idea how to give right PATH to Zed. Any workarounds other that starting from terminal?

github-merge-queue bot pushed a commit that referenced this issue Dec 22, 2024
… from .desktop file (#22335)

Closes #21406

Context:

A few weeks ago on Linux, we resolved an
[issue](#20070) where users
could not open more than one file from the file explorer. This was fixed
by replacing `zed-editor` (zed binary in the code) with `zed` (cli
binary in the code) in the `.desktop` file. The reason for this change
was that using the cli to open files is more convenient - it determines
weather to spawn a new Zed instance or use an existing one, if we use
main binary instead it would throw error `Zed is already running`.

You can read the complete PR here: [linux: Fix file not opening from
file explorer](#21137).

While this fix resolved the original issue, it introduced a new one.

Problem:

When the cli binary is used, it assumes it is always being invoked from
a terminal and relies on `std::env::vars()` to retrieve the environment
variables needed to spawn Zed. These env vars are then passed to the
worktree, and eventually, languages use the `PATH` from this env to find
binaries. This leads to the "Failed to start language server" error when
the `.desktop` entry is used on Linux.

Solution:

When the `zed-editor` binary is used, it uses some clever Unix-specific
logic to retrieve the default shell (`load_shell_from_passwd`) and then
fetch the env vars from that shell (`load_login_shell_environment`).
This same logic should be used in the cli binary when it is invoked via
a `.desktop` entry rather than from a terminal.

Approach:

I moved these two functions mentioned above to a utils file and reused
them in cli binary to fetch env vars only on Linux when it is not run
from a terminal. This provides missing paths, and fix the issue.

It is also possible to handle this in the `zed-editor` binary by
modifying the logic in `handle_cli_connection`, where `CliRequest::Open`
is processed. There we can discard incoming env, and use our logic. But
discarding incoming envs felt weird, and I thought it's better to handle
this at source.

Release Notes:

- Fixed `Failed to start language server` errors when starting from
dekstop entry on Linux
CharlesChen0823 pushed a commit to CharlesChen0823/zed that referenced this issue Dec 24, 2024
… from .desktop file (zed-industries#22335)

Closes zed-industries#21406

Context:

A few weeks ago on Linux, we resolved an
[issue](zed-industries#20070) where users
could not open more than one file from the file explorer. This was fixed
by replacing `zed-editor` (zed binary in the code) with `zed` (cli
binary in the code) in the `.desktop` file. The reason for this change
was that using the cli to open files is more convenient - it determines
weather to spawn a new Zed instance or use an existing one, if we use
main binary instead it would throw error `Zed is already running`.

You can read the complete PR here: [linux: Fix file not opening from
file explorer](zed-industries#21137).

While this fix resolved the original issue, it introduced a new one.

Problem:

When the cli binary is used, it assumes it is always being invoked from
a terminal and relies on `std::env::vars()` to retrieve the environment
variables needed to spawn Zed. These env vars are then passed to the
worktree, and eventually, languages use the `PATH` from this env to find
binaries. This leads to the "Failed to start language server" error when
the `.desktop` entry is used on Linux.

Solution:

When the `zed-editor` binary is used, it uses some clever Unix-specific
logic to retrieve the default shell (`load_shell_from_passwd`) and then
fetch the env vars from that shell (`load_login_shell_environment`).
This same logic should be used in the cli binary when it is invoked via
a `.desktop` entry rather than from a terminal.

Approach:

I moved these two functions mentioned above to a utils file and reused
them in cli binary to fetch env vars only on Linux when it is not run
from a terminal. This provides missing paths, and fix the issue.

It is also possible to handle this in the `zed-editor` binary by
modifying the logic in `handle_cli_connection`, where `CliRequest::Open`
is processed. There we can discard incoming env, and use our logic. But
discarding incoming envs felt weird, and I thought it's better to handle
this at source.

Release Notes:

- Fixed `Failed to start language server` errors when starting from
dekstop entry on Linux
helgemahrt pushed a commit to helgemahrt/zed that referenced this issue Jan 1, 2025
… from .desktop file (zed-industries#22335)

Closes zed-industries#21406

Context:

A few weeks ago on Linux, we resolved an
[issue](zed-industries#20070) where users
could not open more than one file from the file explorer. This was fixed
by replacing `zed-editor` (zed binary in the code) with `zed` (cli
binary in the code) in the `.desktop` file. The reason for this change
was that using the cli to open files is more convenient - it determines
weather to spawn a new Zed instance or use an existing one, if we use
main binary instead it would throw error `Zed is already running`.

You can read the complete PR here: [linux: Fix file not opening from
file explorer](zed-industries#21137).

While this fix resolved the original issue, it introduced a new one.

Problem:

When the cli binary is used, it assumes it is always being invoked from
a terminal and relies on `std::env::vars()` to retrieve the environment
variables needed to spawn Zed. These env vars are then passed to the
worktree, and eventually, languages use the `PATH` from this env to find
binaries. This leads to the "Failed to start language server" error when
the `.desktop` entry is used on Linux.

Solution:

When the `zed-editor` binary is used, it uses some clever Unix-specific
logic to retrieve the default shell (`load_shell_from_passwd`) and then
fetch the env vars from that shell (`load_login_shell_environment`).
This same logic should be used in the cli binary when it is invoked via
a `.desktop` entry rather than from a terminal.

Approach:

I moved these two functions mentioned above to a utils file and reused
them in cli binary to fetch env vars only on Linux when it is not run
from a terminal. This provides missing paths, and fix the issue.

It is also possible to handle this in the `zed-editor` binary by
modifying the logic in `handle_cli_connection`, where `CliRequest::Open`
is processed. There we can discard incoming env, and use our logic. But
discarding incoming envs felt weird, and I thought it's better to handle
this at source.

Release Notes:

- Fixed `Failed to start language server` errors when starting from
dekstop entry on Linux
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 server failure Language server doesn't work as expected language server An umbrella label for all language servers
Projects
None yet
7 participants