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

"Unable to start gopls with multiple nested directories." #10224

Closed
1 task done
youngxhui opened this issue Apr 6, 2024 · 15 comments · Fixed by #12086
Closed
1 task done

"Unable to start gopls with multiple nested directories." #10224

youngxhui opened this issue Apr 6, 2024 · 15 comments · Fixed by #12086
Labels
bug [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 large projects For anything relating to large volumes of files or multiple subprojects in one main project.

Comments

@youngxhui
Copy link

Check for existing issues

  • Completed

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

image

my settings

// Zed settings
//
// For information on how to configure Zed, see the Zed
// documentation: https://zed.dev/docs/configuring-zed
//
// To see all of Zed's default settings without changing your
// custom settings, run the `open default settings` command
// from the command palette or from `Zed` application menu.
{
  "features": {
    "copilot": false
  },
  "theme": "One Dark",
  "telemetry": {
    "metrics": false
  },
  "autosave": {
    "after_delay": {
      "milliseconds": 3000
    }
  },
  "vim_mode": true,
  "ui_font_size": 18,
  "ui_font_family": "JetBrainsMono Nerd Font",
  "buffer_font_size": 18,
  "buffer_font_family": "JetBrainsMono Nerd Font Propo",
  "format_on_save": "off",
  "inlay_hints": {
    "enabled": false,
    "show_type_hints": true,
    "show_parameter_hints": true,
    "show_other_hints": true
  },
  "lsp": {
    "gopls": {
      "binary": {
        "path": "/Users/yangxiaohui/go/bin/gopls"
      },
      "initialization_options": {
        "hints": {
          "assignVariableTypes": true,
          "compositeLiteralFields": true,
          "compositeLiteralTypes": true,
          "constantValues": true,
          "functionTypeParameters": true,
          "parameterNames": true,
          "rangeVariableTypes": true
        }
      },
      "ui.semanticTokens": true,
      "symbolStyle": "Dynamic"
    }
  }
}

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"
}
]
}

@youngxhui youngxhui added admin read Pending admin review bug [core label] triage Maintainer needs to classify the issue labels Apr 6, 2024
@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 Apr 8, 2024
@JosephTLyons
Copy link
Collaborator

cc'ing in the go experts on the team @ConradIrwin @mrnugget

@mrnugget
Copy link
Member

mrnugget commented Apr 8, 2024

Given the following structure

nested-go-proj
└── src
    ├── go.mod
    └── main.go

2 directories, 2 files

When I open Zed at nested-go-proj, as part of initialize we send this:

    "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:

zed/crates/lsp/src/lsp.rs

Lines 691 to 695 in 4ce5b22

workspace_folders: Some(vec![WorkspaceFolder {
uri: root_uri,
name: Default::default(),
}]),
client_info: release_channel::ReleaseChannel::try_global(cx).map(|release_channel| {

But Neovim actively searches upwards for go.mod/go.work files from the current file and uses those as the the workspaceFolderes:

https://github.com/neovim/nvim-lspconfig/blob/9619e53d3f99f0ca4ea3b88f5d97fce703131820/lua/lspconfig/server_configurations/gopls.lua#L23

@mrnugget
Copy link
Member

mrnugget commented Apr 8, 2024

It works when using Go workspaces:

$ cd nested-go-proj
$ go work init
$ go work use src
$ zed .

Based on reading golang/go#32394 again it seems like that this is the official gopls solution to this problem (rust-analyzer handles nested projects fine without any additional configuration). VS Code's and neovim's solution can be kinda seen as a workaround, so I'm not sure whether we should really go down this path.

@Igneous
Copy link

Igneous commented Apr 23, 2024

It works when using Go workspaces

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.

@roanta
Copy link

roanta commented Apr 24, 2024

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 gopls language server is simply not working for me with this project.

The relevant zed log output:

2024-04-24T15:54:51-06:00 [INFO] starting language server "gopls", path: "/Users/*/workspace/grpc-go", id: 1
2024-04-24T15:54:52-06:00 [INFO] found user-installed language server for Go. path: "/Users/*/go/bin/gopls", arguments: ["-mode=stdio"]
2024-04-24T15:54:52-06:00 [INFO] starting language server. binary path: "/Users/*/go/bin/gopls", working directory: "/Users/*/workspace/grpc-go", args: ["-mode=stdio"]
2024-04-24T15:54:53-06:00 [INFO] Language server with id 1 sent unhandled notification client/unregisterCapability:
{
  "unregisterations": [
    {
      "id": "workspace/didChangeWatchedFiles-0",
      "method": "workspace/didChangeWatchedFiles"
    }
  ]
}

and if I open the lsp logs, this is seems to be the output correlated to those logs:

2024/04/24 15:54:53 go/packages.Load #2: updating metadata for 685 packages

Let me know if I'm missing something obvious here.

Thanks in advance!

@mrnugget
Copy link
Member

@roanta can you enable the RPC messages for gopls too? In debug: open language server logs, in the dropdown you should have two entries for gopls and one of them has a checkmark. Toggle that on and then open the logs again.

@roanta
Copy link

roanta commented Apr 25, 2024

Sure, the capture was done after I clicked clear in the lsp log tab and ran editor: restart language server command while I had the helloworld example open and I was clicking around.

// Receive:
{"jsonrpc":"2.0","method":"window/workDoneProgress/create","params":{"token":"2673758160344738593"},"id":1}
// Send:
{"jsonrpc":"2.0","id":1,"result":null}
// Receive:
{"jsonrpc":"2.0","method":"$/progress","params":{"token":"2673758160344738593","value":{"kind":"begin","title":"Setting up workspace","message":"Loading packages..."}}}
// Receive:
{"jsonrpc":"2.0","method":"workspace/configuration","params":{"items":[{"scopeUri":"file:///Users/*/workspace/grpc-go","section":"gopls"}]},"id":2}
// Send:
{"jsonrpc":"2.0","id":2,"result":[null]}
// Receive:
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/04/25 09:18:47 go info for /Users/*/workspace/grpc-go\n(view type GoModView)\n(root dir /Users/*/workspace/grpc-go)\n(go version go version go1.22.2 darwin/arm64)\n(build flags: [])\n(go env: {GOOS:darwin GOARCH:arm64 GOCACHE:/Users/*/Library/Caches/go-build GOMODCACHE:/Users/*/go/pkg/mod GOPATH:/Users/*/go GOPRIVATE:github.com/DataDog GOFLAGS: GO111MODULE:auto GoVersion:22 GoVersionOutput:go version go1.22.2 darwin/arm64\n GOWORK: GOPACKAGESDRIVER:})\n(env overlay: map[])\n\n"}}
// Receive:
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/04/25 09:18:48 go/packages.Load #1\n\tsnapshot=0\n\tdirectory=file:///Users/*/workspace/grpc-go\n\tquery=[/Users/*/workspace/grpc-go/... builtin]\n\tpackages=435\n"}}
// Receive:
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/04/25 09:18:48 go/packages.Load #1: updating metadata for 685 packages\n"}}
// Receive:
{"jsonrpc":"2.0","method":"$/progress","params":{"token":"2673758160344738593","value":{"kind":"end","message":"Finished loading packages."}}}
// Receive:
{"jsonrpc":"2.0","method":"client/registerCapability","params":{"registrations":[{"id":"workspace/didChangeWatchedFiles-0","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/*.{mod,work}","kind":7},{"globPattern":{"baseUri":"file:///Users/*/workspace/grpc-go","pattern":"**/*.{go,mod,sum,work}"},"kind":7}]}}]},"id":3}
// Send:
{"jsonrpc":"2.0","id":3,"result":null}
// Receive:
{"jsonrpc":"2.0","method":"client/registerCapability","params":{"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"}]},"id":4}
// Send:
{"jsonrpc":"2.0","id":4,"result":null}
// Receive:
{"jsonrpc":"2.0","method":"workspace/configuration","params":{"items":[{"section":"gopls"}]},"id":5}
// Send:
{"jsonrpc":"2.0","id":5,"result":[null]}
// Receive:
{"jsonrpc":"2.0","method":"workspace/configuration","params":{"items":[{"scopeUri":"file:///Users/*/workspace/grpc-go","section":"gopls"}]},"id":6}
// Send:
{"jsonrpc":"2.0","id":6,"result":[null]}
// Receive:
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/04/25 09:18:48 go info for /Users/*/workspace/grpc-go\n(view type GoModView)\n(root dir /Users/*/workspace/grpc-go)\n(go version go version go1.22.2 darwin/arm64)\n(build flags: [])\n(go env: {GOOS:darwin GOARCH:arm64 GOCACHE:/Users/*/Library/Caches/go-build GOMODCACHE:/Users/*/go/pkg/mod GOPATH:/Users/*/go GOPRIVATE:github.com/DataDog GOFLAGS: GO111MODULE:auto GoVersion:22 GoVersionOutput:go version go1.22.2 darwin/arm64\n GOWORK: GOPACKAGESDRIVER:})\n(env overlay: map[])\n\n"}}
// Receive:
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/04/25 09:18:48 go info for /Users/*/workspace/grpc-go\n(view type GoModView)\n(root dir /Users/*/workspace/grpc-go/examples)\n(go version go version go1.22.2 darwin/arm64)\n(build flags: [])\n(go env: {GOOS:darwin GOARCH:arm64 GOCACHE:/Users/*/Library/Caches/go-build GOMODCACHE:/Users/*/go/pkg/mod GOPATH:/Users/*/go GOPRIVATE:github.com/DataDog GOFLAGS: GO111MODULE:auto GoVersion:22 GoVersionOutput:go version go1.22.2 darwin/arm64\n GOWORK: GOPACKAGESDRIVER:})\n(env overlay: map[])\n\n"}}
// Receive:
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/04/25 09:18:48 go/packages.Load #3\n\tsnapshot=0\n\tdirectory=file:///Users/*/workspace/grpc-go\n\tquery=[/Users/*/workspace/grpc-go/examples/... builtin]\n\tpackages=64\n"}}
// Receive:
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/04/25 09:18:48 go/packages.Load #3: updating metadata for 463 packages\n"}}
// Receive:
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/04/25 09:18:48 go/packages.Load #2\n\tsnapshot=0\n\tdirectory=file:///Users/*/workspace/grpc-go\n\tquery=[/Users/*/workspace/grpc-go/... builtin]\n\tpackages=435\n"}}
// Receive:
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2024/04/25 09:18:48 go/packages.Load #2: updating metadata for 685 packages\n"}}
// Receive:
{"jsonrpc":"2.0","method":"client/registerCapability","params":{"registrations":[{"id":"workspace/didChangeWatchedFiles-1","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/*.{mod,work}","kind":7},{"globPattern":{"baseUri":"file:///Users/*/workspace/grpc-go","pattern":"**/*.{go,mod,sum,work}"},"kind":7},{"globPattern":{"baseUri":"file:///Users/*/workspace/grpc-go/examples","pattern":"**/*.{go,mod,sum,work}"},"kind":7}]}}]},"id":7}
// Send:
{"jsonrpc":"2.0","id":7,"result":null}
// Receive:
{"jsonrpc":"2.0","method":"client/unregisterCapability","params":{"unregisterations":[{"id":"workspace/didChangeWatchedFiles-0","method":"workspace/didChangeWatchedFiles"}]},"id":8}
// Receive:
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go","diagnostics":[]}}
// Send:
{"jsonrpc":"2.0","id":2,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":27,"character":0}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":2}}
// Send:
{"jsonrpc":"2.0","id":3,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":27,"character":0}}}
// Send:
{"jsonrpc":"2.0","id":4,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"range":{"start":{"line":27,"character":0},"end":{"line":27,"character":0}},"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","source"]}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":3}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":4}}
// Send:
{"jsonrpc":"2.0","id":5,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":21,"character":8}}}
// Send:
{"jsonrpc":"2.0","id":6,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"range":{"start":{"line":21,"character":8},"end":{"line":21,"character":8}},"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","source"]}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":5}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":6}}
// Send:
{"jsonrpc":"2.0","id":7,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":33,"character":28}}}
// Send:
{"jsonrpc":"2.0","id":8,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"range":{"start":{"line":33,"character":28},"end":{"line":33,"character":28}},"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","source"]}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":7}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":8}}
// Send:
{"jsonrpc":"2.0","id":9,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":33,"character":19}}}
// Send:
{"jsonrpc":"2.0","id":10,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"range":{"start":{"line":33,"character":19},"end":{"line":33,"character":19}},"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","source"]}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":9}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":10}}
// Send:
{"jsonrpc":"2.0","id":11,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":37,"character":15}}}
// Send:
{"jsonrpc":"2.0","id":12,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"range":{"start":{"line":37,"character":15},"end":{"line":37,"character":15}},"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","source"]}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":11}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":12}}
// Send:
{"jsonrpc":"2.0","id":13,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":38,"character":12}}}
// Send:
{"jsonrpc":"2.0","id":14,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"range":{"start":{"line":38,"character":12},"end":{"line":38,"character":12}},"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","source"]}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":13}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":14}}
// Send:
{"jsonrpc":"2.0","id":15,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":38,"character":14}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":15}}
// Send:
{"jsonrpc":"2.0","id":16,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":38,"character":14}}}
// Send:
{"jsonrpc":"2.0","id":17,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":38,"character":18}}}
// Send:
{"jsonrpc":"2.0","id":18,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":38,"character":19}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":17}}
// Send:
{"jsonrpc":"2.0","id":19,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":38,"character":20}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":18}}
// Send:
{"jsonrpc":"2.0","id":20,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":38,"character":21}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":19}}
// Send:
{"jsonrpc":"2.0","id":21,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"range":{"start":{"line":38,"character":14},"end":{"line":38,"character":14}},"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","source"]}}}
// Send:
{"jsonrpc":"2.0","id":22,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":38,"character":21}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":20}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":22}}
// Send:
{"jsonrpc":"2.0","id":23,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":36,"character":30}}}
// Send:
{"jsonrpc":"2.0","id":24,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":36,"character":31}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":23}}
// Send:
{"jsonrpc":"2.0","id":25,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":36,"character":31}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":24}}
// Send:
{"jsonrpc":"2.0","id":26,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":36,"character":32}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":25}}
// Send:
{"jsonrpc":"2.0","id":27,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":36,"character":33}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":26}}
// Send:
{"jsonrpc":"2.0","id":28,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":36,"character":34}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":27}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":28}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":16}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":21}}
// Send:
{"jsonrpc":"2.0","id":29,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":38,"character":17}}}
// Send:
{"jsonrpc":"2.0","id":30,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"range":{"start":{"line":38,"character":17},"end":{"line":38,"character":17}},"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","source"]}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":29}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":30}}
// Send:
{"jsonrpc":"2.0","id":31,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":37,"character":20}}}
// Send:
{"jsonrpc":"2.0","id":32,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"range":{"start":{"line":37,"character":20},"end":{"line":37,"character":20}},"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","source"]}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":31}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":32}}
// Send:
{"jsonrpc":"2.0","id":33,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":37,"character":18}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":33}}
// Send:
{"jsonrpc":"2.0","id":34,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":37,"character":18}}}
// Send:
{"jsonrpc":"2.0","id":35,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"range":{"start":{"line":37,"character":18},"end":{"line":37,"character":18}},"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","source"]}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":34}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":35}}
// Send:
{"jsonrpc":"2.0","id":36,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":37,"character":15}}}
// Send:
{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":36}}
// Send:
{"jsonrpc":"2.0","id":37,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"position":{"line":37,"character":18}}}
// Send:
{"jsonrpc":"2.0","id":38,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/*/workspace/grpc-go/examples/helloworld/greeter_server/main.go"},"range":{"start":{"line":37,"character":12},"end":{"line":37,"character":18}},"context":{"diagnostics":[],"only":["","quickfix","refactor","refactor.extract","source"]}}}

Let me know if you need anything else.

@mrnugget
Copy link
Member

@roanta I can't reproduce this. It works fine for me with grpc-go:

$ git clone [... grpc-go ...]
$ cd grpc-go
$ zed .

screenshot-2024-04-29-14 35 43@2x

Since you seem to use a user-installed gopls and it seems like it does start up, you could try to start it with debug server and see what that says. In your Zed settings:

{
  "lsp": {
    "gopls": {
      "binary": {
         "path": "/Users/your-username/bin/gopls",
         "arguments": ["-debug=0.0.0.0:9090"]
       }
    }
  }
}

@roanta
Copy link

roanta commented Apr 30, 2024

@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 go.mod which is the exact issue described above and why it wasn't working. I tried it with go files in the root directory of the project and it worked as expected. One thing to note is that if gopls is started (via zed) in a directory with a nested go.mod it basically gets stuck in a "bad" state, even if I open a file the directory with the root go.mod it won't work. I need to editor: restart language server while I have a file open which is in the root directory.

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 🤷 .

@Igneous
Copy link

Igneous commented Apr 30, 2024

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:
https://github.com/Igneous/zed-gopls-bug

@mrnugget
Copy link
Member

@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.

@Igneous
Copy link

Igneous commented Apr 30, 2024

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.

@mrnugget
Copy link
Member

No worries! You'll never see me complain about a succinct reproduction of an issue :)

@mikayla-maki mikayla-maki added the large projects For anything relating to large volumes of files or multiple subprojects in one main project. label May 9, 2024
mrnugget added a commit that referenced this issue May 21, 2024
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.
mrnugget added a commit that referenced this issue May 21, 2024
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)).
@mrnugget
Copy link
Member

Just to leave an update here: I'm pretty sure I fixed this in #12086. Turns out that gopls got stuck when opened at the root folder because it tried to unregister something and Zed never replied to the request.

@Igneous
Copy link

Igneous commented May 22, 2024

Yep, definitely working now -- you rock!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [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 large projects For anything relating to large volumes of files or multiple subprojects in one main project.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants