1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:54:42 -07:00
go/internal/lsp/testdata/highlights/highlights.go
Rohan Challa 66c5a5ad76 internal/lsp: add control flow highlighting inside for loops
When the cursor is on a "for" statement or on any branch statement inside
the for loop. It will highlight the control flow inside the for loop.

Updates #34496

Change-Id: Idef14e3c89bc161d305d4a49fd784095a93bbc03
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208337
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-21 21:43:27 +00:00

71 lines
2.4 KiB
Go

package highlights
import (
"fmt"
"golang.org/x/tools/internal/lsp/protocol"
)
type F struct{ bar int }
var foo = F{bar: 52} //@mark(fooDeclaration, "foo"),highlight(fooDeclaration, fooDeclaration, fooUse)
func Print() { //@mark(printFunc, "Print"),highlight(printFunc, printFunc, printTest)
fmt.Println(foo) //@mark(fooUse, "foo"),highlight(fooUse, fooDeclaration, fooUse)
fmt.Print("yo") //@mark(printSep, "Print"),highlight(printSep, printSep, print1, print2)
}
func (x *F) Inc() { //@mark(xDeclaration, "x"),highlight(xDeclaration, xDeclaration, xUse)
x.bar++ //@mark(xUse, "x"),highlight(xUse, xDeclaration, xUse)
}
func testFunctions() {
fmt.Print("main start") //@mark(print1, "Print"),highlight(print1, printSep, print1, print2)
fmt.Print("ok") //@mark(print2, "Print"),highlight(print2, printSep, print1, print2)
Print() //@mark(printTest, "Print"),highlight(printTest, printFunc, printTest)
}
func toProtocolHighlight(rngs []protocol.Range) []protocol.DocumentHighlight { //@mark(doc1, "DocumentHighlight"),highlight(doc1, doc1, doc2, doc3)
result := make([]protocol.DocumentHighlight, 0, len(rngs)) //@mark(doc2, "DocumentHighlight"),highlight(doc2, doc1, doc2, doc3)
kind := protocol.Text
for _, rng := range rngs {
result = append(result, protocol.DocumentHighlight{ //@mark(doc3, "DocumentHighlight"),highlight(doc3, doc1, doc2, doc3)
Kind: kind,
Range: rng,
})
}
return result
}
func testForLoops() {
for i := 0; i < 10; i++ { //@mark(forDecl1, "for"),highlight(forDecl1, forDecl1, brk1, cont1)
if i > 8 {
break //@mark(brk1, "break"),highlight(brk1, forDecl1, brk1, cont1)
}
if i < 2 {
for j := 1; j < 10; j++ { //@mark(forDecl2, "for"),highlight(forDecl2, forDecl2, cont2)
if j < 3 {
for k := 1; k < 10; k++ { //@mark(forDecl3, "for"),highlight(forDecl3, forDecl3, cont3)
if k < 3 {
continue //@mark(cont3, "continue"),highlight(cont3, forDecl3, cont3)
}
}
continue //@mark(cont2, "continue"),highlight(cont2, forDecl2, cont2)
}
}
continue //@mark(cont1, "continue"),highlight(cont1, forDecl1, brk1, cont1)
}
}
arr := []int{}
for i := range arr { //@mark(forDecl4, "for"),highlight(forDecl4, forDecl4, brk4, cont4)
if i > 8 {
break //@mark(brk4, "break"),highlight(brk4, forDecl4, brk4, cont4)
}
if i < 4 {
continue //@mark(cont4, "continue"),highlight(cont4, forDecl4, brk4, cont4)
}
}
}