summaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/tools
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/tools')
-rw-r--r--vendor/golang.org/x/tools/go/packages/golist.go18
-rw-r--r--vendor/golang.org/x/tools/go/packages/golist_overlay.go2
-rw-r--r--vendor/golang.org/x/tools/internal/modindex/lookup.go16
-rw-r--r--vendor/golang.org/x/tools/internal/packagesinternal/packages.go6
4 files changed, 28 insertions, 14 deletions
diff --git a/vendor/golang.org/x/tools/go/packages/golist.go b/vendor/golang.org/x/tools/go/packages/golist.go
index 96e43cd80..89f89dd2d 100644
--- a/vendor/golang.org/x/tools/go/packages/golist.go
+++ b/vendor/golang.org/x/tools/go/packages/golist.go
@@ -224,13 +224,22 @@ extractQueries:
return response.dr, nil
}
+// abs returns an absolute representation of path, based on cfg.Dir.
+func (cfg *Config) abs(path string) (string, error) {
+ if filepath.IsAbs(path) {
+ return path, nil
+ }
+ // In case cfg.Dir is relative, pass it to filepath.Abs.
+ return filepath.Abs(filepath.Join(cfg.Dir, path))
+}
+
func (state *golistState) runContainsQueries(response *responseDeduper, queries []string) error {
for _, query := range queries {
// TODO(matloob): Do only one query per directory.
fdir := filepath.Dir(query)
// Pass absolute path of directory to go list so that it knows to treat it as a directory,
// not a package path.
- pattern, err := filepath.Abs(fdir)
+ pattern, err := state.cfg.abs(fdir)
if err != nil {
return fmt.Errorf("could not determine absolute path of file= query path %q: %v", query, err)
}
@@ -703,9 +712,8 @@ func (state *golistState) getGoVersion() (int, error) {
// getPkgPath finds the package path of a directory if it's relative to a root
// directory.
func (state *golistState) getPkgPath(dir string) (string, bool, error) {
- absDir, err := filepath.Abs(dir)
- if err != nil {
- return "", false, err
+ if !filepath.IsAbs(dir) {
+ panic("non-absolute dir passed to getPkgPath")
}
roots, err := state.determineRootDirs()
if err != nil {
@@ -715,7 +723,7 @@ func (state *golistState) getPkgPath(dir string) (string, bool, error) {
for rdir, rpath := range roots {
// Make sure that the directory is in the module,
// to avoid creating a path relative to another module.
- if !strings.HasPrefix(absDir, rdir) {
+ if !strings.HasPrefix(dir, rdir) {
continue
}
// TODO(matloob): This doesn't properly handle symlinks.
diff --git a/vendor/golang.org/x/tools/go/packages/golist_overlay.go b/vendor/golang.org/x/tools/go/packages/golist_overlay.go
index d823c474a..d9d5a45cd 100644
--- a/vendor/golang.org/x/tools/go/packages/golist_overlay.go
+++ b/vendor/golang.org/x/tools/go/packages/golist_overlay.go
@@ -55,7 +55,7 @@ func (state *golistState) determineRootDirsModules() (map[string]string, error)
}
if mod.Dir != "" && mod.Path != "" {
// This is a valid module; add it to the map.
- absDir, err := filepath.Abs(mod.Dir)
+ absDir, err := state.cfg.abs(mod.Dir)
if err != nil {
return nil, err
}
diff --git a/vendor/golang.org/x/tools/internal/modindex/lookup.go b/vendor/golang.org/x/tools/internal/modindex/lookup.go
index 34e3673ff..0c011a99b 100644
--- a/vendor/golang.org/x/tools/internal/modindex/lookup.go
+++ b/vendor/golang.org/x/tools/internal/modindex/lookup.go
@@ -36,13 +36,13 @@ const (
)
// LookupAll only returns those Candidates whose import path
-// finds all the nms.
-func (ix *Index) LookupAll(pkg string, names ...string) map[string][]Candidate {
+// finds all the names.
+func (ix *Index) LookupAll(pkgName string, names ...string) map[string][]Candidate {
// this can be made faster when benchmarks show that it needs to be
names = uniquify(names)
byImpPath := make(map[string][]Candidate)
for _, nm := range names {
- cands := ix.Lookup(pkg, nm, false)
+ cands := ix.Lookup(pkgName, nm, false)
for _, c := range cands {
byImpPath[c.ImportPath] = append(byImpPath[c.ImportPath], c)
}
@@ -67,9 +67,9 @@ func uniquify(in []string) []string {
// Lookup finds all the symbols in the index with the given PkgName and name.
// If prefix is true, it finds all of these with name as a prefix.
-func (ix *Index) Lookup(pkg, name string, prefix bool) []Candidate {
- loc, ok := slices.BinarySearchFunc(ix.Entries, pkg, func(e Entry, pkg string) int {
- return strings.Compare(e.PkgName, pkg)
+func (ix *Index) Lookup(pkgName, name string, prefix bool) []Candidate {
+ loc, ok := slices.BinarySearchFunc(ix.Entries, pkgName, func(e Entry, pkg string) int {
+ return strings.Compare(e.PkgName, pkgName)
})
if !ok {
return nil // didn't find the package
@@ -78,7 +78,7 @@ func (ix *Index) Lookup(pkg, name string, prefix bool) []Candidate {
// loc is the first entry for this package name, but there may be several
for i := loc; i < len(ix.Entries); i++ {
e := ix.Entries[i]
- if e.PkgName != pkg {
+ if e.PkgName != pkgName {
break // end of sorted package names
}
nloc, ok := slices.BinarySearchFunc(e.Names, name, func(s string, name string) int {
@@ -105,7 +105,7 @@ func (ix *Index) Lookup(pkg, name string, prefix bool) []Candidate {
continue // should never happen
}
px := Candidate{
- PkgName: pkg,
+ PkgName: pkgName,
Name: flds[0],
Dir: string(e.Dir),
ImportPath: e.ImportPath,
diff --git a/vendor/golang.org/x/tools/internal/packagesinternal/packages.go b/vendor/golang.org/x/tools/internal/packagesinternal/packages.go
index 73eefa2a7..929b470be 100644
--- a/vendor/golang.org/x/tools/internal/packagesinternal/packages.go
+++ b/vendor/golang.org/x/tools/internal/packagesinternal/packages.go
@@ -5,6 +5,8 @@
// Package packagesinternal exposes internal-only fields from go/packages.
package packagesinternal
+import "fmt"
+
var GetDepsErrors = func(p any) []*PackageError { return nil }
type PackageError struct {
@@ -13,5 +15,9 @@ type PackageError struct {
Err string // the error itself
}
+func (err PackageError) String() string {
+ return fmt.Sprintf("%s: %s (import stack: %s)", err.Pos, err.Err, err.ImportStack)
+}
+
var TypecheckCgo int
var DepsErrors int // must be set as a LoadMode to call GetDepsErrors