-
Notifications
You must be signed in to change notification settings - Fork 5
/
api_base_test.go
47 lines (39 loc) · 1.08 KB
/
api_base_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package example
import (
"testing"
log "github.com/sirupsen/logrus"
"github.com/williamfzc/srctx/parser"
)
func TestBase(t *testing.T) {
yourLsif := "../parser/lsif/testdata/dump.lsif.zip"
sourceContext, err := parser.FromLsifFile(yourLsif, "..")
if err != nil {
panic(err)
}
// all files?
files := sourceContext.Files()
log.Infof("files in lsif: %d", len(files))
// search definition in a specific file
defs, err := sourceContext.DefsByFileName(files[0])
if err != nil {
panic(err)
}
log.Infof("there are %d def happend in %s", len(defs), files[0])
for _, eachDef := range defs {
log.Infof("happened in %d:%d", eachDef.LineNumber(), eachDef.Range.Character)
}
// or specific line?
_, _ = sourceContext.DefsByLine(files[0], 1)
// get all the references of a definition
refs, err := sourceContext.RefsFromDefId(defs[0].Id())
if err != nil {
panic(err)
}
log.Infof("there are %d refs", len(refs))
for _, eachRef := range refs {
log.Infof("happened in file %s %d:%d",
sourceContext.FileName(eachRef.FileId),
eachRef.LineNumber(),
eachRef.Range.Character)
}
}