vscode-go icon indicating copy to clipboard operation
vscode-go copied to clipboard

Appends auto-complete result when swapping slice positions

Open hpurmann opened this issue 3 years ago • 0 comments

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.18.3 darwin/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
golang.org/x/tools/gopls v0.9.0
   golang.org/x/tools/[email protected] h1:nEKQdO89Fkt4QTCN1xXkZzYHWZoBvIhkjJMpUaqRKUU=
   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:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
   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:WJDuUhyXESxK3m93WfO682qKcbEn25aXgEjs0xqWMOs=
   golang.org/x/[email protected] h1:r5bbIROBQtRRgoutV8Q3sFY58VzHW6jMBYl48ANSyS4=
   honnef.co/go/[email protected] h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34=
   mvdan.cc/[email protected] h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
   mvdan.cc/xurls/[email protected] h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.18.3
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.69.0 92d25e35d9bf1a6b16f7d0758f25d48ace11e5b9 x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.34.1
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /Users/hpurmann/dev/go
GOROOT: /usr/local/go
PATH: /usr/local/go/bin:/usr/local/opt/node@16/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/hpurmann/dev/go/bin:/Users/hpurmann/.cargo/bin:/Users/hpurmann/Library/Python/3.7/bin:/Users/hpurmann/.yarn/bin:/Users/hpurmann/dotfiles/scripts:/Users/hpurmann/.fzf/bin
PATH (vscode launched with): /usr/local/opt/node@16/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/hpurmann/dev/go/bin:/usr/local/go/bin:/Users/hpurmann/.cargo/bin:/Users/hpurmann/Library/Python/3.7/bin:/Users/hpurmann/.yarn/bin:/Users/hpurmann/dotfiles/scripts:/Users/hpurmann/.fzf/bin

	go:	/usr/local/go/bin/go: go version go1.18.3 darwin/amd64

	gotests:	/Users/hpurmann/dev/go/bin/gotests	(version: v1.6.0 built with go: go1.18.3)
	gomodifytags:	/Users/hpurmann/dev/go/bin/gomodifytags	(version: v1.16.0 built with go: go1.18.3)
	impl:	/Users/hpurmann/dev/go/bin/impl	(version: v1.1.0 built with go: go1.18.3)
	goplay:	/Users/hpurmann/dev/go/bin/goplay	(version: v1.0.0 built with go: go1.18.3)
	dlv:	/Users/hpurmann/dev/go/bin/dlv	(version: v1.8.3 built with go: go1.18.3)
	staticcheck:	/Users/hpurmann/dev/go/bin/staticcheck	(version: v0.3.2 built with go: go1.18.3)
	gopls:	/Users/hpurmann/dev/go/bin/gopls	(version: v0.9.0 built with go: go1.18.3)

go env
Workspace Folder (vscode-go-reproduce-3103): /Users/hpurmann/dev/go/src/vscode-go-reproduce-3103
	GO111MODULE="on"
	GOARCH="amd64"
	GOBIN=""
	GOCACHE="/Users/hpurmann/Library/Caches/go-build"
	GOENV="/Users/hpurmann/Library/Application Support/go/env"
	GOEXE=""
	GOEXPERIMENT=""
	GOFLAGS=""
	GOHOSTARCH="amd64"
	GOHOSTOS="darwin"
	GOINSECURE=""
	GOMODCACHE="/Users/hpurmann/dev/go/pkg/mod"
	GONOPROXY=""
	GONOSUMDB=""
	GOOS="darwin"
	GOPATH="/Users/hpurmann/dev/go"
	GOPRIVATE=""
	GOPROXY="https://proxy.golang.org,direct"
	GOROOT="/usr/local/go"
	GOSUMDB="sum.golang.org"
	GOTMPDIR=""
	GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
	GOVCS=""
	GOVERSION="go1.18.3"
	GCCGO="gccgo"
	GOAMD64="v1"
	AR="ar"
	CC="clang"
	CXX="clang++"
	CGO_ENABLED="1"
	GOMOD="/dev/null"
	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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1x/57r6d8h13ns8dn05_0fn12zw0000gn/T/go-build65730962=/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.autocompleteUnimportedPackages": true,
  "go.formatTool": "goimports",
  "go.useLanguageServer": true,
  "go.toolsManagement.autoUpdate": true,

Describe the bug

I found this archived issue. I think I have a good reproducing case, documented in this repo

When auto-completing a value, the plugin will append the result instead of replacing it. I tested a few different cases and it only seems to happen when assigning multiple variables, e.g. when doing a swap of values in a slice.

Steps to reproduce the behavior:

  1. Write this code
     s := []string{"First", "Second"}
    
     oldPosition := 0
     newPosition := 1
    
     // swap values
     s[oldPosition], s[newP]
    
    
  2. Auto-complete newP to newPosition
  3. The line will read s[oldPosition], s[newPnewPosition]

Screenshots or recordings

Screen Shot 2022-07-11 at 00 57 31

hpurmann avatar Jul 10 '22 23:07 hpurmann