| 1 |
This test checks textDocument/highlight with highlight kinds. |
| 2 |
For example, a use of a variable is reported as a "read", |
| 3 |
and an assignment to a variable is reported as a "write". |
| 4 |
(Note that the details don't align exactly with the Go |
| 5 |
type-checker notions of values versus addressable variables). |
| 6 |
|
| 7 |
|
| 8 |
-- highlight_kind.go -- |
| 9 |
package a |
| 10 |
|
| 11 |
type Nest struct { |
| 12 |
nest *Nest //@hiloc(fNest, "nest", text) |
| 13 |
} |
| 14 |
type MyMap map[string]string |
| 15 |
|
| 16 |
type NestMap map[Nest]Nest |
| 17 |
|
| 18 |
func _() { |
| 19 |
const constIdent = 1 //@hiloc(constIdent, "constIdent", write) |
| 20 |
//@highlightall(constIdent) |
| 21 |
var varNoInit int //@hiloc(varNoInit, "varNoInit", write) |
| 22 |
(varNoInit) = 1 //@hiloc(varNoInitAssign, "varNoInit", write) |
| 23 |
_ = varNoInit //@hiloc(varNoInitRead, "varNoInit", read) |
| 24 |
//@highlightall(varNoInit, varNoInitAssign, varNoInitRead) |
| 25 |
|
| 26 |
str, num := "hello", 2 //@hiloc(str, "str", write), hiloc(num, "num", write) |
| 27 |
_, _ = str, num //@hiloc(strRead, "str", read), hiloc(numRead, "num", read) |
| 28 |
//@highlightall(str, strRead, strMapKey, strMapVal, strMyMapKey, strMyMapVal, strMyMapSliceKey, strMyMapSliceVal, strMyMapPtrSliceKey, strMyMapPtrSliceVal) |
| 29 |
//@highlightall(num, numRead, numAddr, numIncr, numMul) |
| 30 |
nest := &Nest{nest: nil} //@hiloc(nest, "nest", write),hiloc(fNestComp, re`(nest):`, write) |
| 31 |
nest.nest = &Nest{} //@hiloc(nestSelX, "nest", read), hiloc(fNestSel, re`(nest) =`, write) |
| 32 |
*nest.nest = Nest{} //@hiloc(nestSelXStar, "nest", read), hiloc(fNestSelStar, re`(nest) =`, write) |
| 33 |
//@highlightall(nest, nestSelX, nestSelXStar, nestMapVal) |
| 34 |
//@highlightall(fNest, fNestComp, fNestSel, fNestSelStar, fNestSliceComp, fNestPtrSliceComp, fNestMapKey) |
| 35 |
|
| 36 |
pInt := &num //@hiloc(pInt, "pInt", write),hiloc(numAddr, "num", read) |
| 37 |
// StarExpr is reported as "write" in GoLand and Rust Analyzer |
| 38 |
*pInt = 3 //@hiloc(pIntStar, "pInt", write) |
| 39 |
var ppInt **int = &pInt //@hiloc(ppInt, "ppInt", write),hiloc(pIntAddr, re`&(pInt)`, read) |
| 40 |
**ppInt = 4 //@hiloc(ppIntStar, "ppInt", write) |
| 41 |
*(*ppInt) = 4 //@hiloc(ppIntParen, "ppInt", write) |
| 42 |
//@highlightall(pInt, pIntStar, pIntAddr) |
| 43 |
//@highlightall(ppInt, ppIntStar, ppIntParen) |
| 44 |
|
| 45 |
num++ //@hiloc(numIncr, "num", write) |
| 46 |
num *= 1 //@hiloc(numMul, "num", write) |
| 47 |
|
| 48 |
var ch chan int = make(chan int, 10) //@hiloc(ch, "ch", write) |
| 49 |
ch <- 3 //@hiloc(chSend, "ch", write) |
| 50 |
<-ch //@hiloc(chRecv, "ch", read) |
| 51 |
//@highlightall(ch, chSend, chRecv) |
| 52 |
|
| 53 |
var nums []int = []int{1, 2} //@hiloc(nums, "nums", write) |
| 54 |
// IndexExpr is reported as "read" in GoLand, Rust Analyzer and Java JDT |
| 55 |
nums[0] = 1 //@hiloc(numsIndex, "nums", read) |
| 56 |
//@highlightall(nums, numsIndex) |
| 57 |
|
| 58 |
mapLiteral := map[string]string{ //@hiloc(mapLiteral, "mapLiteral", write) |
| 59 |
str: str, //@hiloc(strMapKey, "str", read),hiloc(strMapVal, re`(str),`, read) |
| 60 |
} |
| 61 |
for key, value := range mapLiteral { //@hiloc(mapKey, "key", write), hiloc(mapVal, "value", write), hiloc(mapLiteralRange, "mapLiteral", read) |
| 62 |
_, _ = key, value //@hiloc(mapKeyRead, "key", read), hiloc(mapValRead, "value", read) |
| 63 |
} |
| 64 |
//@highlightall(mapLiteral, mapLiteralRange) |
| 65 |
//@highlightall(mapKey, mapKeyRead) |
| 66 |
//@highlightall(mapVal, mapValRead) |
| 67 |
|
| 68 |
nestSlice := []Nest{ |
| 69 |
{nest: nil}, //@hiloc(fNestSliceComp, "nest", write) |
| 70 |
} |
| 71 |
nestPtrSlice := []*Nest{ |
| 72 |
{nest: nil}, //@hiloc(fNestPtrSliceComp, "nest", write) |
| 73 |
} |
| 74 |
myMap := MyMap{ |
| 75 |
str: str, //@hiloc(strMyMapKey, "str", read),hiloc(strMyMapVal, re`(str),`, read) |
| 76 |
} |
| 77 |
myMapSlice := []MyMap{ |
| 78 |
{str: str}, //@hiloc(strMyMapSliceKey, "str", read),hiloc(strMyMapSliceVal, re`: (str)`, read) |
| 79 |
} |
| 80 |
myMapPtrSlice := []*MyMap{ |
| 81 |
{str: str}, //@hiloc(strMyMapPtrSliceKey, "str", read),hiloc(strMyMapPtrSliceVal, re`: (str)`, read) |
| 82 |
} |
| 83 |
nestMap := NestMap{ |
| 84 |
Nest{nest: nil}: *nest, //@hiloc(fNestMapKey, "nest", write), hiloc(nestMapVal, re`(nest),`, read) |
| 85 |
} |
| 86 |
|
| 87 |
_, _, _, _, _, _ = myMap, nestSlice, nestPtrSlice, myMapSlice, myMapPtrSlice, nestMap |
| 88 |
} |