PSA: improved go module support in vscode

169 views
Skip to first unread message

Jordan Liggitt

unread,
Apr 25, 2019, 9:42:26 AM4/25/19
to Kubernetes developer/contributor discussion
Now that kubernetes/kubernetes has go.mod files in place, some development environments perform differently when resolving code references, autocomplete, etc

For those using vscode, a recent release greatly improved responsiveness when using go modules. With that update, resolving code references, hover help, and autocomplete went from taking several seconds to being almost instant for me with these settings:

    "go.formatTool": "goimports",
    "go.useLanguageServer": true,
    "go.toolsEnvVars": {
        "GO111MODULE": "on",
        "GOFLAGS": "-mod=vendor"
    },

Hopefully that improves someone else's day as much as it did mine.

Jordan

Miao Zhou

unread,
Apr 26, 2019, 4:05:55 AM4/26/19
to Kubernetes developer/contributor discussion
"Go: Format Tool" setting has such desc
Not applicable when using the language server.

"go.formatTool": "goimports",
"go.useLanguageServer": true,

Do these two settings conflict?

在 2019年4月25日星期四 UTC+8下午9:42:26,Jordan Liggitt写道:

Andrew Kim

unread,
Apr 29, 2019, 4:14:08 PM4/29/19
to Kubernetes developer/contributor discussion
For any folks using vim-go, starting in v1.20, you can also get improved go module support by setting `let g:go_def_mode='gopls'` in your `.vimrc` file and the following go settings:

GOFLAGS="-mod=vendor"
GO111MODULE=on

The first jump-to-definition from gopls will be slow but after it's cache fills up it should be much faster.
Happy to help folks get their vim config setup for Kubernetes (@a_sykim on slack).

Wei Huang

unread,
May 17, 2019, 1:20:13 AM5/17/19
to Kubernetes developer/contributor discussion
A relevant tip for your reference if you're using vscode.

Sometime late last year, I happened to see some of files autosaved with an unnecessary import alias like:

```go
import (
)
```

This really annoyed me, and finally I found the solution to change default formatting tool from `goimports` to `gofmt`.

Everything works fine since then.

Recently after switching to gomod, I found the "Go to definition" (CMD+click) gets really slow. And I found a solution to enable `go.useLanguageServer` which dramatically improves the performance. However, it brings in back the annoying "unnecessary v1 alias" issue. I guess it's because the builtin formatting tool in `gopls` is `goimports`. I tried to disable the formatting option in "go.languageServerExperimentalFeatures", but it didn't work. Then surprisingly I found a magic combination with (1) source.organizeImports=false and (2) languageServerExperimentalFeatures.format=false can resolve the issue. FYI my configuration:

```json
{
    "[go]": {
        "editor.snippetSuggestions": "none",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": false
        },
    },
    "go.useLanguageServer": true,
    "go.languageServerExperimentalFeatures": {
         "format": false
    },
    "go.toolsEnvVars": {
        "GO111MODULE": "on",
        "GOFLAGS": "-mod=vendor"
    },
    "go.formatTool": "gofmt"
}
```

Kevin Wiesmüller

unread,
May 20, 2019, 7:18:58 AM5/20/19
to Kubernetes developer/contributor discussion
With vscode and gopls, do you as well see problems with performance in the K8s repo?
I often more than every 5 minutes got to reload the vscode window to restart gopls because it is using up all cores and ram without delivering any results.
(varying errors like exceeding queue etc.)
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages