zed icon indicating copy to clipboard operation
zed copied to clipboard

"Unable to start gopls with multiple nested directories."

Open youngxhui opened this issue 1 year ago • 13 comments

Check for existing issues

  • [X] 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 avatar Apr 06 '24 05:04 youngxhui

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

JosephTLyons avatar Apr 08 '24 04:04 JosephTLyons

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: https://github.com/zed-industries/zed/blob/4ce5b229895a961d6ebadd22da3f8d5176b8f3a4/crates/lsp/src/lsp.rs#L691-L695

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 avatar Apr 08 '24 13:04 mrnugget

It works when using Go workspaces:

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

Based on reading https://github.com/golang/go/issues/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.

mrnugget avatar Apr 08 '24 13:04 mrnugget

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.

Igneous avatar Apr 23 '24 03:04 Igneous

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!

roanta avatar Apr 24 '24 22:04 roanta

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

mrnugget avatar Apr 25 '24 11:04 mrnugget

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.

roanta avatar Apr 25 '24 15:04 roanta

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

mrnugget avatar Apr 29 '24 12:04 mrnugget

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

roanta avatar Apr 30 '24 00:04 roanta

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

Igneous avatar Apr 30 '24 00:04 Igneous

@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: https://github.com/zed-industries/zed/issues/10224#issuecomment-2042812083

We just need to make it work.

mrnugget avatar Apr 30 '24 07:04 mrnugget

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.

Igneous avatar Apr 30 '24 07:04 Igneous

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

mrnugget avatar Apr 30 '24 07:04 mrnugget

Just to leave an update here: I'm pretty sure I fixed this in https://github.com/zed-industries/zed/pull/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.

mrnugget avatar May 22 '24 13:05 mrnugget

Yep, definitely working now -- you rock!

Igneous avatar May 22 '24 14:05 Igneous