mirror of
https://github.com/golang/go
synced 2024-11-05 14:56:10 -07:00
internal/imports: consider direct mod deps more relevant
As a followup to CL 204203, prefer direct dependencies over indirect. This should improve results for common names like "log" and "errors". Updates golang/go#36077. Change-Id: I3f8cfa070832c2035aec60c4e583ee1c0abf5085 Reviewed-on: https://go-review.googlesource.com/c/tools/+/212021 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
2208e1677e
commit
62b9674312
@ -41,6 +41,7 @@ type ModuleJSON struct {
|
||||
Path string // module path
|
||||
Replace *ModuleJSON // replaced by this module
|
||||
Main bool // is this the main module?
|
||||
Indirect bool // is this module only an indirect dependency of main module?
|
||||
Dir string // directory holding files for this module, if any
|
||||
GoMod string // path to go.mod file for this module, if any
|
||||
GoVersion string // go version used in module
|
||||
@ -433,10 +434,14 @@ func (r *ModuleResolver) canonicalize(info directoryPackageInfo) (*pkg, error) {
|
||||
}
|
||||
|
||||
importPath := info.nonCanonicalImportPath
|
||||
relevance := 2
|
||||
relevance := 3
|
||||
// Check if the directory is underneath a module that's in scope.
|
||||
if mod := r.findModuleByDir(info.dir); mod != nil {
|
||||
relevance = 1
|
||||
if mod.Indirect {
|
||||
relevance = 2
|
||||
} else {
|
||||
relevance = 1
|
||||
}
|
||||
// It is. If dir is the target of a replace directive,
|
||||
// our guessed import path is wrong. Use the real one.
|
||||
if mod.Dir == info.dir {
|
||||
|
@ -856,10 +856,11 @@ import _ "rsc.io/quote"
|
||||
// Stdlib
|
||||
{"bytes", "bytes"},
|
||||
{"http", "net/http"},
|
||||
// In scope modules
|
||||
{"language", "golang.org/x/text/language"},
|
||||
// Direct module deps
|
||||
{"quote", "rsc.io/quote"},
|
||||
// Indirect deps
|
||||
{"rpackage", "example.com/rpackage"},
|
||||
{"language", "golang.org/x/text/language"},
|
||||
// Out of scope modules
|
||||
{"quote", "rsc.io/quote/v2"},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user