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

Zed Editor package can't use language servers #309662

Open
ImTheSquid opened this issue May 6, 2024 · 35 comments · Fixed by #339852
Open

Zed Editor package can't use language servers #309662

ImTheSquid opened this issue May 6, 2024 · 35 comments · Fixed by #339852
Labels
0.kind: bug Something is broken

Comments

@ImTheSquid
Copy link

Describe the bug

Zed has the same issue as many other editors where it tries to run dynamically-linked libraries. A FHS chroot like vscode-fhs would probably fix this.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Open Zed
  2. Attempt to use any language server

Expected behavior

Zed is able to download and execute the language server of choice.

Additional context

Here is the log entry:

2024-05-06T18:29:14-04:00 [INFO] starting language server. binary path: "/home/jack/.local/share/zed/languages/rust-analyzer/rust-analyzer-2024-05-06", working directory: "/home/jack/Code/Rust/CodeCheck", args: []
2024-05-06T18:29:14-04:00 [ERROR] crates/lsp/src/lsp.rs:352: cannot read LSP message headers
2024-05-06T18:29:14-04:00 [ERROR] failed to start language server "rust-analyzer": server shut down
2024-05-06T18:29:14-04:00 [ERROR] server stderr: Some("Could not start dynamically linked executable: /home/jack/.local/share/zed/languages/rust-analyzer/rust-analyzer-2024-05-06\nNixOS cannot run dynamically linked executables intended for generic\nlinux environments out of the box. For more information, see:\n")

Notify maintainers

@GaetanLepage
@niklaskorz

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.30, NixOS, 24.05 (Uakari), 24.05pre621993.25865a40d14b`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - channels(root): `"nixos"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Add a 👍 reaction to issues you find important.

@ImTheSquid ImTheSquid added the 0.kind: bug Something is broken label May 6, 2024
@FireFragment
Copy link

Temporary workaround that works for me with Rust Analyzer is to use buildFHSEnv.

Create shell.nix and paste:

{ pkgs ? import <nixpkgs> {} }:

(pkgs.buildFHSEnv {
    name = "zed";
    runScript = "zed";
}).env

Then run nix-shell in the same directory.

@GaetanLepage
Copy link
Contributor

Is zed trying to run the language servers from your PATH, failing and then defaulting to its own binaries (~/.local/share/zed/languages) or is it directly using those regardless of your environment ?

@ImTheSquid
Copy link
Author

As far as I can tell I think it only tries from the ones it downloads.

2024-05-12T08:35:16-04:00 [INFO] starting language servers for Rust: rust-analyzer
2024-05-12T08:35:16-04:00 [INFO] starting language server "rust-analyzer", path: "/home/jack/Code/Rust/CodeCheck", id: 1
2024-05-12T08:35:16-04:00 [INFO] starting language servers for Rust: rust-analyzer
2024-05-12T08:35:16-04:00 [INFO] starting language servers for Nix: 
2024-05-12T08:35:16-04:00 [INFO] starting language servers for Git Ignore: 
2024-05-12T08:35:16-04:00 [INFO] starting language servers for Rust: rust-analyzer
2024-05-12T08:35:16-04:00 [INFO] starting language servers for Rust: rust-analyzer
2024-05-12T08:35:16-04:00 [INFO] fetching latest version of language server "rust-analyzer"
2024-05-12T08:35:16-04:00 [INFO] Creating buffer 0x56126b48f6c0 of size 45472, name 'chunk-6', handle 8
2024-05-12T08:35:17-04:00 [INFO] add connection to peer
2024-05-12T08:35:17-04:00 [INFO] add_connection;
2024-05-12T08:35:17-04:00 [INFO] waiting for server hello
2024-05-12T08:35:17-04:00 [INFO] got server hello
2024-05-12T08:35:17-04:00 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 403, id: 1518134 })
2024-05-12T08:35:17-04:00 [INFO] set status on client 55287: Connected { peer_id: PeerId { owner_id: 403, id: 1518134 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-05-12T08:35:17-04:00 [INFO] downloading language server "rust-analyzer"
2024-05-12T08:35:18-04:00 [INFO] Creating texture 0x56126b48fc50 of size 1024x1024x1 and format Bgra8Unorm, name 'atlas', handle 9
2024-05-12T08:35:18-04:00 [WARN] GPU frame is out of date
2024-05-12T08:35:18-04:00 [INFO] Using surface present mode FIFO_RELAXED
2024-05-12T08:35:20-04:00 [INFO] starting language server. binary path: "/home/jack/.local/share/zed/languages/rust-analyzer/rust-analyzer-2024-05-06", working directory: "/home/jack/Code/Rust/CodeCheck", args: []
2024-05-12T08:35:20-04:00 [ERROR] crates/lsp/src/lsp.rs:352: cannot read LSP message headers
2024-05-12T08:35:20-04:00 [ERROR] crates/lsp/src/lsp.rs:374: Broken pipe (os error 32)
2024-05-12T08:35:20-04:00 [ERROR] failed to start language server "rust-analyzer": server shut down
2024-05-12T08:35:20-04:00 [ERROR] server stderr: Some("Could not start dynamically linked executable: /home/jack/.local/share/zed/languages/rust-analyzer/rust-analyzer-2024-05-06\nNixOS cannot run dynamically linked executables intended for generic\nlinux environments out of the box. For more information, see:\n")

@GaetanLepage
Copy link
Contributor

According to their website, Zed is not yet able to connect with "arbitrary language servers". Maybe we'll have to wait for this to be able to inject our nix built binaries...

@Liamolucko
Copy link
Contributor

Liamolucko commented May 29, 2024

According to their website, Zed is not yet able to connect with "arbitrary language servers". Maybe we'll have to wait for this to be able to inject our nix built binaries...

There seems to be an (undocumented) configuration option to override the language server binary it uses for a language: #284064 (comment).

EDIT: seems like it only works for C, Tailwind, Rust and Go right now though, since each language has to set it up manually.

@oliveirarleo
Copy link

oliveirarleo commented May 31, 2024

Try this:
In my configuration.nix:

 with pkgs; [
  unstable-small.zed-editor
  nodePackages.typescript-language-server
  tree-sitter-grammars.tree-sitter-javascript
  elixir-ls
  tree-sitter-grammars.tree-sitter-elixir
 ...
]

Run with:

steam-run zed &

I got it working by running with steam-run, since the default download fails and binaries for the lsp are not patched. The editor uses the system's lsp in case it cannot download.

I've noticed this by investigating zed logs and seeing logs of the downloaded node command was not patched. Seems like there is more to it, since elixir was not working without steam run as well.
image

@vinicius507
Copy link

vinicius507 commented Jun 7, 2024

I'm executing Zed in a FHS environment using:

{pkgs, ...}: let
  zed-fhs = pkgs.buildFHSUserEnv {
    name = "zed";
    targetPkgs = pkgs:
      with pkgs; [
        zed-editor
      ];
    runScript = "zed";
  };
in {
  home.packages = [zed-fhs];
};

And it works quite well. The only problem is that it does not show up in the desktop entries.

@ioitiki
Copy link

ioitiki commented Jul 12, 2024

I'm executing Zed in a FHS environment using:

{pkgs, ...}: let
  zed-fhs = pkgs.buildFHSUserEnv {
    name = "zed";
    targetPkgs = pkgs:
      with pkgs; [
        zed-editor
      ];
    runScript = "zed";
  };
in {
  home.packages = [zed-fhs];
};

And it works quite well. The only problem is that it does not show up in the desktop entries.

this works for me but every time i open the editor it has to reinitialize and i see this:

image

@vinicius507 is this the same for you?

@bbigras
Copy link
Contributor

bbigras commented Jul 12, 2024

Mine is not reinitializing on every launch. I'm using 0.143.7 though.

@ioitiki
Copy link

ioitiki commented Jul 12, 2024

okay thanks @bbigras mind sharing the overlay?

@bbigras
Copy link
Contributor

bbigras commented Jul 12, 2024

@ioitiki I didn't make an overlay yet, but I made a devShell #324549 (comment) . I also pushed a x86_64 build to cachix.

@domenkozar
Copy link
Member

I'd recommend leaving a thumbs up at zed-industries/zed#4977

@ioitiki
Copy link

ioitiki commented Jul 13, 2024

image
@bbigras I was able to get an overlay working :D :D

@jansol
Copy link
Contributor

jansol commented Jul 17, 2024

FWIW for many language servers Zed will first check PATH before trying to download and run its own. Additionally some language servers let you explicitly specify a binary path, which is what I have been doing:

  "lsp": {
    "bash-language-server": {
      "binary":{
        "path": "/etc/profiles/per-user/myself/bin/bash-language-server",
        "arguments": ["start"]
      }
    },
    "clangd": {
      "binary":{
        "path": "/etc/profiles/per-user/myself/bin/clangd",
        "arguments": ["--background-index", "--compile-commands-dir=build"]
      }
    },
    "rust-analyzer": {
      "binary": {
        "path": "/run/current-system/sw/bin/bash",
        "arguments": ["-c", "if [ -e flake.nix ]; then nix develop --command rust-analyzer; else rust-analyzer; fi"]
      }
    },
    "taplo": {
      "binary":{
        "path": "/etc/profiles/per-user/myself/bin/taplo",
        "arguments": ["lsp"]
      }
    },
    "json-language-server": {
      "binary":{
        "path": "/etc/profiles/per-user/myself/bin/vscode-json-languageserver",
        "arguments": ["--stdio"]
      }
    }
  }

(the rust-analyzer is a bit hacky but I wanted it to work both for simple projects with no system dependencies and for complex ones with a flake.nix that specifies system deps & stuff)

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/zed-editor-the-server-certificate-could-not-be-validated/49992/2

@Th1nkK1D
Copy link

Th1nkK1D commented Aug 6, 2024

I'd recommend leaving a thumbs up at zed-industries/zed#4977

Look like they add direnv support in v0.147.0-pre according to the changelog

Improved the environment-variable detection when running tasks so that tasks can now access environment variables as if the task had been spawned in a terminal that cded into a project directory. That means environment variables set by direnv/asdf/mise and other tools are now picked up

Waiting for the stable release. I'm not sure if it can solve our issues, we might need to wait for zed-industries/zed#4978 as well.

@Mastermindaxe
Copy link
Contributor

I'm asking because there is some conflicting information out there. Is there any workaround atm to make Zed work (including language servers)? And would I have to provide a shell every time or can I use this workaround #309662 (comment) only in shells?

@jansol
Copy link
Contributor

jansol commented Aug 28, 2024

It's not so much conflicting information as there being multiple viable workarounds. Pick whichever you like most.

@jrunestone
Copy link

jrunestone commented Aug 28, 2024

I'm executing Zed in a FHS environment using:

{pkgs, ...}: let
  zed-fhs = pkgs.buildFHSUserEnv {
    name = "zed";
    targetPkgs = pkgs:
      with pkgs; [
        zed-editor
      ];
    runScript = "zed";
  };
in {
  home.packages = [zed-fhs];
};

And it works quite well. The only problem is that it does not show up in the desktop entries.

(#309662 (comment))

@Mastermindaxe this works perfectly for me, using that in my nix config and running zed as usual.

@k3yss
Copy link
Contributor

k3yss commented Sep 6, 2024

@GaetanLepage I don't think the issue is fixed yet and we should close it, my comment here describe that rust analyzer still doesn't work with zed

@k3yss k3yss reopened this Sep 6, 2024
@niklaskorz
Copy link
Contributor

@GaetanLepage I don't think the issue is fixed yet and we should close it, my comment here describe that rust analyzer still doesn't work with zed

I'll have a look which packages might be missing for rust-analyzer

@niklaskorz
Copy link
Contributor

@k3yss rust-analyzer inside Zed works fine for me without additional configuration, are you using pkgs.zed-editor.fhs? (not pkgs.zed-editor)

@k3yss
Copy link
Contributor

k3yss commented Sep 6, 2024

@niklaskorz

Here are the steps that I am doing:
1: Clone the latest nixpkgs
2: Run nix build .#zed-editor (I also tried nix build .#zed-editor.fhs)
3: Run zed via ./result/bin/zed
4: Open my rust based project, using zed Ctrl+o option

I get a similar error that I described before

@niklaskorz
Copy link
Contributor

@niklaskorz

Here are the steps that I am doing: 1: Clone the latest nixpkgs 2: Run nix build .#zed-editor (I also tried nix build .#zed-editor.fhs) 3: Run zed via ./result/bin/zed 4: Open my rust based project, using zed Ctrl+o option

I get a similar error that I described before

Can you try removing your custom LSP path config and then run zed-editor.fhs again?

@k3yss
Copy link
Contributor

k3yss commented Sep 6, 2024

I tried removing it and am received with the error Failed to load workspaces. When you say I need to run zed-editor.fhs you mean running the ./result/bin/zed right?

@niklaskorz
Copy link
Contributor

I tried removing it and am received with the error Failed to load workspaces. When you say I need to run zed-editor.fhs you mean running the ./result/bin/zed right?

Either nix-build -A zed-editor.fhs && result/bin/zed or nix run .#zed-editor.fhs, yes (they're essentially doing the same)

@k3yss
Copy link
Contributor

k3yss commented Sep 6, 2024

hmmm... that's weird, do you want me to share any other logs so we know what the exact error is?

@k3yss
Copy link
Contributor

k3yss commented Sep 6, 2024

This worked for me to setup rust-analyzer #339852 (comment)

I am not sure how it would work natively though : (

@yatesco
Copy link

yatesco commented Sep 14, 2024

(not read the whole thread so maybe missing something)
Since zed-industries/zed#17075, running zed . in my nix develop environment works fine with Rust. I only have rust/cargo setup in my nix develop environment.

Before zed-industries/zed#17075 it would fail miserably to find rust-analyser. Starting Zed from outside my nix develop environment still fails miserably.

My config:

// Zed settings
//
// For information on how to configure Zed, see the Zed
// documentation: https://zed.dev/docs/configuring-zed
//
// To see all of Zed's default settings without changing your
// custom settings, run `zed: open default settings` from the
// command palette
{
  "ui_font_size": 14,
  "buffer_font_size": 14,
  "theme": {
    "mode": "system",
    "light": "One Light",
    "dark": "One Dark"
  }
}

@jansol
Copy link
Contributor

jansol commented Sep 14, 2024

@yatesco just read the thread. I've posted a config that worked both before and after that PR if you have a flake.nix for your project that provides rust-analyzer. (essentially by running nix develop as part of the r-a command)

@jansol
Copy link
Contributor

jansol commented Nov 6, 2024

Now that zed will check PATH for a node.js installation before downloading its own (as of 0.155.2), maybe we should wrap zed to bring in node from nixpkgs? That should solve the problem for node-based language servers (and copilot & prettier).

@jansol
Copy link
Contributor

jansol commented Nov 6, 2024

Initial attempt at wrapping Zed to make node-based LSPs Just Work in #354063

@fzakaria
Copy link
Contributor

what about nix-ld ?

@ninelore
Copy link
Contributor

ninelore commented Nov 28, 2024

what about nix-ld ?

didnt work for me at least

I think this is done

@fzakaria
Copy link
Contributor

fzakaria commented Nov 28, 2024

Most of the language servers worked with nix-ld except for Node on account of zed-industries/zed#20524

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.