Originally from @bruce-quickplay in microsoft/vscode#191339
Type: Bug
I have found what I believe to be an issue with Go language syntax highlighting. Constants that are declared with an explicit type have the wrong colour for the identifier and type tokens:
This screenshot shows the issue while running the Dark+ theme. I included a variety of different uses of variables and constants to demonstrate the respective syntax highlighting.
Comparing constant to variable declarations shows the issue:
- Constant/variable declarations and assignments should have a light blue identifier
- Constant declarations that include a type have a white identifier
- Constant/variable references should have a white identifier
- Types should be green
- Constant declarations that include a type have a light blue identifier
The problem appears to be, when constant declarations include a type, the type is incorrectly interpreted as the identifier. I believe this may have slipped through because when declaring constants in Go,
I find this most obvious with the Dark+ theme, but the issue exists with all themes I checked.
I disabled all extensions and found the issue persists.
The issue goes away when enabling Semantic Highlighting in the settings, as recommended in the Go in Visual Studio Code doc (this requires the official Go Language Extension). The issue is fixed for all themes except the standard Dark and Light themes.
Here is the sample code in case anyone wants to copy into their own IDE:
package test
import "fmt"
type customType string
const testConst string = "test"
const testConst2 = "test"
const testConst3 customType = "test"
var testVar string = "test"
var testVar2 = "test"
var testVar3 customType = "test"
var testVar4 string
func testFunc(arg string) string {
const localTestConst string = "test"
const localTestConst2 = "test"
var localTestVar string = arg
testVar2 = arg
fmt.Println(localTestVar)
fmt.Println(testConst)
return localTestVar
}
VS Code version: Code 1.80.2 (Universal) (2ccd690cbff1569e4a83d7c43d45101f817401dc, 2023-07-27T21:05:41.366Z)
OS version: Darwin arm64 22.2.0
Modes:
System Info
Item |
Value |
CPUs |
Apple M1 Pro (10 x 24) |
GPU Status |
2d_canvas: enabled canvas_oop_rasterization: disabled_off direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled metal: disabled_off multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok video_decode: enabled video_encode: enabled vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: enabled |
Load (avg) |
5, 4, 4 |
Memory (System) |
16.00GB (0.07GB free) |
Process Argv |
--crash-reporter-id 70ee87b8-bad3-40fb-a659-1cd8cc3a4260 |
Screen Reader |
no |
VM |
0% |
Extensions: none
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30410667
py29gd2263:30792226
vscaat:30438848
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
vsccc:30803844
282f8724:30602487
89544117:30613380
showlangstatbar:30737416
03d35959:30757346
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
gsofb:30804716
pythonnosmt12:30797651
pythonidxpt:30805730
pythonnoceb:30805159
dsvsc013:30795093
dsvsc014:30804076
diffeditorv1:30821571