本文整理汇总了Golang中sourcegraph/com/sourcegraph/srclib/unit.SourceUnit类的典型用法代码示例。如果您正苦于以下问题:Golang SourceUnit类的具体用法?Golang SourceUnit怎么用?Golang SourceUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SourceUnit类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SourceUnitMatchesArgs
func SourceUnitMatchesArgs(specified []string, u *unit.SourceUnit) bool {
var match bool
if len(specified) == 0 {
match = true
} else {
for _, unitSpec := range specified {
if string(u.ID()) == unitSpec || u.Name == unitSpec {
match = true
break
}
}
}
return match
}
示例2: addSourceUnitFiles
func addSourceUnitFiles(u *unit.SourceUnit, file string) {
for _, f := range u.Files {
if f == file {
return
}
}
u.Files = append(u.Files, file)
}
示例3: addSourceUnitFilesFromData
func addSourceUnitFilesFromData(u *unit.SourceUnit, data *graph.Output) {
files := map[string]struct{}{}
for _, def := range data.Defs {
files[def.File] = struct{}{}
}
for _, ref := range data.Refs {
files[ref.File] = struct{}{}
}
for f := range files {
u.Files = append(u.Files, f)
}
sort.Strings(u.Files)
}
示例4: genUnit
func (c *SimpleRepoCmd) genUnit(ut *unit.SourceUnit) error {
defs := make([]*graph.Def, 0)
refs := make([]*graph.Ref, 0)
docs := make([]*graph.Doc, 0)
for _, filename := range hierarchicalNames("dir", "file", ut.Name, c.NFiles) {
ut.Files = append(ut.Files, filename)
fileDefs, fileRefs, fileDocs, err := c.genFile(ut, filename)
if err != nil {
return err
}
defs, refs, docs = append(defs, fileDefs...), append(refs, fileRefs...), append(docs, fileDocs...)
}
if !c.GenSource {
gr := graph.Output{Defs: defs, Refs: refs, Docs: docs}
deps := make([]*dep.Resolution, 0)
if err := writeSrclibCache(ut, &gr, deps); err != nil {
return err
}
}
return nil
}
示例5: SelectUnit
func (f unitDefOffsetsFilter) SelectUnit(u *unit.SourceUnit) bool {
_, present := f[u.ID2()]
return present
}
示例6: genDefsFile
func (c *URefsRepoCmd) genDefsFile(ut *unit.SourceUnit, filename string) (defs []*graph.Def, defRefs []*graph.Ref, err error) {
filename = filepath.Join(ut.Name, filename)
ut.Files = append(ut.Files, filename)
offset := 0
defName := "foo"
var sourceFile *os.File
if c.GenSource {
err := os.MkdirAll(filepath.Dir(filename), 0700)
if err != nil {
return nil, nil, err
}
file, err := os.Create(filename)
if err != nil {
return nil, nil, err
}
sourceFile = file
}
for i := 0; i < c.NDefs; i++ {
def := &graph.Def{
DefKey: graph.DefKey{
Repo: ut.Repo,
CommitID: ut.CommitID,
UnitType: ut.Type,
Unit: ut.Name,
Path: filepath.ToSlash(filepath.Join(filename, fmt.Sprintf("method_%d", i))),
},
Name: defName,
Exported: true,
File: filename,
DefStart: uint32(offset),
DefEnd: uint32(offset + len(defName) - 1),
}
if sourceFile != nil {
_, err := sourceFile.WriteString(def.Name + "\n")
if err != nil {
return nil, nil, err
}
}
offset += len(defName) + 1
defs = append(defs, def)
defRef := &graph.Ref{
DefRepo: def.Repo,
DefUnitType: def.UnitType,
DefUnit: def.Unit,
DefPath: def.Path,
Repo: def.Repo,
CommitID: def.CommitID,
UnitType: def.UnitType,
Unit: def.Unit,
Def: true,
File: def.File,
Start: def.DefStart,
End: def.DefEnd,
}
defRefs = append(defRefs, defRef)
}
// Close source file
if sourceFile != nil {
sourceFile.WriteString("\n")
sourceFile.Close()
}
return defs, defRefs, nil
}
示例7: checkSourceUnitFiles
// checkSourceUnitFiles warns if any files appear in graph data but
// are not in u.Files.
func (s *indexedTreeStore) checkSourceUnitFiles(u *unit.SourceUnit, data graph.Output) {
if u == nil {
return
}
graphFiles := make(map[string]struct{}, len(u.Files))
for _, def := range data.Defs {
graphFiles[def.File] = struct{}{}
}
for _, ref := range data.Refs {
graphFiles[ref.File] = struct{}{}
}
for _, doc := range data.Docs {
graphFiles[doc.File] = struct{}{}
}
for _, ann := range data.Anns {
graphFiles[ann.File] = struct{}{}
}
delete(graphFiles, "")
unitFiles := make(map[string]struct{}, len(u.Files))
for _, f := range u.Files {
unitFiles[f] = struct{}{}
}
if u.Dir != "" {
unitFiles[u.Dir] = struct{}{}
}
var missingFiles []string
for f := range graphFiles {
if _, present := unitFiles[f]; !present {
missingFiles = append(missingFiles, f)
}
}
if len(missingFiles) > 0 {
sort.Strings(missingFiles)
log.Printf("Warning: The graph output (defs/refs/docs/anns) for source unit %+v contain %d references to files that are not present in the source unit's Files list. Indexed lookups by any of these missing files will return no results. To fix this, ensure that the source unit's Files list includes all files that appear in the graph output. The missing files are: %s.", u.ID2(), len(missingFiles), strings.Join(missingFiles, " "))
}
}
示例8: Scan
// Scan a directory, listing all source units
func Scan(srcdir string, repoURI string, repoSubdir string) ([]*unit.SourceUnit, error) {
if units, isSpecial := specialUnits[repoURI]; isSpecial {
return units, nil
}
p, err := getVENVBinPath()
if err != nil {
return nil, err
}
cmd := exec.Command(filepath.Join(p, "python"), filepath.Join(p, "pydep-run.py"), "list", srcdir)
cmd.Stderr = os.Stderr
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
if err := cmd.Start(); err != nil {
return nil, err
}
var pkgs []*pkgInfo
if err := json.NewDecoder(stdout).Decode(&pkgs); err != nil {
return nil, err
}
if err := cmd.Wait(); err != nil {
return nil, err
}
// Keep track of all files that have been successfully discovered
discoveredScripts := make(map[string]bool)
units := make([]*unit.SourceUnit, len(pkgs))
for i, pkg := range pkgs {
units[i] = pkg.SourceUnit()
units[i].Files = pythonSourceFiles(pkg.RootDir, discoveredScripts)
units[i].Repo = repoURI // override whatever's in the setup.py file with the actual reposit;5Dory URI
reqs, err := requirements(pkg.RootDir)
if err != nil {
return nil, err
}
reqs_ := make([]interface{}, len(reqs))
for i, req := range reqs {
reqs_[i] = req
}
units[i].Dependencies = reqs_
}
// Scan for independant scripts, appending to the current set of source units
scripts := pythonSourceFiles(srcdir, discoveredScripts)
if len(scripts) > 0 {
scriptsUnit := unit.SourceUnit{
Name: ".",
Type: "PythonProgram",
Files: scripts,
Dir: ".",
Ops: map[string]*srclib.ToolRef{"depresolve": nil, "graph": nil},
}
reqs, err := requirements(srcdir)
if err == nil {
reqs_ := make([]interface{}, len(reqs))
for i, req := range reqs {
reqs_[i] = req
}
scriptsUnit.Dependencies = reqs_
}
units = append(units, &scriptsUnit)
}
return units, nil
}
示例9: SelectUnit
func (f byUnitsFilter) SelectUnit(unit *unit.SourceUnit) bool {
return (unit.Type == "" && unit.Name == "") || f.contains(unit.ID2())
}