vscode-go
vscode-go copied to clipboard
Suggested code action for "should replace loop with..." ends up suggesting something for a different line of code
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.23.1 darwin/arm64
- Run
gopls -v versionto get version of Gopls from the VS Code integrated terminal.
Build info
----------
golang.org/x/tools/gopls v0.16.2
golang.org/x/tools/[email protected] h1:K1z03MlikHfaMTtG01cUeL5FAOTJnITuNe0TWOcg8tM=
github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
golang.org/x/[email protected] h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/[email protected] h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/[email protected] h1:Wm3cG5X6sZ0RSVRc/H1/sciC4AT6HAKgLCSH2lbpR/c=
golang.org/x/[email protected] h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/[email protected] h1:6bJEg2w2kUHWlfdJaESYsmNfI1LKAZQi6zCa7LUn7eI=
golang.org/x/[email protected] h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
honnef.co/go/[email protected] h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
mvdan.cc/[email protected] h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.23.1
- Run
code -vorcode-insiders -vto get version of VS Code or VS Code Insiders.
1.94.1
e10f2369d0d9614a452462f2e01cdc4aa9486296
arm64
- Check your installed extensions to get the version of the VS Code Go extension
- v0.42.1
- Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) >
Go: Locate Configured Go Toolscommand.
# Tools Configuration
## Environment
GOBIN: undefined
toolsGopath:
gopath: /Users/rcjsuen/go
GOROOT: /opt/homebrew/Cellar/go/1.23.1/libexec
PATH: /Users/rcjsuen/.nvm/versions/node/v20.16.0/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/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:/usr/local/go/bin:/Applications/iTerm.app/Contents/Resources/utilities:/Applications/Visual Studio Code.app/Contents/Resources/app/bin:/Users/rcjsuen/go/bin
## Tools
go: /opt/homebrew/bin/go: go version go1.23.1 darwin/arm64
gopls: /Users/rcjsuen/go/bin/gopls (version: v0.16.2 built with go: go1.23.1)
gotests: not installed
gomodifytags: not installed
impl: not installed
goplay: not installed
dlv: /Users/rcjsuen/go/bin/dlv (version: v1.23.0 built with go: go1.23.0)
staticcheck: /Users/rcjsuen/go/bin/staticcheck (version: v0.5.1 built with go: go1.23.0)
## Go env
Workspace Folder (docker-language-server): /Users/rcjsuen/code/docker/docker-language-server
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/rcjsuen/Library/Caches/go-build'
GOENV='/Users/rcjsuen/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/rcjsuen/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/rcjsuen/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.23.1/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.23.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/rcjsuen/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/rcjsuen/code/docker/docker-language-server/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/ln/c6gntgwx7m5gwlhx2dkc73w40000gp/T/go-build1934959577=/tmp/go-build -gno-record-gcc-switches -fno-common'
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.
"go.toolsManagement.autoUpdate": true
Describe the bug
I have a "should replace loop" yellow warning squiggly line. Clicking on it suggests code action though clicking on it seems to suggest something totally different in something a few lines above. Code actions should be contextual to the line the text cursor is at and not something in another part of the file.
Steps to reproduce the behavior:
- Use this file.
- Click on yellow squiggly area on line 16.
- Click light bulb.
- Confused about the "Split parameters into separate lines" suggestion but click on it anyway.
- Code is modified but does not resolve the yellow warning that the text cursor was on. 🤔
package hcl
import (
"testing"
)
func TestX(t *testing.T) {
testCases := []struct {
name string
}{}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
symbols, _ := returnTwoThings()
var result []interface{}
for _, symbol := range symbols {
result = append(result, symbol)
}
})
}
}
func returnTwoThings() ([]interface{}, error) {
return nil, nil
}
Screenshots or recordings
https://github.com/user-attachments/assets/1d558b43-8697-47f4-a15e-d76025562491