-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
"Unable to start gopls with multiple nested directories." #10224
Comments
cc'ing in the go experts on the team @ConradIrwin @mrnugget |
Given the following structure
When I open Zed at "rootUri": "file:///Users/thorstenball/work/projs/nested-go-proj",
"workspaceFolders": [
{
"uri": "file:///Users/thorstenball/work/projs/nested-go-proj",
"name": ""
}
] But Neovim, for example, sends this: rootPath = "/Users/thorstenball/work/projs/nested-go-proj/src",
rootUri = "file:///Users/thorstenball/work/projs/nested-go-proj/src",
trace = "off",
workspaceFolders = { {
name = "/Users/thorstenball/work/projs/nested-go-proj/src",
uri = "file:///Users/thorstenball/work/projs/nested-go-proj/src"
} } So I'm wondering whether we have to become smarter here with how we initialize language servers. Right now we only send the root folder: Lines 691 to 695 in 4ce5b22
But Neovim actively searches upwards for |
It works when using Go workspaces:
Based on reading golang/go#32394 again it seems like that this is the official |
This is good to know there's a fix for this, but it's worth mentioning that neovim/mason, helix, and vscode support this behavior of shifting to the root directory of the most-adjacent go.mod out of the box (as a fallback, I suppose). imo it's reasonable for zed to punt the responsibility back on the dev to set up go workspaces, but if that's the judgement call being made here, it's probably good to at least mention it in an FAQ or something. |
I'm seeing a similar error as above when trying to open grpc-go where the mod file is in the root directory. The symptom is that the The relevant zed log output:
and if I open the lsp logs, this is seems to be the output correlated to those logs:
Let me know if I'm missing something obvious here. Thanks in advance! |
@roanta can you enable the RPC messages for |
Sure, the capture was done after I clicked
Let me know if you need anything else. |
@roanta I can't reproduce this. It works fine for me with
Since you seem to use a user-installed {
"lsp": {
"gopls": {
"binary": {
"path": "/Users/your-username/bin/gopls",
"arguments": ["-debug=0.0.0.0:9090"]
}
}
}
}
|
@mrnugget Okay thanks so much for trying this out. I actually missed the fact that the examples directory I was trying to navigate has a nested Fwiw: I've ended up just switching between vscode and zed for various projects when I run into this. Another alternative is to just open up the nested directories within a project. Either way, it's not ideal. I understand the position that the recommendation from the golang community is to use workspaces for nested mod files like this, but at the same time the vscode plugin (which if IIUC is blessed by the go community) just works under these scenarios 🤷 . |
Just to chime in -- a simpler example that might help you trigger this behavior: In my usecase, I'm opening zed at the root of my non-go monorepo, then opening a subfolder containing a go module and go code. In this case, gopls starts but offers no suggestions. Here's a quick and dirty repo that (hopefully?) reproduces the bug: |
@Igneous yep, that's exactly what this issue is about. Again: it's not strictly a bug, but more a lack of a feature. See comment above: #10224 (comment) We just need to make it work. |
Sorry @mrnugget, I thought you were having trouble reproducing this behavior at all -- that's the only reason I chimed in. Thank you, carry on. |
No worries! You'll never see me complain about a succinct reproduction of an issue :) |
This fixes #10224 by handling `client/unregisterCapability` requests that have a `workspace/didChangeWatchedFiles` method. While debugging the issue, I found out that `gopls` seems to block indefinitely when there's no reply to the `client/unregisterCapability` request. Even an empty response would fix the issue. Seems like gopls 15.x and later seem to handle nested subfolders well, but do not handle unanswered requests. Instead of replying with an empty response, I decided to change how we handle file watching and keep a list of all registered paths so that we can then unregister paths and recreate the glob patterns.
This fixes #10224 by handling `client/unregisterCapability` requests that have a `workspace/didChangeWatchedFiles` method. While debugging the issue, I found out that `gopls` seems to block indefinitely when there's no reply to the `client/unregisterCapability` request. Even an empty response would fix the issue. Seems like gopls 15.x and later seem to handle nested subfolders well, but do not handle unanswered requests. Instead of replying with an empty response, I decided to change how we handle file watching and keep a list of all registered paths so that we can then unregister paths and recreate the glob patterns. Release Notes: - Fixed `gopls` not working correctly when the `go.mod` file was in a subfolder and not the root folder of the project opened in Zed. ([#10224](#10224)).
Just to leave an update here: I'm pretty sure I fixed this in #12086. Turns out that |
Yep, definitely working now -- you rock! |
Check for existing issues
Describe the bug / provide steps to reproduce it
If the opened directory is 6.5840, the LSP not work , and there are no code suggestions. If the opened directory is 'src', everything works fine.
project:
git clone git://g.csail.mit.edu/6.5840-golabs-2024 6.5840
my settings
Environment
Zed: v0.129.2 (Zed)
OS: macOS 14.4.1
Memory: 16 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-04-05T22:16:47-07:00 [INFO] ========== starting zed ==========
2024-04-05T22:16:47-07:00 [INFO] Opening main db
2024-04-05T22:16:47-07:00 [INFO] set environment variables from shell:/opt/homebrew/bin/fish, path:/opt/homebrew/sbin:/Users/yangxiaohui/go/bin:/opt/homebrew/opt/[email protected]/bin:/opt/homebrew/bin/:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin
2024-04-05T22:16:47-07:00 [INFO] Opening main db
2024-04-05T22:16:47-07:00 [INFO] building git repository,
.git
path in the worktree: ".git"2024-04-05T22:16:47-07:00 [INFO] Opening main db
2024-04-05T22:16:47-07:00 [INFO] Opening main db
2024-04-05T22:16:47-07:00 [ERROR] crates/workspace/src/persistence/model.rs:268: No worktree for path: "/Users/yangxiaohui/.config/zed/settings.json"
2024-04-05T22:16:48-07:00 [INFO] set status on client 0: Authenticating
2024-04-05T22:16:48-07:00 [INFO] set status on client 65188: Connecting
2024-04-05T22:16:48-07:00 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-04-05T22:16:49-07:00 [INFO] add connection to peer
2024-04-05T22:16:49-07:00 [INFO] waiting for server hello
2024-04-05T22:16:49-07:00 [INFO] got server hello
2024-04-05T22:16:49-07:00 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 387, id: 1118833 })
2024-04-05T22:16:49-07:00 [INFO] set status on client 65188: Connected { peer_id: PeerId { owner_id: 387, id: 1118833 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-04-05T22:16:56-07:00 [INFO] installing extension make latest version
2024-04-05T22:16:57-07:00 [INFO] rebuilt extension index in 3.762ms
2024-04-05T22:16:57-07:00 [INFO] extensions updated. loading 1, reloading 0, unloading 0
2024-04-05T22:17:02-07:00 [INFO] installing extension git-firefly latest version
2024-04-05T22:17:02-07:00 [INFO] rebuilt extension index in 4.736166ms
2024-04-05T22:17:02-07:00 [INFO] extensions updated. loading 1, reloading 0, unloading 0
2024-04-05T22:17:08-07:00 [INFO] starting language server "gopls", path: "/Users/yangxiaohui/mit6824/project", id: 1
2024-04-05T22:17:08-07:00 [INFO] found user-installed language server for Go. path: "/Users/yangxiaohui/go/bin/gopls", arguments: []
2024-04-05T22:17:08-07:00 [INFO] starting language server. binary path: "/Users/yangxiaohui/go/bin/gopls", working directory: "/Users/yangxiaohui/mit6824/project", args: []
2024-04-05T22:17:08-07:00 [INFO] Language server with id 1 sent unhandled notification client/unregisterCapability:
{
"unregisterations": [
{
"id": "workspace/didChangeWatchedFiles-0",
"method": "workspace/didChangeWatchedFiles"
}
]
}
The text was updated successfully, but these errors were encountered: