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

Fails to start gopls, "not a directory" #11361

Closed
1 task done
llimllib opened this issue May 3, 2024 · 1 comment · Fixed by #12129
Closed
1 task done

Fails to start gopls, "not a directory" #11361

llimllib opened this issue May 3, 2024 · 1 comment · Fixed by #12129
Labels
defect [core label] go Go programming language support language server An umbrella label for all language servers language An umbrella label for all programming languages syntax behaviors

Comments

@llimllib
Copy link

llimllib commented May 3, 2024

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

  1. clone https://github.com/llimllib/git-ls
  2. open main.go
  3. note that there's no LSP, and a failure I don't understand is in the logs

The logs have the error: err: fork/exec /opt/homebrew/bin/go: not a directory (see below for context). The error is correct in that /opt/homebrew/bin/go is not a directory, but a symlink to my go binary:

$ which go
/opt/homebrew/bin/go
$ ls -alh /opt/homebrew/bin/go
lrwxr-xr-x 1 llimllib 26 May  2 11:15 /opt/homebrew/bin/go -> ../Cellar/go/1.22.2/bin/go*

gopls works as expected in neovim, with the same go and gopls install:

 Client: gopls (id: 2, bufnr: [1])
 	filetypes:       go, gomod, gowork, gotmpl
 	autostart:       true
 	root directory:  /Users/llimllib/code/git-ls
 	cmd:             /Users/llimllib/go/bin/gopls

~/go/bin/gopls is version 0.15.2:

$ ~/go/bin/gopls version
golang.org/x/tools/gopls v0.15.2

Environment

Zed: v0.133.7 (Zed)
OS: macOS 14.4.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 ~/Library/Logs/Zed/Zed.log file to this issue.

2024-05-03T11:54:01-04:00 [INFO] starting language servers for Go: gopls
2024-05-03T11:54:01-04:00 [INFO] starting language servers for JSON: json-language-server
2024-05-03T11:54:01-04:00 [INFO] stopping language server gopls
2024-05-03T11:54:01-04:00 [WARN] Generic lsp request to gopls failed: oneshot canceled
2024-05-03T11:54:01-04:00 [ERROR] crates/lsp/src/lsp.rs:768: oneshot canceled
2024-05-03T11:54:01-04:00 [WARN] Generic lsp request to gopls failed: oneshot canceled
2024-05-03T11:54:01-04:00 [ERROR] crates/lsp/src/lsp.rs:352: cannot read LSP message headers
2024-05-03T11:54:01-04:00 [ERROR] crates/project/src/project.rs:6949: oneshot canceled
2024-05-03T11:54:01-04:00 [INFO] starting language servers for Go: gopls
2024-05-03T11:54:01-04:00 [INFO] starting language server "gopls", path: "/Users/llimllib/code/git-ls/main.go", id: 4
2024-05-03T11:54:01-04:00 [ERROR] crates/editor/src/editor.rs:3876: oneshot canceled
2024-05-03T11:54:01-04:00 [INFO] found user-installed language server for Go. path: "/Users/llimllib/go/bin/gopls", arguments: ["-mode=stdio"]
2024-05-03T11:54:01-04:00 [INFO] starting language server. binary path: "/Users/llimllib/go/bin/gopls", working directory: "/Users/llimllib/code/git-ls", args: ["-mode=stdio"]
2024-05-03T11:54:01-04:00 [INFO] Language server with id 4 sent unhandled notification window/showMessage:
{
  "type": 1,
  "message": "Error loading workspace folders (expected 1, got 0)\nfailed to load view for file:///Users/llimllib/code/git-ls/main.go: err: fork/exec /opt/homebrew/bin/go: not a directory: stderr: \n"
}
2024-05-03T11:54:01-04:00 [WARN] Generic lsp request to node failed: Unhandled method textDocument/definition
2024-05-03T11:54:01-04:00 [INFO] Language server with id 4 sent unhandled notification client/unregisterCapability:
{
  "unregisterations": [
    {
      "id": "workspace/didChangeWatchedFiles-0",
      "method": "workspace/didChangeWatchedFiles"
    }
  ]
}
@llimllib llimllib added admin read Pending admin review defect [core label] triage Maintainer needs to classify the issue labels May 3, 2024
@llimllib
Copy link
Author

llimllib commented May 3, 2024

Ah ha! I think this is related to #8764 - this only occurs if I start zed on a go file, which doesn't appear to load a workspace.

So, this fails: open -a /Applications/Zed.app main.go

But this succeeds: open -a /Applications/Zed.app . in the folder containing main.go, then opening up main.go

It seems like in the failure case, zed should be providing the cwd to gopls but it's not

@JosephTLyons JosephTLyons added language An umbrella label for all programming languages syntax behaviors go Go programming language support language server An umbrella label for all language servers and removed triage Maintainer needs to classify the issue admin read Pending admin review labels May 3, 2024
mrnugget added a commit that referenced this issue May 22, 2024
This fixes #11361 and #8764 by making sure we pass a directory as
`WorkspaceFolder` to the language server.

We already compute the `working_dir` correctly when
`self.root_path.is_file()`, but we didn't use it.

This now makes use of the file.
mrnugget added a commit that referenced this issue May 22, 2024
This fixes #11361 and #8764 by making sure we pass a directory as
`WorkspaceFolder` to the language server.

We already compute the `working_dir` correctly when
`self.root_path.is_file()`, but we didn't use it.

Release Notes:

- Fixed language servers (such as `gopls`) not starting up correctly
when opening a single file in Zed.
([#11361](#11361) and
[#8764](#8764)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect [core label] go Go programming language support language server An umbrella label for all language servers language An umbrella label for all programming languages syntax behaviors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants