Repository navigation
Expand file tree
/
Copy pathindex.go
More file actions
80 lines (65 loc) · 1.71 KB
/
Copy pathindex.go
File metadata and controls
80 lines (65 loc) · 1.71 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"fmt"
"os"
"time"
"github.com/sourcegraph/lsif-go/internal/indexer"
protocol "github.com/sourcegraph/lsif-protocol"
"github.com/sourcegraph/lsif-protocol/writer"
)
func writeIndex(repositoryRoot, projectRoot, moduleName, moduleVersion string, dependencies map[string]string, outFile string) error {
start := time.Now()
out, err := os.Create(outFile)
if err != nil {
return fmt.Errorf("create dump file: %v", err)
}
defer out.Close()
toolInfo := protocol.ToolInfo{
Name: "lsif-go",
Version: version,
Args: os.Args[1:],
}
packageDataCache := indexer.NewPackageDataCache()
// TODO(efritz) - With cgo enabled, the indexer cannot handle packages
// that include assembly (.s) files. To index such a package you need to
// set CGO_ENABLED=0. Consider maybe doing this explicitly, always.
indexer := indexer.New(
repositoryRoot,
projectRoot,
toolInfo,
moduleName,
moduleVersion,
dependencies,
writer.NewJSONWriter(out),
packageDataCache,
indexer.OutputOptions{
Verbosity: getVerbosity(),
ShowAnimations: !noAnimation,
},
)
if err := indexer.Index(); err != nil {
return fmt.Errorf("index: %v", err)
}
if isVerbose() {
displayStats(indexer.Stats(), packageDataCache.Stats(), start)
}
return nil
}
var verbosityLevels = map[int]indexer.Verbosity{
0: indexer.DefaultOutput,
1: indexer.VerboseOutput,
2: indexer.VeryVerboseOutput,
3: indexer.VeryVeryVerboseOutput,
}
func getVerbosity() indexer.Verbosity {
if noOutput {
return indexer.NoOutput
}
if verbosity >= len(verbosityLevels) {
verbosity = len(verbosityLevels) - 1
}
return verbosityLevels[verbosity]
}
func isVerbose() bool {
return getVerbosity() >= indexer.VerboseOutput
}