tools icon indicating copy to clipboard operation
tools copied to clipboard

x/tools/gopls semantically tokenize export comments

Open JoeyShapiro opened this issue 2 months ago • 3 comments

I would like to colorize the export comments in golang a different color. I have this PR, and it kinda works, as shown below.

main_test.go //go:build cgo

package main

//export main func main() {

}

Before $ ~/go/bin/gopls semtok main_test.go /⇒2,comment,[]/// /⇒8,namespace,[]/go:build /⇒3,comment,[]/cgo

/⇒7,keyword,[]/package /⇒4,namespace,[]/main

/⇒13,comment,[]///export main /⇒4,keyword,[]/func /⇒4,function,[definition]/main() {

}

After $ go run . -- semtok main_test.go
/⇒2,comment,[]/// /⇒8,namespace,[]/go:build /⇒3,comment,[]/cgo

/⇒7,keyword,[]/package /⇒4,namespace,[]/main

/⇒2,comment,[]/// /⇒7,namespace,[]/export /⇒4,function,[]/main /⇒4,keyword,[]/func /⇒4,function,[definition]/main() {

}

I copied what go directives do, but it still needs some work. I want to write some tests and find a way to only colorize it when the export is directly above a function header.

Before I get any farther, could I get confirmation that a PR like this would be accepted. Or is there a reason this has not been added in.

JoeyShapiro avatar Nov 19 '25 03:11 JoeyShapiro