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

Go support not working at all #4471

Closed
1 task done
nikitavoloboev opened this issue Sep 16, 2023 · 38 comments
Closed
1 task done

Go support not working at all #4471

nikitavoloboev opened this issue Sep 16, 2023 · 38 comments
Labels
enhancement [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 language An umbrella label for all programming languages syntax behaviors

Comments

@nikitavoloboev
Copy link

nikitavoloboev commented Sep 16, 2023

Check for existing issues

  • Completed

Describe the feature

Opened this project in Zed: https://github.com/nikitavoloboev/sol-pay

Opened this file: https://github.com/nikitavoloboev/sol-pay/blob/main/main.go

In Zed:

image

In VSCode:

image

No idea what I am doing wrong. But I wish I could use Zed for Go code too.

@nikitavoloboev nikitavoloboev added admin read Pending admin review enhancement [core label] triage Maintainer needs to classify the issue labels Sep 16, 2023
@JosephTLyons JosephTLyons added go Go programming language support language An umbrella label for all programming languages syntax behaviors language server failure Language server doesn't work as expected language server An umbrella label for all language servers and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Sep 18, 2023
@ConradIrwin
Copy link
Member

@nikitavoloboev Thanks for sharing the issue!

I found that this repo worked for me when I opened it in Zed:

Screenshot 2023-09-18 at 9 17 08 AM

I am worried that there must be something different between our computers causing this.

To help us debug, would you mind opening this repo, and then doing cmd-shift-p debug: Open Language Server Logs and pasting any logs generated while trying to complete here?

@nikitavoloboev
Copy link
Author

https://gist.github.com/nikitavoloboev/5be6fb1411bb857dcce7156c7fa3cc80

here it is

I got the logs after doing this in a file

image

@ConradIrwin
Copy link
Member

Sorry for giving you poor instructions, these are unfortunately the logs for the tailwind language server.

At the top of the screen after going to cmd-shift-p debug: Open Language Server Logs there is a dropdown selector for which language. You'll need to select "Go language server (sol-pay)" and it should look like this:

Screenshot 2023-09-18 at 2 21 18 PM

@nikitavoloboev
Copy link
Author

@ConradIrwin

I think Go language server never got started as I don't see it here.

image

@ConradIrwin
Copy link
Member

ConradIrwin commented Sep 19, 2023 via email

@nikitavoloboev
Copy link
Author

Yes

image

@nikitavoloboev
Copy link
Author

actually i think it started downloading go lsp

image

now it gives this error

@nikitavoloboev
Copy link
Author

I think that means I need to create a go workspaces file at ~/src?

@ConradIrwin
Copy link
Member

@nikitavoloboev thanks for the screenshot!

This is caused by a poor handling of multiple go modules in go-pls (with a confusing error message to add to the confusion).

For more information see here: https://github.com/golang/tools/blob/master/gopls/doc/workspace.md, but TLDR you should be able to fix this by adding a go.work file at the top level that contains a list of directories containing modules and then running cmd-shift-p editor: Restart Language Server.

# go.work
go 1.21.1

use (
  ./go/sol-pay
  ./other/modules/...
)

Do you have the same issue in VSCode? If not I think we need to figure out how they work around this and copy that.

@JosephTLyons
Copy link
Collaborator

Thanks for jumping in here to help @ConradIrwin - appreciate it!

@JosephTLyons JosephTLyons transferred this issue from zed-industries/community Jan 24, 2024
@vxxvvxxv
Copy link

vxxvvxxv commented Feb 9, 2024

@ConradIrwin
Hello! I have an error when Zed tryied to download Language server:

Language server error: Go

failed to parse gopls version output

@mrnugget
Copy link
Member

mrnugget commented Feb 9, 2024

@vxxvvxxv what do you get when you run ls ~/Library/Application\ Support/Zed/languages/gopls/?

In my case, I see the gopls binary in there:

$ ls ~/Library/Application\ Support/Zed/languages/gopls/
gobin        gopls_0.14.2

Do you also have that? If so, what's the output when you run it with version as an arg? Like this:

$ ~/Library/Application\ Support/Zed/languages/gopls/gopls_0.14.2 version
golang.org/x/tools/gopls v0.14.2
    golang.org/x/tools/[email protected] h1:sIw6vjZiuQ9S7s0auUUkHlWgsCkKZFWDHmrge8LYsnc=

@SomeoneToIgnore
Copy link
Contributor

Also interesting to know the version it fails on — we did release a new binary yesterday, that included a fix for #7534 with the exact same error.

@vxxvvxxv
Copy link

vxxvvxxv commented Feb 9, 2024

@mrnugget I got this:

ls ~/Library/Application\ Support/Zed/languages/gopls/
gobin

@SomeoneToIgnore Zed notified me about auto-update, and after restarting, I have a new version (Zed 0.121.7).
After that, I wanted to open a Golang project for the first time and got this error.

I also tried downloading the latest release from GitHub, dragged Zed to Applications, opened it, and got the same thing.

Logs from Zed:

2024-02-09T20:08:56+06:00 [INFO] Opening main db
2024-02-09T20:09:06+06:00 [INFO] starting language server "gopls", path: "/Users/user/golang-project", id: 1
2024-02-09T20:09:15+06:00 [INFO] reload git repository ".git"
2024-02-09T20:09:16+06:00 [INFO] reload git repository ".git"
2024-02-09T20:09:17+06:00 [ERROR] crates/zed/src/languages/go.rs:358: no cached binary
2024-02-09T20:09:17+06:00 [ERROR] failed to start language server "gopls": failed to parse gopls version output
2024-02-09T20:09:17+06:00 [ERROR] server stderr: Some("")
2024-02-09T20:09:17+06:00 [ERROR] crates/zed/src/languages/go.rs:358: no cached binary
2024-02-09T20:09:17+06:00 [INFO] About to spawn test binary
2024-02-09T20:09:17+06:00 [WARN] test binary failed to launch
2024-02-09T20:09:17+06:00 [WARN] test binary check failed
2024-02-09T20:09:17+06:00 [INFO] beginning to reinstall server
2024-02-09T20:09:17+06:00 [INFO] deleting server container
2024-02-09T20:09:17+06:00 [INFO] starting language server "gopls", path: "/Users/user/golang-project", id: 2
2024-02-09T20:09:28+06:00 [ERROR] crates/zed/src/languages/go.rs:358: no cached binary
2024-02-09T20:09:28+06:00 [ERROR] failed to start language server "gopls": failed to parse gopls version output
2024-02-09T20:09:28+06:00 [ERROR] server stderr: Some("")
2024-02-09T20:09:28+06:00 [ERROR] crates/zed/src/languages/go.rs:358: no cached binary
2024-02-09T20:09:28+06:00 [INFO] About to spawn test binary
2024-02-09T20:09:28+06:00 [WARN] test binary failed to launch
2024-02-09T20:09:28+06:00 [WARN] test binary check failed
2024-02-09T20:09:28+06:00 [INFO] beginning to reinstall server
2024-02-09T20:09:28+06:00 [INFO] deleting server container
2024-02-09T20:09:28+06:00 [INFO] starting language server "gopls", path: "/Users/user/golang-project", id: 3
2024-02-09T20:09:33+06:00 [ERROR] crates/zed/src/languages/go.rs:358: no cached binary
2024-02-09T20:09:33+06:00 [ERROR] failed to start language server "gopls": failed to parse gopls version output
2024-02-09T20:09:33+06:00 [ERROR] server stderr: Some("")
2024-02-09T20:09:33+06:00 [ERROR] crates/zed/src/languages/go.rs:358: no cached binary
2024-02-09T20:09:33+06:00 [INFO] About to spawn test binary
2024-02-09T20:09:33+06:00 [WARN] test binary failed to launch
2024-02-09T20:09:33+06:00 [WARN] test binary check failed
2024-02-09T20:09:33+06:00 [INFO] beginning to reinstall server
2024-02-09T20:09:33+06:00 [INFO] deleting server container
2024-02-09T20:09:33+06:00 [INFO] starting language server "gopls", path: "/Users/user/golang-project", id: 4
2024-02-09T20:09:41+06:00 [ERROR] crates/zed/src/languages/go.rs:358: no cached binary
2024-02-09T20:09:41+06:00 [ERROR] failed to start language server "gopls": failed to parse gopls version output
2024-02-09T20:09:41+06:00 [ERROR] server stderr: Some("")
2024-02-09T20:09:41+06:00 [ERROR] crates/zed/src/languages/go.rs:358: no cached binary
2024-02-09T20:09:41+06:00 [INFO] About to spawn test binary
2024-02-09T20:09:41+06:00 [WARN] test binary failed to launch
2024-02-09T20:09:41+06:00 [WARN] test binary check failed
2024-02-09T20:09:41+06:00 [INFO] beginning to reinstall server
2024-02-09T20:09:41+06:00 [INFO] deleting server container
2024-02-09T20:09:41+06:00 [INFO] starting language server "gopls", path: "/Users/user/golang-project", id: 5
2024-02-09T20:09:49+06:00 [ERROR] crates/zed/src/languages/go.rs:358: no cached binary
2024-02-09T20:09:49+06:00 [ERROR] failed to start language server "gopls": failed to parse gopls version output
2024-02-09T20:09:49+06:00 [ERROR] server stderr: Some("")
2024-02-09T20:09:49+06:00 [ERROR] Hit 4 reinstallation attempts for "gopls"

@SomeoneToIgnore
Copy link
Contributor

SomeoneToIgnore commented Feb 9, 2024

This is very weird: just did rm -rf ~/Library/Application\ Support/Zed/languages/gopls/, opened a random go project with Zed 0.121.7, witnessed it downloading the binary and starting gopls successfully afterwards.

So it looks like we have the logic for checking go releases right but it does not work for you due to either some local network issues (doubtfully, since you're able to post here) or some GitHub rate limiting mechanism?

Unfortunately, that failed to parse gopls version output error is super uninformative, I'll add something better there right now.
Would you be able to build Zed from source and run it on a go project? cargo run project/directory/path from Zed source tree would be enough.

If not, then I could only suggest to wait a bit and try later: https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28 states that it allows 60 requests/hour for unauthenticated users.
Or, you could try to inspect Zed's traffic with external utilities and see what it gets in response from GitHub, if that's an option for you.

@SomeoneToIgnore
Copy link
Contributor

SomeoneToIgnore commented Feb 9, 2024

Thinking of it more, it is not actually a network error at this point?
It tries to start the server but somehow fails to get the output from it in the format it expects.

@vxxvvxxv
What if you also remove/move the ~/Library/Application\ Support/Zed/languages/gopls directory and try a fresh start?

@vxxvvxxv
Copy link

vxxvvxxv commented Feb 9, 2024

I just deleted the gopls directory and Zed downloaded it again, which looks correct.
But the error is the same.
Also connected a VPN, to check the file download, same result.

Unfortunately, I haven't seen any internet problems, nor do I think I'm catching Rate Limit (~5000 rps) from GitHub.

@SomeoneToIgnore
Now I will try to run Zed from the source.

SomeoneToIgnore added a commit that referenced this issue Feb 9, 2024
Part of
#4471 (comment)

Improves gopls error logging to actually see what is wrong with the
output we failed to match against the version regex.

Release Notes:

- N/A
@SomeoneToIgnore
Copy link
Contributor

Thank you for trying all that.

Great timing, please do a git pull before that so #7614 is in, that should be more descriptive, hopefully.

Apparently, that gopls that's being installed is somehow not conformant with the regex that's used to fetch the version.

@vxxvvxxv
Copy link

vxxvvxxv commented Feb 9, 2024

Thank you, yes I did before running git pull and the latest changes came in.

I followed all the steps that are described here:
https://github.com/zed-industries/zed/blob/main/docs/src/developing_zed__building_zed.md
but got an error on trying to do a cargo run:

cargo run
    Updating git repository `https://github.com/tree-sitter/tree-sitter`
error: failed to load source for dependency `tree-sitter`

Caused by:
  Unable to update https://github.com/tree-sitter/tree-sitter?rev=1d8975319c2d5de1bf710e7e21db25b0eee4bc66#1d897531

Caused by:
  failed to fetch into: /Users/sokol/.cargo/git/db/tree-sitter-60edc5fae03f2366

Caused by:
  failed to authenticate when downloading repository: ssh://[email protected]/tree-sitter/tree-sitter

  * attempted ssh-agent authentication, but no usernames succeeded: `git`

  if the git CLI succeeds then `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  no authentication methods succeeded

@SomeoneToIgnore
Copy link
Contributor

SomeoneToIgnore commented Feb 9, 2024

I think we could be onto something that breaks the gopls installation for you.
The error in question is the cargo one, related to odd combination of git settings and/or credentials related to those settings, but may also influence the way gopls is fetched?
rust-lang/cargo#3381 or related things could help, but I cannot provide anything specific due to zero clues about your local configs.

Glad to continue debugging after you deal with that one.

@SomeoneToIgnore
Copy link
Contributor

SomeoneToIgnore commented Feb 9, 2024

Alternative track to try, if cargo seems too alien: this is the code that tries to install gopls and run it with version command:

let gobin_dir = container_dir.join("gobin");
fs::create_dir_all(&gobin_dir).await?;
let install_output = process::Command::new("go")
.env("GO111MODULE", "on")
.env("GOBIN", &gobin_dir)
.args(["install", "golang.org/x/tools/gopls@latest"])
.output()
.await?;
anyhow::ensure!(
install_output.status.success(),
"failed to install gopls. Is `go` installed and in the PATH?"
);
let installed_binary_path = gobin_dir.join("gopls");
let version_output = process::Command::new(&installed_binary_path)
.arg("version")
.output()
.await
.context("failed to run installed gopls binary")?;

It should be more or less clear what it does from that piece, so you can try repro the CLI commands locally and see what is not right with gopls that gets fetched this way.

@vxxvvxxv
Copy link

vxxvvxxv commented Feb 9, 2024

Thank you! Yeah, that's what it's all about. I suppose it would be useful to add the Troubleshooting section.

echo '[net]\ngit-fetch-with-cli = true' >> ~/.cargo/config


The code seems correct. I am waiting to finish downloading dependencies for the cargo run command.

Also, I tried to run your command into bash and got this:

GO111MODULE=on \
GOBIN=/Users/sokol/Work/go/src/gitlab.com/zed-industries/tmp_g \
go install golang.org/x/tools/gopls@latest && \
/Users/sokol/Work/go/src/gitlab.com/zed-industries/tmp_g/gopls version

zsh: killed     /Users/sokol/Work/go/src/gitlab.com/zed-industries/tmp_g/gopls version

But if I try to run my locally gopls:

gopls version
golang.org/x/tools/gopls v0.14.2
    golang.org/x/tools/[email protected] h1:sIw6vjZiuQ9S7s0auUUkHlWgsCkKZFWDHmrge8LYsnc=

which gopls
/Users/sokol/Work/go/bin/gopls

Also, I tried to run the downloaded gopls from the Zed folder:

~/Library/Application\ Support/Zed/languages/gopls/gobin/gopls version
zsh: killed     ~/Library/Application\ Support/Zed/languages/gopls/gobin/gopls version

I'll post after I wait for the cargo run to be executed.

@pstjean
Copy link

pstjean commented Feb 9, 2024

~/Library/Application\ Support/Zed/languages/gopls/gobin/gopls version
zsh: killed     ~/Library/Application\ Support/Zed/languages/gopls/gobin/gopls version

I ran into this issue the other day, gopls was being compiled with an alternative llvm toolchain to the one Apple installs alongside Xcode. The underlying issue is documented here: golang/go/issues/63997

The issue is that the binary is not signed when compiled using this toolchain. Unsigned binaries are killed immediately on launch, which is the behavior we see here. I would try signing the Zed installed binary manually (see here).

@mrnugget
Copy link
Member

I'm going to close this, since a lot has changed with our gopls integration since the last activity in this issue (we not detect whether it already exists in path, we use the shell env for that path, ...). So if a problem pops up again, let's open a new ticket (ideally more specific) or reopen this one.

@pedronasser
Copy link

pedronasser commented Mar 25, 2024

I am still having issues with Zed and Gopls.

@mrnugget
Copy link
Member

@pedronasser Can you create a new ticket and provide some debugging information?

@quinn
Copy link

quinn commented Apr 26, 2024

I'm having this issue too. Not sure where to find debugging info, nothing shows in the log as far as I can tell

@quinn
Copy link

quinn commented Apr 26, 2024

image

I don't seem to have the go lsp at all for some reason.

@mrnugget
Copy link
Member

I'm having this issue too. Not sure where to find debugging info, nothing shows in the log as far as I can tell

You can also provide debugging information: what's the project setup? Do you use GOPATH? go.mod? Is it a monorepo?

Did you try go.work file? #10224 (comment)

@quinn
Copy link

quinn commented Apr 29, 2024

I'm using go modules, I have a go.mod file. Its not a monorepo, go.mod/go.sum are in the project root. I do not have a go.work file, haven't heard of this before. I assume that I only need that if using a monorepo?

@quinn
Copy link

quinn commented Apr 29, 2024

I just tried a totally fresh project (and installed gopls):

image

Is there any reason why the language server logs don't show up at all?

@mrnugget
Copy link
Member

Use zed: open log or look in ~/Library/Logs/Zed/Zed.log for more information.

@quinn
Copy link

quinn commented May 1, 2024

thanks @mrnugget I needed to asdf reshim 🤦

I found the error message in the logs. I had looked previously but must have missed it, tailing the log while it booted helped, rather than using zed: open log. I would love it if Zed alerted me when the lsp failed to boot, rather than failing silently.

@mrnugget
Copy link
Member

mrnugget commented May 2, 2024

I would love it if Zed alerted me when the lsp failed to boot, rather than failing silently.

Yeah that's a good point. Can you create a ticket with the relevant parts of the logs (meaning: shows where and why it failed) for this?

@simonbanyard
Copy link

If the version in go.mod has a patch version, it seems that the completions won't work. Changing it to display major. minor seems to fix the issue.

CleanShot 2024-05-07 at 21 26 09@2x

@mrnugget
Copy link
Member

mrnugget commented May 8, 2024

Yeah, that error comes from gopls and I also get it if I open a project with go 1.22.2 in Neovim, for example.

@algoflows
Copy link

not working for me either Golang is defunct with Zed.

@mrnugget
Copy link
Member

Hey @algoflows! I can't do much with that analysis. Can you create a ticket with details on your setup, log output, etc., anything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement [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 language An umbrella label for all programming languages syntax behaviors
Projects
None yet
Development

No branches or pull requests