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.17 darwin/amd64 * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_.
Build info
----------
golang.org/x/tools/gopls v0.7.2
    golang.org/x/tools/gopls@v0.7.2 h1:kRKKdvA8GOzra8rhSFDClOR7hV/x8v0J0Vm4C/gWq8s=
    github.com/BurntSushi/toml@v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
    github.com/google/go-cmp@v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/sys@v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
    golang.org/x/tools@v0.1.6-0.20210908190839-cf92b39a962c h1:C0nyHiBU2m0cR6hDiUORWqQIt3h37wsp1255QBSSXqY=
    golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    honnef.co/go/tools@v0.2.0 h1:ws8AfbgTX3oIczLPNPCu5166oBg9ST2vNs0rcht+mDE=
    mvdan.cc/gofumpt@v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=
    mvdan.cc/xurls/v2@v2.3.0 h1:59Olnbt67UKpxF1EwVBopJvkSUBmgtb468E4GVWIZ1I=
* Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders.
1.61.0
ee8c7def80afc00dd6e593ef12f37756d8f504ea
x64
* Check your installed extensions to get the version of the VS Code Go extension - v0.28.1 * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command.
go env
Workspace Folder (code): /Users/abhi1589/go/src/code
    GO111MODULE=""
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/Users/abhi1589/Library/Caches/go-build"
    GOENV="/Users/abhi1589/Library/Application Support/go/env"
    GOEXE=""
    GOEXPERIMENT=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOINSECURE=""
    GOMODCACHE="/Users/abhi1589/go/pkg/mod"
    GONOPROXY="github.rackspace.com"
    GONOSUMDB="github.rackspace.com"
    GOOS="darwin"
    GOPATH="/Users/abhi1589/go"
    GOPRIVATE="github.rackspace.com"
    GOPROXY="https://proxy.golang.org,direct"
    GOROOT="/usr/local/Cellar/go/1.17/libexec"
    GOSUMDB="sum.golang.org"
    GOTMPDIR=""
    GOTOOLDIR="/usr/local/Cellar/go/1.17/libexec/pkg/tool/darwin_amd64"
    GOVCS=""
    GOVERSION="go1.17"
    GCCGO="gccgo"
    AR="ar"
    CC="clang"
    CXX="clang++"
    CGO_ENABLED="1"
    GOMOD="/Users/abhi1589/go/src/code/go.mod"
    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/wy/s6djdr5x6zx6vw7h5g3r8k6m0000gp/T/go-build3142353325=/tmp/go-build -gno-record-gcc-switches -fno-common"

Describe the bug

Auto variable auto-complete is not working as expected

Expected: cMap
Got: cmcMap

Code Used.

package main

func main() {
    test("abcabcbb")
}

func test(s string) int {
    b := []byte(s)
    var last int
    var cMap map[int]int
    for _, v : = range b {
        cmcMap // <------------------- This is where problem is
    return 0
}

Steps to reproduce the behavior:

  1. Copy the above code
  2. Try to update the line with <------------------- This is where the problem is comment

Screenshots or recordings

https://user-images.githubusercontent.com/265913/136856080-cb219335-832b-4365-a6ec-26fe1f836fbe.mp4

Comment From: stamblerre

Thanks for the repro case! I don't know if it's likely that we'll address this soon since there are multiple issues going on here, but we can certainly look into it at some point.

Comment From: muirdm

In case you missed it, the issue is the := has a space in it.

The AST ends up looking like:

for <BadExpr> {
  <BadStmt>

Maybe gopls (or someday go/parser) could become robust to the BadExpr and parse the loop body normally.

Comment From: abhimanyu003

Thanks @muirdm I guess we can close this one for now then.