mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Update github.com/blevesearch/bleve v1.0.13 -> v1.0.14 (#13947)
This commit is contained in:
13
vendor/golang.org/x/tools/go/analysis/analysis.go
generated
vendored
13
vendor/golang.org/x/tools/go/analysis/analysis.go
generated
vendored
@@ -95,12 +95,13 @@ type Pass struct {
|
||||
Analyzer *Analyzer // the identity of the current analyzer
|
||||
|
||||
// syntax and type information
|
||||
Fset *token.FileSet // file position information
|
||||
Files []*ast.File // the abstract syntax tree of each file
|
||||
OtherFiles []string // names of non-Go files of this package
|
||||
Pkg *types.Package // type information about the package
|
||||
TypesInfo *types.Info // type information about the syntax trees
|
||||
TypesSizes types.Sizes // function for computing sizes of types
|
||||
Fset *token.FileSet // file position information
|
||||
Files []*ast.File // the abstract syntax tree of each file
|
||||
OtherFiles []string // names of non-Go files of this package
|
||||
IgnoredFiles []string // names of ignored source files in this package
|
||||
Pkg *types.Package // type information about the package
|
||||
TypesInfo *types.Info // type information about the syntax trees
|
||||
TypesSizes types.Sizes // function for computing sizes of types
|
||||
|
||||
// Report reports a Diagnostic, a finding about a specific location
|
||||
// in the analyzed source code such as a potential mistake.
|
||||
|
21
vendor/golang.org/x/tools/go/analysis/doc.go
generated
vendored
21
vendor/golang.org/x/tools/go/analysis/doc.go
generated
vendored
@@ -121,13 +121,14 @@ package being analyzed, and provides operations to the Run function for
|
||||
reporting diagnostics and other information back to the driver.
|
||||
|
||||
type Pass struct {
|
||||
Fset *token.FileSet
|
||||
Files []*ast.File
|
||||
OtherFiles []string
|
||||
Pkg *types.Package
|
||||
TypesInfo *types.Info
|
||||
ResultOf map[*Analyzer]interface{}
|
||||
Report func(Diagnostic)
|
||||
Fset *token.FileSet
|
||||
Files []*ast.File
|
||||
OtherFiles []string
|
||||
IgnoredFiles []string
|
||||
Pkg *types.Package
|
||||
TypesInfo *types.Info
|
||||
ResultOf map[*Analyzer]interface{}
|
||||
Report func(Diagnostic)
|
||||
...
|
||||
}
|
||||
|
||||
@@ -139,6 +140,12 @@ files such as assembly that are part of this package. See the "asmdecl"
|
||||
or "buildtags" analyzers for examples of loading non-Go files and reporting
|
||||
diagnostics against them.
|
||||
|
||||
The IgnoredFiles field provides the names, but not the contents,
|
||||
of ignored Go and non-Go source files that are not part of this package
|
||||
with the current build configuration but may be part of other build
|
||||
configurations. See the "buildtags" analyzer for an example of loading
|
||||
and checking IgnoredFiles.
|
||||
|
||||
The ResultOf field provides the results computed by the analyzers
|
||||
required by this one, as expressed in its Analyzer.Requires field. The
|
||||
driver runs the required analyzers first and makes their results
|
||||
|
2
vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker.go
generated
vendored
2
vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker.go
generated
vendored
@@ -63,6 +63,7 @@ type Config struct {
|
||||
ImportPath string
|
||||
GoFiles []string
|
||||
NonGoFiles []string
|
||||
IgnoredFiles []string
|
||||
ImportMap map[string]string
|
||||
PackageFile map[string]string
|
||||
Standard map[string]bool
|
||||
@@ -333,6 +334,7 @@ func run(fset *token.FileSet, cfg *Config, analyzers []*analysis.Analyzer) ([]re
|
||||
Fset: fset,
|
||||
Files: files,
|
||||
OtherFiles: cfg.NonGoFiles,
|
||||
IgnoredFiles: cfg.IgnoredFiles,
|
||||
Pkg: pkg,
|
||||
TypesInfo: info,
|
||||
TypesSizes: tc.Sizes,
|
||||
|
26
vendor/golang.org/x/tools/go/internal/packagesdriver/sizes.go
generated
vendored
26
vendor/golang.org/x/tools/go/internal/packagesdriver/sizes.go
generated
vendored
@@ -39,7 +39,12 @@ func GetSizes(ctx context.Context, buildFlags, env []string, gocmdRunner *gocomm
|
||||
}
|
||||
|
||||
if tool == "off" {
|
||||
return GetSizesGolist(ctx, buildFlags, env, gocmdRunner, dir)
|
||||
inv := gocommand.Invocation{
|
||||
BuildFlags: buildFlags,
|
||||
Env: env,
|
||||
WorkingDir: dir,
|
||||
}
|
||||
return GetSizesGolist(ctx, inv, gocmdRunner)
|
||||
}
|
||||
|
||||
req, err := json.Marshal(struct {
|
||||
@@ -75,26 +80,17 @@ func GetSizes(ctx context.Context, buildFlags, env []string, gocmdRunner *gocomm
|
||||
return response.Sizes, nil
|
||||
}
|
||||
|
||||
func GetSizesGolist(ctx context.Context, buildFlags, env []string, gocmdRunner *gocommand.Runner, dir string) (types.Sizes, error) {
|
||||
inv := gocommand.Invocation{
|
||||
Verb: "list",
|
||||
Args: []string{"-f", "{{context.GOARCH}} {{context.Compiler}}", "--", "unsafe"},
|
||||
Env: env,
|
||||
BuildFlags: buildFlags,
|
||||
WorkingDir: dir,
|
||||
}
|
||||
func GetSizesGolist(ctx context.Context, inv gocommand.Invocation, gocmdRunner *gocommand.Runner) (types.Sizes, error) {
|
||||
inv.Verb = "list"
|
||||
inv.Args = []string{"-f", "{{context.GOARCH}} {{context.Compiler}}", "--", "unsafe"}
|
||||
stdout, stderr, friendlyErr, rawErr := gocmdRunner.RunRaw(ctx, inv)
|
||||
var goarch, compiler string
|
||||
if rawErr != nil {
|
||||
if strings.Contains(rawErr.Error(), "cannot find main module") {
|
||||
// User's running outside of a module. All bets are off. Get GOARCH and guess compiler is gc.
|
||||
// TODO(matloob): Is this a problem in practice?
|
||||
inv := gocommand.Invocation{
|
||||
Verb: "env",
|
||||
Args: []string{"GOARCH"},
|
||||
Env: env,
|
||||
WorkingDir: dir,
|
||||
}
|
||||
inv.Verb = "env"
|
||||
inv.Args = []string{"GOARCH"}
|
||||
envout, enverr := gocmdRunner.Run(ctx, inv)
|
||||
if enverr != nil {
|
||||
return nil, enverr
|
||||
|
119
vendor/golang.org/x/tools/go/packages/golist.go
generated
vendored
119
vendor/golang.org/x/tools/go/packages/golist.go
generated
vendored
@@ -91,7 +91,7 @@ type golistState struct {
|
||||
|
||||
goVersionOnce sync.Once
|
||||
goVersionError error
|
||||
goVersion string // third field of 'go version'
|
||||
goVersion int // The X in Go 1.X.
|
||||
|
||||
// vendorDirs caches the (non)existence of vendor directories.
|
||||
vendorDirs map[string]bool
|
||||
@@ -139,6 +139,12 @@ func goListDriver(cfg *Config, patterns ...string) (*driverResponse, error) {
|
||||
|
||||
response := newDeduper()
|
||||
|
||||
state := &golistState{
|
||||
cfg: cfg,
|
||||
ctx: ctx,
|
||||
vendorDirs: map[string]bool{},
|
||||
}
|
||||
|
||||
// Fill in response.Sizes asynchronously if necessary.
|
||||
var sizeserr error
|
||||
var sizeswg sync.WaitGroup
|
||||
@@ -146,19 +152,13 @@ func goListDriver(cfg *Config, patterns ...string) (*driverResponse, error) {
|
||||
sizeswg.Add(1)
|
||||
go func() {
|
||||
var sizes types.Sizes
|
||||
sizes, sizeserr = packagesdriver.GetSizesGolist(ctx, cfg.BuildFlags, cfg.Env, cfg.gocmdRunner, cfg.Dir)
|
||||
sizes, sizeserr = packagesdriver.GetSizesGolist(ctx, state.cfgInvocation(), cfg.gocmdRunner)
|
||||
// types.SizesFor always returns nil or a *types.StdSizes.
|
||||
response.dr.Sizes, _ = sizes.(*types.StdSizes)
|
||||
sizeswg.Done()
|
||||
}()
|
||||
}
|
||||
|
||||
state := &golistState{
|
||||
cfg: cfg,
|
||||
ctx: ctx,
|
||||
vendorDirs: map[string]bool{},
|
||||
}
|
||||
|
||||
// Determine files requested in contains patterns
|
||||
var containFiles []string
|
||||
restPatterns := make([]string, 0, len(patterns))
|
||||
@@ -381,32 +381,34 @@ func (state *golistState) adhocPackage(pattern, query string) (*driverResponse,
|
||||
// Fields must match go list;
|
||||
// see $GOROOT/src/cmd/go/internal/load/pkg.go.
|
||||
type jsonPackage struct {
|
||||
ImportPath string
|
||||
Dir string
|
||||
Name string
|
||||
Export string
|
||||
GoFiles []string
|
||||
CompiledGoFiles []string
|
||||
CFiles []string
|
||||
CgoFiles []string
|
||||
CXXFiles []string
|
||||
MFiles []string
|
||||
HFiles []string
|
||||
FFiles []string
|
||||
SFiles []string
|
||||
SwigFiles []string
|
||||
SwigCXXFiles []string
|
||||
SysoFiles []string
|
||||
Imports []string
|
||||
ImportMap map[string]string
|
||||
Deps []string
|
||||
Module *Module
|
||||
TestGoFiles []string
|
||||
TestImports []string
|
||||
XTestGoFiles []string
|
||||
XTestImports []string
|
||||
ForTest string // q in a "p [q.test]" package, else ""
|
||||
DepOnly bool
|
||||
ImportPath string
|
||||
Dir string
|
||||
Name string
|
||||
Export string
|
||||
GoFiles []string
|
||||
CompiledGoFiles []string
|
||||
IgnoredGoFiles []string
|
||||
IgnoredOtherFiles []string
|
||||
CFiles []string
|
||||
CgoFiles []string
|
||||
CXXFiles []string
|
||||
MFiles []string
|
||||
HFiles []string
|
||||
FFiles []string
|
||||
SFiles []string
|
||||
SwigFiles []string
|
||||
SwigCXXFiles []string
|
||||
SysoFiles []string
|
||||
Imports []string
|
||||
ImportMap map[string]string
|
||||
Deps []string
|
||||
Module *Module
|
||||
TestGoFiles []string
|
||||
TestImports []string
|
||||
XTestGoFiles []string
|
||||
XTestImports []string
|
||||
ForTest string // q in a "p [q.test]" package, else ""
|
||||
DepOnly bool
|
||||
|
||||
Error *jsonPackageError
|
||||
}
|
||||
@@ -558,6 +560,7 @@ func (state *golistState) createDriverResponse(words ...string) (*driverResponse
|
||||
GoFiles: absJoin(p.Dir, p.GoFiles, p.CgoFiles),
|
||||
CompiledGoFiles: absJoin(p.Dir, p.CompiledGoFiles),
|
||||
OtherFiles: absJoin(p.Dir, otherFiles(p)...),
|
||||
IgnoredFiles: absJoin(p.Dir, p.IgnoredGoFiles, p.IgnoredOtherFiles),
|
||||
forTest: p.ForTest,
|
||||
Module: p.Module,
|
||||
}
|
||||
@@ -728,7 +731,7 @@ func (state *golistState) shouldAddFilenameFromError(p *jsonPackage) bool {
|
||||
|
||||
// On Go 1.14 and earlier, only add filenames from errors if the import stack is empty.
|
||||
// The import stack behaves differently for these versions than newer Go versions.
|
||||
if strings.HasPrefix(goV, "go1.13") || strings.HasPrefix(goV, "go1.14") {
|
||||
if goV < 15 {
|
||||
return len(p.Error.ImportStack) == 0
|
||||
}
|
||||
|
||||
@@ -739,31 +742,9 @@ func (state *golistState) shouldAddFilenameFromError(p *jsonPackage) bool {
|
||||
return len(p.Error.ImportStack) == 0 || p.Error.ImportStack[len(p.Error.ImportStack)-1] == p.ImportPath
|
||||
}
|
||||
|
||||
func (state *golistState) getGoVersion() (string, error) {
|
||||
func (state *golistState) getGoVersion() (int, error) {
|
||||
state.goVersionOnce.Do(func() {
|
||||
var b *bytes.Buffer
|
||||
// Invoke go version. Don't use invokeGo because it will supply build flags, and
|
||||
// go version doesn't expect build flags.
|
||||
inv := gocommand.Invocation{
|
||||
Verb: "version",
|
||||
Env: state.cfg.Env,
|
||||
Logf: state.cfg.Logf,
|
||||
}
|
||||
gocmdRunner := state.cfg.gocmdRunner
|
||||
if gocmdRunner == nil {
|
||||
gocmdRunner = &gocommand.Runner{}
|
||||
}
|
||||
b, _, _, state.goVersionError = gocmdRunner.RunRaw(state.cfg.Context, inv)
|
||||
if state.goVersionError != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sp := strings.Split(b.String(), " ")
|
||||
if len(sp) < 3 {
|
||||
state.goVersionError = fmt.Errorf("go version output: expected 'go version <version>', got '%s'", b.String())
|
||||
return
|
||||
}
|
||||
state.goVersion = sp[2]
|
||||
state.goVersion, state.goVersionError = gocommand.GoVersion(state.ctx, state.cfgInvocation(), state.cfg.gocmdRunner)
|
||||
})
|
||||
return state.goVersion, state.goVersionError
|
||||
}
|
||||
@@ -836,18 +817,26 @@ func golistargs(cfg *Config, words []string) []string {
|
||||
return fullargs
|
||||
}
|
||||
|
||||
// invokeGo returns the stdout of a go command invocation.
|
||||
func (state *golistState) invokeGo(verb string, args ...string) (*bytes.Buffer, error) {
|
||||
// cfgInvocation returns an Invocation that reflects cfg's settings.
|
||||
func (state *golistState) cfgInvocation() gocommand.Invocation {
|
||||
cfg := state.cfg
|
||||
|
||||
inv := gocommand.Invocation{
|
||||
Verb: verb,
|
||||
Args: args,
|
||||
return gocommand.Invocation{
|
||||
BuildFlags: cfg.BuildFlags,
|
||||
ModFile: cfg.modFile,
|
||||
ModFlag: cfg.modFlag,
|
||||
Env: cfg.Env,
|
||||
Logf: cfg.Logf,
|
||||
WorkingDir: cfg.Dir,
|
||||
}
|
||||
}
|
||||
|
||||
// invokeGo returns the stdout of a go command invocation.
|
||||
func (state *golistState) invokeGo(verb string, args ...string) (*bytes.Buffer, error) {
|
||||
cfg := state.cfg
|
||||
|
||||
inv := state.cfgInvocation()
|
||||
inv.Verb = verb
|
||||
inv.Args = args
|
||||
gocmdRunner := cfg.gocmdRunner
|
||||
if gocmdRunner == nil {
|
||||
gocmdRunner = &gocommand.Runner{}
|
||||
|
4
vendor/golang.org/x/tools/go/packages/golist_overlay.go
generated
vendored
4
vendor/golang.org/x/tools/go/packages/golist_overlay.go
generated
vendored
@@ -1,3 +1,7 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package packages
|
||||
|
||||
import (
|
||||
|
23
vendor/golang.org/x/tools/go/packages/packages.go
generated
vendored
23
vendor/golang.org/x/tools/go/packages/packages.go
generated
vendored
@@ -144,6 +144,12 @@ type Config struct {
|
||||
// the build system's query tool.
|
||||
BuildFlags []string
|
||||
|
||||
// modFile will be used for -modfile in go command invocations.
|
||||
modFile string
|
||||
|
||||
// modFlag will be used for -modfile in go command invocations.
|
||||
modFlag string
|
||||
|
||||
// Fset provides source position information for syntax trees and types.
|
||||
// If Fset is nil, Load will use a new fileset, but preserve Fset's value.
|
||||
Fset *token.FileSet
|
||||
@@ -289,6 +295,11 @@ type Package struct {
|
||||
// including assembly, C, C++, Fortran, Objective-C, SWIG, and so on.
|
||||
OtherFiles []string
|
||||
|
||||
// IgnoredFiles lists source files that are not part of the package
|
||||
// using the current build configuration but that might be part of
|
||||
// the package using other build configurations.
|
||||
IgnoredFiles []string
|
||||
|
||||
// ExportFile is the absolute path to a file containing type
|
||||
// information for the package as provided by the build system.
|
||||
ExportFile string
|
||||
@@ -361,6 +372,12 @@ func init() {
|
||||
packagesinternal.SetGoCmdRunner = func(config interface{}, runner *gocommand.Runner) {
|
||||
config.(*Config).gocmdRunner = runner
|
||||
}
|
||||
packagesinternal.SetModFile = func(config interface{}, value string) {
|
||||
config.(*Config).modFile = value
|
||||
}
|
||||
packagesinternal.SetModFlag = func(config interface{}, value string) {
|
||||
config.(*Config).modFlag = value
|
||||
}
|
||||
packagesinternal.TypecheckCgo = int(typecheckCgo)
|
||||
}
|
||||
|
||||
@@ -404,6 +421,7 @@ type flatPackage struct {
|
||||
GoFiles []string `json:",omitempty"`
|
||||
CompiledGoFiles []string `json:",omitempty"`
|
||||
OtherFiles []string `json:",omitempty"`
|
||||
IgnoredFiles []string `json:",omitempty"`
|
||||
ExportFile string `json:",omitempty"`
|
||||
Imports map[string]string `json:",omitempty"`
|
||||
}
|
||||
@@ -426,6 +444,7 @@ func (p *Package) MarshalJSON() ([]byte, error) {
|
||||
GoFiles: p.GoFiles,
|
||||
CompiledGoFiles: p.CompiledGoFiles,
|
||||
OtherFiles: p.OtherFiles,
|
||||
IgnoredFiles: p.IgnoredFiles,
|
||||
ExportFile: p.ExportFile,
|
||||
}
|
||||
if len(p.Imports) > 0 {
|
||||
@@ -712,7 +731,8 @@ func (ld *loader) refine(roots []string, list ...*Package) ([]*Package, error) {
|
||||
result[i] = lpkg.Package
|
||||
}
|
||||
for i := range ld.pkgs {
|
||||
// Clear all unrequested fields, for extra de-Hyrum-ization.
|
||||
// Clear all unrequested fields,
|
||||
// to catch programs that use more than they request.
|
||||
if ld.requestedMode&NeedName == 0 {
|
||||
ld.pkgs[i].Name = ""
|
||||
ld.pkgs[i].PkgPath = ""
|
||||
@@ -720,6 +740,7 @@ func (ld *loader) refine(roots []string, list ...*Package) ([]*Package, error) {
|
||||
if ld.requestedMode&NeedFiles == 0 {
|
||||
ld.pkgs[i].GoFiles = nil
|
||||
ld.pkgs[i].OtherFiles = nil
|
||||
ld.pkgs[i].IgnoredFiles = nil
|
||||
}
|
||||
if ld.requestedMode&NeedCompiledGoFiles == 0 {
|
||||
ld.pkgs[i].CompiledGoFiles = nil
|
||||
|
36
vendor/golang.org/x/tools/internal/gocommand/invoke.go
generated
vendored
36
vendor/golang.org/x/tools/internal/gocommand/invoke.go
generated
vendored
@@ -130,6 +130,8 @@ type Invocation struct {
|
||||
Verb string
|
||||
Args []string
|
||||
BuildFlags []string
|
||||
ModFlag string
|
||||
ModFile string
|
||||
Env []string
|
||||
WorkingDir string
|
||||
Logf func(format string, args ...interface{})
|
||||
@@ -158,17 +160,35 @@ func (i *Invocation) run(ctx context.Context, stdout, stderr io.Writer) error {
|
||||
}
|
||||
|
||||
goArgs := []string{i.Verb}
|
||||
|
||||
appendModFile := func() {
|
||||
if i.ModFile != "" {
|
||||
goArgs = append(goArgs, "-modfile="+i.ModFile)
|
||||
}
|
||||
}
|
||||
appendModFlag := func() {
|
||||
if i.ModFlag != "" {
|
||||
goArgs = append(goArgs, "-mod="+i.ModFlag)
|
||||
}
|
||||
}
|
||||
|
||||
switch i.Verb {
|
||||
case "mod":
|
||||
// mod needs the sub-verb before build flags.
|
||||
goArgs = append(goArgs, i.Args[0])
|
||||
goArgs = append(goArgs, i.BuildFlags...)
|
||||
goArgs = append(goArgs, i.Args[1:]...)
|
||||
case "env":
|
||||
// env doesn't take build flags.
|
||||
case "env", "version":
|
||||
goArgs = append(goArgs, i.Args...)
|
||||
default:
|
||||
case "mod":
|
||||
// mod needs the sub-verb before flags.
|
||||
goArgs = append(goArgs, i.Args[0])
|
||||
appendModFile()
|
||||
goArgs = append(goArgs, i.Args[1:]...)
|
||||
case "get":
|
||||
goArgs = append(goArgs, i.BuildFlags...)
|
||||
appendModFile()
|
||||
goArgs = append(goArgs, i.Args...)
|
||||
|
||||
default: // notably list and build.
|
||||
goArgs = append(goArgs, i.BuildFlags...)
|
||||
appendModFile()
|
||||
appendModFlag()
|
||||
goArgs = append(goArgs, i.Args...)
|
||||
}
|
||||
cmd := exec.Command("go", goArgs...)
|
||||
|
40
vendor/golang.org/x/tools/internal/gocommand/version.go
generated
vendored
Normal file
40
vendor/golang.org/x/tools/internal/gocommand/version.go
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package gocommand
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GoVersion checks the go version by running "go list" with modules off.
|
||||
// It returns the X in Go 1.X.
|
||||
func GoVersion(ctx context.Context, inv Invocation, r *Runner) (int, error) {
|
||||
inv.Verb = "list"
|
||||
inv.Args = []string{"-e", "-f", `{{context.ReleaseTags}}`}
|
||||
inv.Env = append(append([]string{}, inv.Env...), "GO111MODULE=off")
|
||||
// Unset any unneeded flags.
|
||||
inv.ModFile = ""
|
||||
inv.ModFlag = ""
|
||||
stdoutBytes, err := r.Run(ctx, inv)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
stdout := stdoutBytes.String()
|
||||
if len(stdout) < 3 {
|
||||
return 0, fmt.Errorf("bad ReleaseTags output: %q", stdout)
|
||||
}
|
||||
// Split up "[go1.1 go1.15]"
|
||||
tags := strings.Fields(stdout[1 : len(stdout)-2])
|
||||
for i := len(tags) - 1; i >= 0; i-- {
|
||||
var version int
|
||||
if _, err := fmt.Sscanf(tags[i], "go1.%d", &version); err != nil {
|
||||
continue
|
||||
}
|
||||
return version, nil
|
||||
}
|
||||
return 0, fmt.Errorf("no parseable ReleaseTags in %v", tags)
|
||||
}
|
34
vendor/golang.org/x/tools/internal/imports/fix.go
generated
vendored
34
vendor/golang.org/x/tools/internal/imports/fix.go
generated
vendored
@@ -83,7 +83,7 @@ type ImportFix struct {
|
||||
IdentName string
|
||||
// FixType is the type of fix this is (AddImport, DeleteImport, SetImportName).
|
||||
FixType ImportFixType
|
||||
Relevance int // see pkg
|
||||
Relevance float64 // see pkg
|
||||
}
|
||||
|
||||
// An ImportInfo represents a single import statement.
|
||||
@@ -592,9 +592,9 @@ func getFixes(fset *token.FileSet, f *ast.File, filename string, env *ProcessEnv
|
||||
return fixes, nil
|
||||
}
|
||||
|
||||
// Highest relevance, used for the standard library. Chosen arbitrarily to
|
||||
// match pre-existing gopls code.
|
||||
const MaxRelevance = 7
|
||||
// MaxRelevance is the highest relevance, used for the standard library.
|
||||
// Chosen arbitrarily to match pre-existing gopls code.
|
||||
const MaxRelevance = 7.0
|
||||
|
||||
// getCandidatePkgs works with the passed callback to find all acceptable packages.
|
||||
// It deduplicates by import path, and uses a cached stdlib rather than reading
|
||||
@@ -607,6 +607,10 @@ func getCandidatePkgs(ctx context.Context, wrappedCallback *scanCallback, filena
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var mu sync.Mutex // to guard asynchronous access to dupCheck
|
||||
dupCheck := map[string]struct{}{}
|
||||
|
||||
// Start off with the standard library.
|
||||
for importPath, exports := range stdlib {
|
||||
p := &pkg{
|
||||
@@ -615,14 +619,12 @@ func getCandidatePkgs(ctx context.Context, wrappedCallback *scanCallback, filena
|
||||
packageName: path.Base(importPath),
|
||||
relevance: MaxRelevance,
|
||||
}
|
||||
dupCheck[importPath] = struct{}{}
|
||||
if notSelf(p) && wrappedCallback.dirFound(p) && wrappedCallback.packageNameLoaded(p) {
|
||||
wrappedCallback.exportsLoaded(p, exports)
|
||||
}
|
||||
}
|
||||
|
||||
var mu sync.Mutex
|
||||
dupCheck := map[string]struct{}{}
|
||||
|
||||
scanFilter := &scanCallback{
|
||||
rootFound: func(root gopathwalk.Root) bool {
|
||||
// Exclude goroot results -- getting them is relatively expensive, not cached,
|
||||
@@ -658,8 +660,8 @@ func getCandidatePkgs(ctx context.Context, wrappedCallback *scanCallback, filena
|
||||
return resolver.scan(ctx, scanFilter)
|
||||
}
|
||||
|
||||
func ScoreImportPaths(ctx context.Context, env *ProcessEnv, paths []string) (map[string]int, error) {
|
||||
result := make(map[string]int)
|
||||
func ScoreImportPaths(ctx context.Context, env *ProcessEnv, paths []string) (map[string]float64, error) {
|
||||
result := make(map[string]float64)
|
||||
resolver, err := env.GetResolver()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -802,6 +804,8 @@ type ProcessEnv struct {
|
||||
GocmdRunner *gocommand.Runner
|
||||
|
||||
BuildFlags []string
|
||||
ModFlag string
|
||||
ModFile string
|
||||
|
||||
// Env overrides the OS environment, and can be used to specify
|
||||
// GOPROXY, GO111MODULE, etc. PATH cannot be set here, because
|
||||
@@ -995,7 +999,7 @@ type Resolver interface {
|
||||
// loadExports may be called concurrently.
|
||||
loadExports(ctx context.Context, pkg *pkg, includeTest bool) (string, []string, error)
|
||||
// scoreImportPath returns the relevance for an import path.
|
||||
scoreImportPath(ctx context.Context, path string) int
|
||||
scoreImportPath(ctx context.Context, path string) float64
|
||||
|
||||
ClearForNewScan()
|
||||
}
|
||||
@@ -1260,10 +1264,10 @@ func packageDirToName(dir string) (packageName string, err error) {
|
||||
}
|
||||
|
||||
type pkg struct {
|
||||
dir string // absolute file path to pkg directory ("/usr/lib/go/src/net/http")
|
||||
importPathShort string // vendorless import path ("net/http", "a/b")
|
||||
packageName string // package name loaded from source if requested
|
||||
relevance int // a weakly-defined score of how relevant a package is. 0 is most relevant.
|
||||
dir string // absolute file path to pkg directory ("/usr/lib/go/src/net/http")
|
||||
importPathShort string // vendorless import path ("net/http", "a/b")
|
||||
packageName string // package name loaded from source if requested
|
||||
relevance float64 // a weakly-defined score of how relevant a package is. 0 is most relevant.
|
||||
}
|
||||
|
||||
type pkgDistance struct {
|
||||
@@ -1389,7 +1393,7 @@ func (r *gopathResolver) scan(ctx context.Context, callback *scanCallback) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *gopathResolver) scoreImportPath(ctx context.Context, path string) int {
|
||||
func (r *gopathResolver) scoreImportPath(ctx context.Context, path string) float64 {
|
||||
if _, ok := stdlib[path]; ok {
|
||||
return MaxRelevance
|
||||
}
|
||||
|
26
vendor/golang.org/x/tools/internal/imports/mod.go
generated
vendored
26
vendor/golang.org/x/tools/internal/imports/mod.go
generated
vendored
@@ -59,6 +59,8 @@ func (r *ModuleResolver) init() error {
|
||||
}
|
||||
inv := gocommand.Invocation{
|
||||
BuildFlags: r.env.BuildFlags,
|
||||
ModFlag: r.env.ModFlag,
|
||||
ModFile: r.env.ModFile,
|
||||
Env: r.env.env(),
|
||||
Logf: r.env.Logf,
|
||||
WorkingDir: r.env.WorkingDir,
|
||||
@@ -487,7 +489,7 @@ func (r *ModuleResolver) scan(ctx context.Context, callback *scanCallback) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ModuleResolver) scoreImportPath(ctx context.Context, path string) int {
|
||||
func (r *ModuleResolver) scoreImportPath(ctx context.Context, path string) float64 {
|
||||
if _, ok := stdlib[path]; ok {
|
||||
return MaxRelevance
|
||||
}
|
||||
@@ -495,17 +497,31 @@ func (r *ModuleResolver) scoreImportPath(ctx context.Context, path string) int {
|
||||
return modRelevance(mod)
|
||||
}
|
||||
|
||||
func modRelevance(mod *gocommand.ModuleJSON) int {
|
||||
func modRelevance(mod *gocommand.ModuleJSON) float64 {
|
||||
var relevance float64
|
||||
switch {
|
||||
case mod == nil: // out of scope
|
||||
return MaxRelevance - 4
|
||||
case mod.Indirect:
|
||||
return MaxRelevance - 3
|
||||
relevance = MaxRelevance - 3
|
||||
case !mod.Main:
|
||||
return MaxRelevance - 2
|
||||
relevance = MaxRelevance - 2
|
||||
default:
|
||||
return MaxRelevance - 1 // main module ties with stdlib
|
||||
relevance = MaxRelevance - 1 // main module ties with stdlib
|
||||
}
|
||||
|
||||
_, versionString, ok := module.SplitPathVersion(mod.Path)
|
||||
if ok {
|
||||
index := strings.Index(versionString, "v")
|
||||
if index == -1 {
|
||||
return relevance
|
||||
}
|
||||
if versionNumber, err := strconv.ParseFloat(versionString[index+1:], 64); err == nil {
|
||||
relevance += versionNumber / 1000
|
||||
}
|
||||
}
|
||||
|
||||
return relevance
|
||||
}
|
||||
|
||||
// canonicalize gets the result of canonicalizing the packages using the results
|
||||
|
3
vendor/golang.org/x/tools/internal/packagesinternal/packages.go
generated
vendored
3
vendor/golang.org/x/tools/internal/packagesinternal/packages.go
generated
vendored
@@ -12,3 +12,6 @@ var GetGoCmdRunner = func(config interface{}) *gocommand.Runner { return nil }
|
||||
var SetGoCmdRunner = func(config interface{}, runner *gocommand.Runner) {}
|
||||
|
||||
var TypecheckCgo int
|
||||
|
||||
var SetModFlag = func(config interface{}, value string) {}
|
||||
var SetModFile = func(config interface{}, value string) {}
|
||||
|
Reference in New Issue
Block a user