| 1 |
This test checks the semantic tokens in comments (golang/go#64648). |
| 2 |
|
| 3 |
There will be doc links in the comments to reference other objects. Parse these |
| 4 |
links and output tokens according to the referenced object types, so that the |
| 5 |
editor can highlight them. This will help in checking the doc link errors and |
| 6 |
reading comments in the code. |
| 7 |
|
| 8 |
-- settings.json -- |
| 9 |
{ |
| 10 |
"semanticTokens": true |
| 11 |
} |
| 12 |
|
| 13 |
-- a.go -- |
| 14 |
package p |
| 15 |
|
| 16 |
import "strconv" |
| 17 |
|
| 18 |
const A = 1 |
| 19 |
var B = 2 |
| 20 |
|
| 21 |
type Foo int |
| 22 |
|
| 23 |
|
| 24 |
// [F] accept a [Foo], and print it. //@token("F", "function", "signature"),token("Foo", "type", "number") |
| 25 |
func F(v Foo) { |
| 26 |
println(v) |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
/* |
| 31 |
[F1] print [A] and [B] //@token("F1", "function", "signature"),token("A", "variable", "readonly number"),token("B", "variable", "static number") |
| 32 |
*/ |
| 33 |
func F1() { |
| 34 |
// print [A] and [B]. //@token("A", "variable", "readonly number"),token("B", "variable", "static number") |
| 35 |
println(A, B) |
| 36 |
} |
| 37 |
|
| 38 |
// [F2] use [strconv.Atoi] convert s, then print it //@token("F2", "function", "signature"),token("strconv", "namespace", ""),token("Atoi", "function", "signature") |
| 39 |
func F2(s string) { |
| 40 |
a, _ := strconv.Atoi("42") |
| 41 |
b, _ := strconv.Atoi("42") |
| 42 |
println(a, b) // this is a tail comment in F2 //hover(F2, "F2", F2) |
| 43 |
} |
| 44 |
-- b.go -- |
| 45 |
package p |
| 46 |
|
| 47 |
// [F3] accept [*Foo] //@token("F3", "function", "signature"),token("Foo", "type", "number") |
| 48 |
func F3(v *Foo) { |
| 49 |
println(*v) |
| 50 |
} |
| 51 |
|
| 52 |
// [F4] equal [strconv.Atoi] //@token("F4", "function", "signature"),token("strconv", "namespace", ""),token("Atoi", "function", "signature") |
| 53 |
func F4(s string) (int, error) { |
| 54 |
return 0, nil |
| 55 |
} |