Tab completing an identifier when the cursor is right before an identifier overwrites the following identifier
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.21.0 linux/amd64
- Run
gopls -v versionto get version of Gopls from the VS Code integrated terminal.golang.org/x/tools/gopls v0.13.1
- Run
code -vorcode-insiders -vto get version of VS Code or VS Code Insiders.1.81.06445d93c81ebe42c4cbd7a60712e0b17d9463e97x64
- Check your installed extensions to get the version of the VS Code Go extension
v0.39.1
- Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) >
Go: Locate Configured Go Toolscommand.
Checking configured tools....
GOBIN: undefined
toolsGopath:
gopath: C:\Users\bigyi\go
GOROOT: C:\Program Files\Go
PATH: C:\Program Files\Go\bin;D:\Program Files\ImageMagick-7.1.1-Q16-HDRI;C:\Program Files\Zulu\zulu-17\bin\;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\CMake\bin;C:\Program Files (x86)\GnuWin32\bin;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;D:\Program Files;D:\Program Files (x86);C:\Program Files;C:\Program Files (x86);C:\Users\bigyi\AppData\Local\Programs\Python\Python310\Scripts\;C:\Users\bigyi\AppData\Local\Programs\Python\Python310\;C:\Users\bigyi\.cargo\bin;C:\Users\bigyi\AppData\Local\Microsoft\WindowsApps;C:\Users\bigyi\.dotnet\tools;C:\Users\bigyi\AppData\Roaming\npm;C:\Users\bigyi\go\bin
PATH (vscode launched with): D:\Program Files\ImageMagick-7.1.1-Q16-HDRI;C:\Program Files\Zulu\zulu-17\bin\;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\CMake\bin;C:\Program Files (x86)\GnuWin32\bin;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;D:\Program Files;D:\Program Files (x86);C:\Program Files;C:\Program Files (x86);C:\Program Files\Go\bin;C:\Users\bigyi\AppData\Local\Programs\Python\Python310\Scripts\;C:\Users\bigyi\AppData\Local\Programs\Python\Python310\;C:\Users\bigyi\.cargo\bin;C:\Users\bigyi\AppData\Local\Microsoft\WindowsApps;C:\Users\bigyi\.dotnet\tools;C:\Users\bigyi\AppData\Roaming\npm;C:\Users\bigyi\go\bin
go: C:\Program Files\Go\bin\go.exe: go version go1.21.0 windows/amd64
gotests: C:\Users\bigyi\go\bin\gotests.exe (version: v1.6.0 built with go: go1.21.0)
gomodifytags: C:\Users\bigyi\go\bin\gomodifytags.exe (version: v1.16.0 built with go: go1.21.0)
impl: C:\Users\bigyi\go\bin\impl.exe (version: v1.1.0 built with go: go1.21.0)
goplay: C:\Users\bigyi\go\bin\goplay.exe (version: v1.0.0 built with go: go1.21.0)
dlv: C:\Users\bigyi\go\bin\dlv.exe (version: v1.21.0 built with go: go1.21.0)
staticcheck: C:\Users\bigyi\go\bin\staticcheck.exe (version: v0.4.3 built with go: go1.21.0)
gopls: C:\Users\bigyi\go\bin\gopls.exe (version: v0.13.1 built with go: go1.21.0)
go env
Workspace Folder (phono-word-gen): d:\Programming\GithubRepos\phono-word-gen
set GO111MODULE=
set GOARCH=wasm
set GOBIN=
set GOCACHE=C:\Users\bigyi\AppData\Local\go-build
set GOENV=C:\Users\bigyi\AppData\Roaming\go\env
set GOEXE=
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\bigyi\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=js
set GOPATH=C:\Users\bigyi\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21.0
set GCCGO=gccgo
set GOWASM=
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=d:\Programming\GithubRepos\phono-word-gen\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-fPIC -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\bigyi\AppData\Local\Temp\go-build1278179464=/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.
// workspace .vscode/settings.json
{
"go.toolsEnvVars": {
"GOARCH": "wasm",
"GOOS": "js"
}
}
// user settings.json
{
"gopls": {
// "experimentalWorkspaceModule": true,
"ui.semanticTokens": true
},
"go.enableCodeLens": {},
"go.toolsManagement.autoUpdate": true,
"go.inlayHints.constantValues": true,
"go.inlayHints.functionTypeParameters": true,
"go.inlayHints.rangeVariableTypes": true,
"go.inlayHints.assignVariableTypes": true,
}
Describe the bug
When pressing tab to autocomplete an identifier, if the cursor is right before another identifier, the completed identifier overwrites the one after it.
- Expected: The autocompleted identifier to be placed right before the identifier following it.
- Actual: The autocompleted identifier overwrites the identifier after it.
This is inconsistent when it comes to autocompleting methods:
- typing
namethen completing the method call, it overwrites the next identifier. - typing
name.then completing the method call, it does not overwrite the next identifier.
Steps to reproduce the behavior:
- Write an identifier for the autocomplete to use.
- Write a different identifier.
- Put the cursor before that different identifier.
- Type so that the autocompleter suggests the identifier in step 1.
- Press tab (or the autocomplete trigger button)
- The identifier from step 1 overwrites the identifier after it.
Screenshots or recordings
https://github.com/golang/vscode-go/assets/12767476/643379f8-7f5a-4218-872d-690b0e726f09
Hi, sorry for the slow response on this issue.
We discussed this in our triage meeting, and the problem is tricky to get right. In some contexts (e.g. a binary expression) I think more often than not one does want to overwrite the identifier, as otherwise the code won't be valid syntax. In a function call, one sometimes wants the identifier to be overwritten, sometimes not, depending on context.
In all likelihood, this is too tricky for us to tackle any time soon.
@findleyr is this still getting worked on? It is a massive pain to work with when having to ensure you don't accidentally hit tab for autocomplete.
@bigyihsuan, @DanielBJanes,
I agree, this is a pain. As a workaround, I am hitting the spacebar first, followed by moving the cursor to the left, so there is a space between the identifiers. This way, it will not be removed. It takes some time to retrain the muscle memory, but it works okay.