Repository navigation
Expand file tree
/
Copy pathindex.go
More file actions
82 lines (67 loc) · 1.94 KB
/
Copy pathindex.go
File metadata and controls
82 lines (67 loc) · 1.94 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
892E
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
81
82
package main
import (
"fmt"
"os"
"time"
"github.com/sourcegraph/lsif-go/internal/gomod"
"github.com/sourcegraph/lsif-go/internal/indexer"
"github.com/sourcegraph/lsif-go/internal/output"
protocol "github.com/sourcegraph/sourcegraph/lib/codeintel/lsif/protocol"
"github.com/sourcegraph/sourcegraph/lib/codeintel/lsif/protocol/writer"
)
func writeIndex(repositoryRoot, repositoryRemote, projectRoot, moduleName, moduleVersion string, dependencies map[string]gomod.GoModule, projectDependencies []string, outFile string, outputOptions output.Options, generationOptions indexer.GenerationOptions) error {
start := time.Now()
out, err := os.Create(outFile)
if err != nil {
return fmt.Errorf("failed to 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,
repositoryRemote,
projectRoot,
toolInfo,
moduleName,
moduleVersion,
dependencies,
projectDependencies,
writer.NewJSONWriter(out),
packageDataCache,
outputOptions,
generationOptions,
)
if err := indexer.Index(); err != nil {
return err
}
if isVerbose() {
displayStats(indexer.Stats(), packageDataCache.Stats(), start)
}
return nil
}
var verbosityLevels = map[int]output.Verbosity{
0: output.DefaultOutput,
1: output.VerboseOutput,
2: output.VeryVerboseOutput,
3: output.VeryVeryVerboseOutput,
}
func getVerbosity() output.Verbosity {
if noOutput {
return output.NoOutput
}
if verbosity >= len(verbosityLevels) {
verbosity = len(verbosityLevels) - 1
}
return verbosityLevels[verbosity]
}
func isVerbose() bool {
return getVerbosity() >= output.VerboseOutput
}