microsoft / vscode-go

An extension for VS Code which provides support for the Go language. We have moved to https://github.com/golang/vscode-go
Other
5.93k stars 648 forks source link

Frequent pop-up when saving with "Getting code actions: Go, Go, ..." #3179

Closed stamblerre closed 4 years ago

stamblerre commented 4 years ago

If you encounter this issue, please try the following steps to troubleshoot:

  1. Check your other installed extensions. Go Group Imports and Spell Right have both been identified as causing slow saves.
  2. Your workspace may have errors which are causing gopls to be slow. Capture your gopls logs and post them here (if you're able to share them). Detailed gopls logs are best, so please add the -rpc.trace to go.languageServerFlags.

For reference, this bug is referring to an error that appears like this: image

This issue consolidates https://github.com/microsoft/vscode-go/issues/3063, https://github.com/microsoft/vscode-go/issues/3105, https://github.com/microsoft/vscode-go/issues/3141, https://github.com/microsoft/vscode-go/issues/3170, etc.

hairyhenderson commented 4 years ago

@stamblerre I was seeing this dialog for a little bit, but now it's not popping up at all and gopls seems to be ... napping?

I'm seeing this error in the logs:

[Error - 5:05:20 p.m.] 2020/04/16 17:05:20 failed to load workspace packages, skipping diagnostics: github.com/myorg/myproject/api/model has no metadata
    snapshot=10087
    directory=file:///Users/hairyhenderson/go/src/github.com/myorg/myproject

I did delete the api/model directory (with a git rm command in a shell), but it appears something went out of sync and thinks that directory is still around?

stamblerre commented 4 years ago

That's definitely possible - thanks for the report @hairyhenderson. I'll add a regression test for this case (https://github.com/golang/go/issues/38407#issuecomment-614938365). Ctrl + Shift + P -> Go: Restart Language Server should fix it temporarily.

hairyhenderson commented 4 years ago

@stamblerre thanks! That's a super-helpful shortcut! I usually just ps -eaf | grep gopls and kill one at random until the right one restarts πŸ˜‚

Wisgon commented 4 years ago

That's definitely possible - thanks for the report @hairyhenderson. I'll add a regression test for this case (golang/go#38407 (comment)). Ctrl + Shift + P -> Go: Restart Language Server should fix it temporarily.

It doesn't work for me. When I Ctrl + Shift + P -> Go: Restart Language Server , Nothing happen and there is no code hintting any more, though I wait a long time. Finally I have to restart vscode.

By the way, I got gopls error message:

[Info  - 上午11:41:17] 2020/05/07 11:41:17 go/packages.Load
    snapshot=0
    directory=D:\Documents\my_projects\learn_micro
    query=[./... builtin]
    packages=17
[Error - 上午11:41:18] Request textDocument/foldingRange failed.
  Message: invalid pos
  Code: 0 
[Error - 上午11:41:18] 2020/05/07 11:41:18 DocumentSymbols failed: invalid pos
    URI=file:///D:/Documents/my_projects/learn_micro/grpcConsulDemo/simpleClient_test.go
[Error - 上午11:57:02] Request textDocument/foldingRange failed.
  Message: invalid pos
  Code: 0 
[Error - 上午11:57:02] 2020/05/07 11:57:02 DocumentSymbols failed: invalid pos
    URI=file:///D:/Documents/my_projects/learn_micro/grpcConsulDemo/simpleClient_test.go
[Error - 上午11:57:02] Request textDocument/codeAction failed.
  Message: computing fix edits: D:\Documents\my_projects\learn_micro\grpcConsulDemo\simpleClient_test.go:16:6: expected operand, found ',' (and 9 more errors)
  Code: 0 
[Error - 上午11:57:02] Request textDocument/codeAction failed.
  Message: computing fix edits: D:\Documents\my_projects\learn_micro\grpcConsulDemo\simpleClient_test.go:16:6: expected operand, found ',' (and 9 more errors)
  Code: 0 
[Error - 上午11:57:02] Request textDocument/formatting failed.
  Message: 16:6: expected operand, found ',' (and 2 more errors)
  Code: 0 
[Error - 上午11:57:02] Request textDocument/codeAction failed.
  Message: computing fix edits: D:\Documents\my_projects\learn_micro\grpcConsulDemo\simpleClient_test.go:16:6: expected operand, found ',' (and 9 more errors)
  Code: 0 

I know I have syntax error in my code, that not the key, the key point is, the Saving 'main.go': Getting code actions from ''Go', 'Go'' (configure). takes too much time.

stamblerre commented 4 years ago

@Wisgon: If you add

"go.languageServerFlags": [
  "-rpc.trace"
]

to your VS Code settings, it should give you more detailed information. However, if your project is very large / has a lot of dependencies, it's possible that something else is going wrong.

bobheadxi commented 4 years ago

Restarting the language server didn't do anything for me, but @onlyafly 's recommendation to downgrade the Go extension to 0.13.1 solved the issue completely

Things I tried:

stamblerre commented 4 years ago

@bobheadxi: This error usually starts happening when there is some misconfiguration or issue with gopls. Please take a look at the first comment on this issue (https://github.com/microsoft/vscode-go/issues/3179#issue-600430641) for advice on how to troubleshoot this.

stamblerre commented 4 years ago

Going to close this issue, as I haven't heard of many people encountering this recently.