vscode-go
vscode-go copied to clipboard
Displays "No code actions available" for generic structs when trying to use "fill struct" feature
What version of Go, VS Code & VS Code Go extension are you using?
Version Information
- Run
go versionto get version of Go from the VS Code integrated terminal.- go version go1.18 linux/amd64
- Run
gopls -v versionto get version of Gopls from the VS Code integrated terminal.
gopls -v version
bash: gopls: command not found...
Install package 'golang-x-tools-gopls' to provide command 'gopls'? [N/y]
However, going into my home directory, I see that there is a binary called gopls. I'm assuming this is the one VS Code is using.
~/go/bin > pwd
/home/mattwelke/go/bin
~/go/bin > ./gopls -v version
Build info
----------
golang.org/x/tools/gopls v0.8.3
golang.org/x/tools/[email protected] h1:Mxm94ix8oSARQ6svioO6SxKEYWT/VCP54/448LOHzrk=
github.com/BurntSushi/[email protected] h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
github.com/google/[email protected] h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/sergi/[email protected] h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
golang.org/x/exp/[email protected] h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=
golang.org/x/[email protected] h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
golang.org/x/[email protected] h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/[email protected] h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
golang.org/x/[email protected] h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/[email protected] h1:rYiuK/jn6TCxjAq1hQ6MR6pgOeP3A5gIHDxgrQ8Vbys=
golang.org/x/[email protected] h1:9dMzk88fnONra7zrEalqkRMGa9jMGf9B5mdzhYVyI28=
golang.org/x/[email protected] h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
honnef.co/go/[email protected] h1:2LdYUZ7CIxnYgskbUZfY7FPggmqnh6shBqfWa8Tn3XU=
mvdan.cc/[email protected] h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
mvdan.cc/xurls/[email protected] h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.18
- Run
code -vorcode-insiders -vto get version of VS Code or VS Code Insiders.
> code -v
1.65.2
c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1
x64
- Check your installed extensions to get the version of the VS Code Go extension
v0.32.0
- Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) >
Go: Locate Configured Go Toolscommand.
Checking configured tools....
GOBIN: undefined
toolsGopath:
gopath: /home/mattwelke/go
GOROOT: /usr/local/go
PATH: /home/mattwelke/.pyenv/plugins/pyenv-virtualenv/shims:/home/mattwelke/.pyenv/shims:/home/mattwelke/.pyenv/bin:/home/mattwelke/.pyenv/plugins/pyenv-virtualenv/shims:/home/mattwelke/.pyenv/shims:/home/mattwelke/.pyenv/bin:/home/mattwelke/.rvm/gems/ruby-3.1.1/bin:/home/mattwelke/.rvm/gems/ruby-3.1.1@global/bin:/home/mattwelke/.rvm/rubies/ruby-3.1.1/bin:/home/mattwelke/.sdkman/candidates/maven/current/bin:/home/mattwelke/.sdkman/candidates/java/current/bin:/home/mattwelke/.sdkman/candidates/gradle/current/bin:/home/mattwelke/.local/bin:/home/mattwelke/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/mattwelke/.rvm/bin:/home/mattwelke/n/bin:/home/mattwelke/.rvm/bin:/usr/local/go/bin
go: /usr/local/go/bin/go: go version go1.18 linux/amd64
go-outline: /home/mattwelke/go/bin/go-outline (version: v0.0.0-20210608161538-9736a4bde949 built with go: go1.18)
gotests: /home/mattwelke/go/bin/gotests (version: v1.6.0 built with go: go1.18)
gomodifytags: /home/mattwelke/go/bin/gomodifytags (version: v1.16.0 built with go: go1.18)
impl: /home/mattwelke/go/bin/impl (version: v1.1.0 built with go: go1.18)
goplay: /home/mattwelke/go/bin/goplay (version: v1.0.0 built with go: go1.18)
dlv: /home/mattwelke/go/bin/dlv (version: v1.8.2 built with go: go1.18)
staticcheck: /home/mattwelke/go/bin/staticcheck (version: v0.2.2 built with go: go1.18)
gopls: /home/mattwelke/go/bin/gopls (version: v0.8.3 built with go: go1.18)
go env
Workspace Folder (go): /home/mattwelke/java-test/go
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mattwelke/.cache/go-build"
GOENV="/home/mattwelke/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mattwelke/go/pkg/mod"
GONOPROXY="github.com/groupby/*"
GONOSUMDB="github.com/groupby/*"
GOOS="linux"
GOPATH="/home/mattwelke/go"
GOPRIVATE="github.com/groupby/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/mattwelke/java-test/go/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2598810975=/tmp/go-build -gno-record-gcc-switches"
Share the Go related settings you have added/edited
Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.
n/a
Describe the bug
When I have defined a struct, or if I'm referencing a struct defined in a library, I expect that if I type the name of the struct, then the opening and closing curly brace, position my cursor in between the two curly braces, and then type ctrl-., I get an option called "Fill
Example:
type someStruct struct {
prop1 string
prop2 string
}
someStruct := someStruct{}
Type ctrl-.:

If I choose that, I get:
someStruct := someStruct{
prop1: "",
prop2: "",
}
But with a struct that uses generics, I don't get that code action.
Example:
type optional[T any] struct {
present bool
value T
}
optionalNumber1 := optional[int]{}
Type ctrl-.:

Expected behavior is that I get this same code action, and if I select it, it fills in the field names and default values. Because I've specified the type I intend to use (int in this case), it would know which default values to choose to fill in. It would fill in the field value with 0 in this case.
Steps to reproduce the behavior:
- Create a Go project using the latest version of VS Code, the VS Code Go extension, and gopls.
- Create the code I posted above.
- Try to use the "fill struct" feature with a generic struct, as I described above.
Screenshots or recordings
n/a
More info about system:
> lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: Fedora
Description: Fedora release 35 (Thirty Five)
Release: 35
Codename: ThirtyFive
Just realized I wasn't running the latest version of VS Code when I reported this. I just updated, and it's still behaving this way with the latest version:
Version: 1.66.2
Commit: dfd34e8260c270da74b5c2d86d61aee4b6d56977
Date: 2022-04-11T07:49:24.808Z
Electron: 17.2.0
Chromium: 98.0.4758.109
Node.js: 16.13.0
V8: 9.8.177.11-electron.0
OS: Linux x64 5.16.18-200.fc35.x86_64
Related to golang/go#52291.