zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
50.98k stars 3.16k forks source link

Direnv Integration ignore for external formatter command #18261

Closed jlgeering closed 1 month ago

jlgeering commented 2 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

install a formatter "only in project folder" and make it available with direnv (in my case using nix)

=> the formatter is not available in my normal shell PATH, only in the "direnv PATH"

and configure direnv + external formatter (using treefmt2 as an example)

  "load_direnv": "shell_hook",
  "formatter": {
    "external": {
      "command": "treefmt",
      "arguments": []
    }
  }

nothing happens on editor:format (see also attached zed.log)

when the formatter is available in my normal shell path / installed globally => formatting works

Environment

Zed: v0.153.6 (Zed) OS: macOS 14.5.0 Memory: 32 GiB Architecture: aarch64

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-09-24T09:50:02.436273+02:00 [ERROR] failed to format via external command "treefmt"

Caused by:
    No such file or directory (os error 2)

willcosgrove commented 2 months ago

@mrnugget This seems to be the last thing I've found that doesn't appear to use the environment variables from the shell Zed was launched in.

In my case I'm using chruby which puts a selected ruby version in my PATH. From the shell Zed is launched in, I'm using the correct ruby, but when the formatter runs, it's using the default system ruby.

mrnugget commented 2 months ago

@mrnugget This seems to be the last thing I've found that doesn't appear to use the environment variables from the shell Zed was launched in.

Good catch! You're right, yeah, it is the only place missing the env.

mrnugget commented 2 months ago

Here's a draft PR: https://github.com/zed-industries/zed/pull/18611

Haven't tested it yet and the code needs to be better. Happy if someone wants to pick it up, but this week I really have to focus on SSH remoting. Will pick this up as soon as possible.