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

Syntax highlighting and Intellisense broken in VS Code 1.86+ when a string with "]" is cast to []byte

Open anirudhgiri opened this issue 1 year ago • 6 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.21.6 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.

    • golang.org/x/tools/gopls v0.14.2
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.

    • 1.86.0
  • Check your installed extensions to get the version of the VS Code Go extension

    • v0.40.3
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

    • Checking configured tools.... GOBIN: undefined toolsGopath: gopath: /home/anirudh-g/go GOROOT: /snap/go/10489 PATH: /snap/go/10489/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin

    go: /snap/go/current/bin/go: go version go1.21.6 linux/amd64

    gopls: /home/anirudh-g/go/bin/gopls (version: v0.14.2 built with go: go1.21.4) gotests: not installed gomodifytags: not installed impl: not installed goplay: not installed dlv: /home/anirudh-g/go/bin/dlv (version: v1.21.0 built with go: go1.21.0) staticcheck: /home/anirudh-g/go/bin/staticcheck (version: v0.4.5 built with go: go1.21.0)

go env Workspace Folder (playground): /home/anirudh-g/Documents/programming/golang/playground GO111MODULE='' GOARCH='amd64' GOBIN='' GOCACHE='/home/anirudh-g/.cache/go-build' GOENV='/home/anirudh-g/.config/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='linux' GOINSECURE='' GOMODCACHE='/home/anirudh-g/go/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='linux' GOPATH='/home/anirudh-g/go' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/snap/go/10489' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/snap/go/10489/pkg/tool/linux_amd64' GOVCS='' GOVERSION='go1.21.6' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='gcc' CXX='g++' CGO_ENABLED='1' GOMOD='/home/anirudh-g/Documents/programming/golang/playground/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2453955022=/tmp/go-build -gno-record-gcc-switches'

Share the Go related settings you have added/edited

"go.toolsManagement.autoUpdate": true,
  "go.alternateTools": {
    "go": "/snap/go/current/bin/go"
},

Describe the bug

If a string that contains the ] character is converted to a []byte, both syntax highlighting and intellisense stop working from that line onwards. All subsequent lines of code have incorrect syntax highlighting, and intellisense does not work on those lines of code. This only happens on VSCode version 1.86.0

Steps to reproduce the behavior:

  1. Take a project with multiple lines of correctly syntax highlighted code
  2. Add the line var myByteArray []byte = []byte("]") somewhere in the middle
  3. From that line onward, syntax highlighting and Intellisense ceases to work

Screenshots or recordings

Syntax highlighting on VSCode version 1.86.0: image

Expected Syntax highlighting: image (2)

anirudhgiri avatar Feb 05 '24 08:02 anirudhgiri

I am not naively able to reproduce this. It would be very suprising if this code broke gopls' intellisense, since gopls is built on top of compiler tools which definitely handle these inputs.

Do you have any other extensions installed that may interact with Go code?

findleyr avatar Feb 08 '24 20:02 findleyr

@anirudhgiri Can you please try semantic token based syntax highlighting and if it works better for you?

"gopls": { "ui.semanticTokens": true }

hyangah avatar Feb 13 '24 14:02 hyangah

Apologies for the late response.

@findleyr I just reproduced it on a different machine running VSCode 1.86.1 with no other extensions installed except vscode-go (please refer to the screenshot below, note that line 6 is highlighted properly while line 8 is not). Are you sure you're using a version of VSCode that is 1.86.0 or above?

image

@hyangah Yes, adding the provided field to my settings.json seems to fix the issue

image

anirudhgiri avatar Feb 14 '24 17:02 anirudhgiri

@anirudhgiri indeed, I just installed VS Code 1.86.1 and reproduced, without even installing the Go extension.

This is a VS Code bug. I've filed it as microsoft/vscode#205306. VS Code 1.86 switched to a new Go syntax engine, apparently.

findleyr avatar Feb 15 '24 19:02 findleyr

I'm going to leave this open for visibility. For now, the workaround is to use "gopls": { "ui.semanticTokens": true }.

findleyr avatar Feb 15 '24 19:02 findleyr

I will add my very similar case to this issue and note that adding this to my user settings or project settings.json does not fix the issue:

	"gopls": {
		"ui.semanticTokens": true
	},

image

Steps to Reproduce

Add this line before any Go code:

var baseNameRE = regexp.MustCompile(`(\d+)(.*)`)

drgrib avatar Feb 25 '24 22:02 drgrib