Skip to content

Commit 470d58f

Browse files
Don't panic on missing pkg.Module
1 parent 4e8264a commit 470d58f

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ scip-go --version
2020

2121
## Indexing a Go project
2222

23+
### Standard `go.mod` project
24+
2325
From the root of your project, you can run:
2426

2527
```
@@ -39,6 +41,18 @@ If this doesn't solve the problem, check the rest of the available flags in:
3941
scip-go --help
4042
```
4143

44+
### Other build systems
45+
46+
The other build systems Buck/Bazel/Please/etc are supported via [Go Packages Driver Protocol](https://pkg.go.dev/golang.org/x/tools/go/packages#hdr-The_driver_protocol).
47+
48+
49+
Usage:
50+
```
51+
GOPACKAGESDRIVER=your_driver scip-go
52+
```
53+
54+
Note: Due to the current protocol design cross-repo navigation will not work.
55+
4256
### Common Problems:
4357

4458
- Unable to navigate to Go standard library.
@@ -54,7 +68,7 @@ scip-go --help
5468

5569
`scip-go` by default uses a few different `go` commands from the command line to
5670
gain information about the project and module. To avoid running `go` directly
57-
(perhaps you have some other build system), you will need to supply the folling args.
71+
(perhaps you have some other build system), you will need to supply the following args.
5872

5973
```
6074
scip-go --module-name="<my modules name here>"

internal/config/config.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package config
22

3-
import "path/filepath"
3+
import (
4+
"os"
5+
"path/filepath"
6+
)
47

58
type IndexOpts struct {
69
ModuleRoot string
@@ -9,6 +12,8 @@ type IndexOpts struct {
912
// Path for the current module we are indexing. Same as packages.Package.Module.Path
1013
ModulePath string
1114

15+
IsGoPackagesDriverSet bool
16+
1217
// Go version. Used for linking to the Go standard library
1318
GoStdlibVersion string
1419

@@ -25,13 +30,17 @@ func New(ModuleRoot, ModuleVersion, ModulePath, GoStdlibVersion string, IsIndexi
2530
panic(err)
2631
}
2732

33+
driver := os.Getenv("GOPACKAGESDRIVER")
34+
isGoPackagesDriverSet := driver != "" && driver != "off"
35+
2836
return IndexOpts{
29-
ModuleRoot: ModuleRoot,
30-
ModuleVersion: ModuleVersion,
31-
ModulePath: ModulePath,
32-
GoStdlibVersion: GoStdlibVersion,
33-
SkipImplementations: SkipImplementations,
34-
SkipTests: SkipTests,
35-
IsIndexingStdlib: IsIndexingStdlib,
37+
ModuleRoot: ModuleRoot,
38+
ModuleVersion: ModuleVersion,
39+
ModulePath: ModulePath,
40+
GoStdlibVersion: GoStdlibVersion,
41+
SkipImplementations: SkipImplementations,
42+
SkipTests: SkipTests,
43+
IsIndexingStdlib: IsIndexingStdlib,
44+
IsGoPackagesDriverSet: isGoPackagesDriverSet,
3645
}
3746
}

internal/loader/loader.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,23 @@ func normalizePackage(opts *config.IndexOpts, pkg *packages.Package) *packages.P
164164
// Path string = "github.com/efritz/pentimento"
165165
// Version string = "v0.0.0-20190429011147-ade47d831101"
166166

167+
if opts.IsGoPackagesDriverSet {
168+
pkg.Module = &packages.Module{
169+
Path: ".",
170+
Version: ".",
171+
}
172+
173+
if opts.ModulePath != "" {
174+
pkg.Module.Path = opts.ModulePath
175+
}
176+
177+
if opts.ModuleVersion != "" {
178+
pkg.Module.Version = opts.ModuleVersion
179+
}
180+
181+
return pkg
182+
}
183+
167184
if IsStandardLib(pkg) || opts.IsIndexingStdlib {
168185
pkg.Module = &packages.Module{
169186
Path: "github.com/golang/go/src",
@@ -183,7 +200,6 @@ func normalizePackage(opts *config.IndexOpts, pkg *packages.Package) *packages.P
183200
pkg.PkgPath,
184201
))
185202
}
186-
187203
}
188204

189205
// Follow replaced modules

0 commit comments

Comments
 (0)