Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
anirudhgiri opened this issue Feb 5, 2024 · 6 comments
Labels
upstream-vscode Issues that are by problems in VS Code itself.

Comments

@anirudhgiri
Copy link

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)

@gopherbot gopherbot added this to the Untriaged milestone Feb 5, 2024
@findleyr
Copy link
Member

findleyr commented Feb 8, 2024

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?

@hyangah
Copy link
Contributor

hyangah commented Feb 13, 2024

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

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

@hyangah hyangah added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 13, 2024
@anirudhgiri
Copy link
Author

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

@findleyr findleyr removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 15, 2024
@findleyr
Copy link
Member

findleyr commented Feb 15, 2024

@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 findleyr changed the title Syntax highlighting and Intellisense break when a string with "]" is cast to []byte Syntax highlighting and Intellisense broken in VS Code 1.86+ when a string with "]" is cast to []byte Feb 15, 2024
@findleyr
Copy link
Member

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

@findleyr findleyr added the upstream-vscode Issues that are by problems in VS Code itself. label Feb 15, 2024
@drgrib
Copy link

drgrib commented Feb 25, 2024

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+)(.*)`)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream-vscode Issues that are by problems in VS Code itself.
Projects
None yet
Development

No branches or pull requests

5 participants