zed icon indicating copy to clipboard operation
zed copied to clipboard

LSP only loads when launching zed via cli

Open zacowan opened this issue 1 year ago • 7 comments

Summary

Launching Zed normally does not automatically load necessary LSPs for the project, but using zed [workspace] correctly loads the LSPs.

Steps to trigger the problem:

  1. Install Zed.
  2. Open Zed.
  3. Install the Zed CLI via the menu.
  4. Open any project with Zed (I've tried TypeScript projects with eslint/prettier/tailwind and a Go project).
  5. Open a file and note that the primary LSP for the language (TypeScript or Go) does not load.
  6. Close Zed.
  7. Open a terminal.
  8. Open the same project using zed [workspace].
  9. Note that immediately upon the workspace loading, the LSP for the language (TypeScript or Go) is loaded.
  10. Open a file and note that LSP features are enabled.

Actual Behavior: Opening a file (not using the CLI) does not load the primary LSP for the language (TypeScript or Go) as soon as the workspace loads. Expected Behavior: Opening a file (not using the CLI) correctly loads the primary LSP for the language (TypeScript or Go) as soon as the workspace loads.

Zed Version and System Specs

Zed: v0.174.6 (Zed) OS: macOS 15.3.1 Memory: 16 GiB Architecture: aarch64

zacowan avatar Feb 22 '25 19:02 zacowan

Hey, thanks for reporting this. This is likely an issue with environment variables and paths.

How were the LSP's installed? Were they installed through Zed or did you install them yourself some other way? If you installed them yourself, how?

Additionally, could you please provide any error messages you are seeing when the LSPs fail to start, either in the UI, error notification (bottom left near diagnostics count icon), or in your zed log (zed: open log)

Once we're able to understand what is going wrong here we'll try and get it fixed for you as soon as possible!

probably-neb avatar Feb 28 '25 23:02 probably-neb

Thanks @probably-neb!

LSP's were installed with Zed automatically. I'm not seeing any error messages unfortunately, but I've grabbed the logs: https://gist.github.com/zacowan/1fb943a92c06b71748dbb93b8444d715.

At a quick glance, environment variables look like they might be the culprit. I've had a read through of the docs and stumbled upon this: https://zed.dev/docs/environment?highlight=environment%20variables#launched-via-window-manager-dock-or-launcher, which does seem to illustrate what might be the problem here.

The languages I tested were Go and TypeScript - for these, I set environments variables like so (fnm is a tool for managing different versions of node.js):

eval "$(fnm env --use-on-cd)"

export GOPATH="some/path"
export PATH="$GOPATH/bin:$PATH"

Not sure if it's a me/config problem or an actual problem, lmk what you think 😁

zacowan avatar Mar 01 '25 05:03 zacowan

Hmm, a couple things are weird here.

  • we should absolutely be seeing errors in your logs if they're failing to start.
  • we use our own bundled version of node to run the installed TypeScript LSP, both of which we (should) use absolute paths to access so env vars shouldn't mess with that
  • we do depend on the user having go installed to run go install to install gopls for them, but then we move the installed binary to our folder where we keep the rest of the LSP's and run it with an absolute path after that, so I also see no reason why that wouldn't be working either?

Based on all of that, env vars are probably not the issue. I've got a couple other things for you to try so I can hopefully figure out what's going wrong here

  1. After opening Zed not through the cli in a go project, could you run which go in the Zed terminal and make sure go is found on the path?
  2. In both a go project and a ts project, opened not through the cli
    • run debug: open language server logs
    • in the pane that opens up, click on the thing that looks like the name of an LSP in the top left, and select the relevant language server (gopls for go and vtsls for ts)
    • Look at the server logs to see if there's anything of note
    • Click where it says "Server Logs" next to the LSP name and click through all of the options (server trace, rpc messages, etc) and look for anything noteworthy
      • When you have RPC Messages selected, click around in the project, maybe type a little, a bunch of json messages should appear in the LSP logs pane, if nothing appears but the Server info, logs, and trace seem fine that's definitely an issue
    • If you feel comfortable pasting the output from any of the LSP logs here, I'd be happy to take a look

Thanks, and sorry for the delayed response. Hopefully we can get this figured out pretty fast for you!

probably-neb avatar Mar 04 '25 22:03 probably-neb

no worries on the delay!

  1. which go does suggest go is available in the path (ran in the zed integrated terminal when NOT opened via CLI):
Image
  1. For both my Go project and my TS project, I can open the logs but there's no logs for me to look at (no language servers available to select, NOT opened via CLI):
Image

And to be clear, I can open and view logs when I open these projects from the CLI.

Not super helpful I realize - let me know if there's a workaround and I'm happy to retry 2 and/or get any logs sent over

zacowan avatar Mar 05 '25 00:03 zacowan

Weird, so it seems like we are attempting to start the language servers, and hitting some error that we're not logging that causes them to fail to be registered at all. Maybe it is an env var issue?

Either way I'll look into this more and see if we can at least make sure all the cases where LSPs fail to launch & register get logged appropriately.

So, current plan, unless I come up with something better or figure out what's going wrong, is to make sure we have 100% LSP startup error logging coverage, release that, and see if the additional logs provide any useful information for this error you're having. This isn't my favorite solution, but it's all I've got at this point.

To that end, it seems like the error case logs you provided end kind of abruptly, would you mind opening not via the CLI, and clicking around coding for a minute or so and then share the complete log? I just want to make sure we're not missing a log that comes later.

Thanks, and hopefully we can get this fixed for you very soon

probably-neb avatar Mar 06 '25 15:03 probably-neb

@probably-neb sorry for the delay! That sounds like a solid plan 😁

I did a fresh install of the latest version of Zed, opened my project, coded for a bit, and then attempted to restart the language server. The result of those logs is here: https://gist.github.com/zacowan/9aa1400ec56a74c97ab7f7072874da1a

Keep me in the loop if there's more that I can do! Looking forward to the fix

zacowan avatar Mar 15 '25 01:03 zacowan

Maybe related:

  • https://github.com/zed-industries/zed/issues/22575

smitbarmase avatar Mar 20 '25 18:03 smitbarmase