本文整理汇总了Golang中sourcegraph/com/sourcegraph/srclib/graph.Output.Defs方法的典型用法代码示例。如果您正苦于以下问题:Golang Output.Defs方法的具体用法?Golang Output.Defs怎么用?Golang Output.Defs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sourcegraph/com/sourcegraph/srclib/graph.Output
的用法示例。
在下文中一共展示了Output.Defs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makeGraphData
func makeGraphData(t testing.TB, n int) graph.Output {
data := graph.Output{}
if n > 0 {
data.Defs = make([]*graph.Def, n)
data.Refs = make([]*graph.Ref, n)
}
for i := 0; i < n; i++ {
data.Defs[i] = &graph.Def{
DefKey: graph.DefKey{Path: fmt.Sprintf("def-path-%d", i)},
Name: fmt.Sprintf("def-name-%d", i),
Kind: "mykind",
DefStart: uint32((i % 53) * 37),
DefEnd: uint32((i%53)*37 + (i % 20)),
File: fmt.Sprintf("dir%d/subdir%d/subsubdir%d/file-%d.foo", i%5, i%3, i%7, i%5),
Exported: i%5 == 0,
Local: i%3 == 0,
Data: []byte(`"` + strings.Repeat("abcd", 50) + `"`),
}
data.Refs[i] = &graph.Ref{
DefPath: fmt.Sprintf("ref-path-%d", i),
Def: i%5 == 0,
Start: uint32((i % 51) * 39),
End: uint32((i%51)*37 + (int(i) % 18)),
File: fmt.Sprintf("dir%d/subdir%d/subsubdir%d/file-%d.foo", i%3, i%5, i%7, i%5),
}
if i%3 == 0 {
data.Refs[i].DefUnit = fmt.Sprintf("def-unit-%d", i%17)
data.Refs[i].DefUnitType = fmt.Sprintf("def-unit-type-%d", i%3)
if i%7 == 0 {
data.Refs[i].DefRepo = fmt.Sprintf("def-repo-%d", i%13)
}
}
}
return data
}
示例2: transform
func (c *GraphContext) transform(raw *RawOutput, unit *unit.SourceUnit) *graph.Output {
var out graph.Output
for _, def := range raw.Defs {
out.Defs = append(out.Defs, c.transformDef(def))
if doc := c.transformDefDoc(def); doc != nil {
out.Docs = append(out.Docs, doc)
}
}
for _, ref := range raw.Refs {
if outRef, err := c.transformRef(ref); err == nil {
out.Refs = append(out.Refs, outRef)
} else {
log.Printf("Could not transform ref %v: %s", ref, err)
}
}
return &out
}
示例3: Graph
func Graph(unit *unit.SourceUnit) (*graph.Output, error) {
pkg, err := UnitDataAsBuildPackage(unit)
if err != nil {
return nil, err
}
o, err := doGraph(pkg)
if err != nil {
return nil, err
}
o2 := graph.Output{}
for _, gs := range o.Defs {
d, err := convertGoDef(gs)
if err != nil {
return nil, err
}
if d != nil {
o2.Defs = append(o2.Defs, d)
}
}
for _, gr := range o.Refs {
r, err := convertGoRef(gr)
if err != nil {
return nil, err
}
if r != nil {
o2.Refs = append(o2.Refs, r)
}
}
for _, gd := range o.Docs {
d, err := convertGoDoc(gd)
if err != nil {
return nil, err
}
if d != nil {
o2.Docs = append(o2.Docs, d)
}
}
return &o2, nil
}