From b1af8fd87760b34e3ff2fd3bda38f211815a0473 Mon Sep 17 00:00:00 2001 From: Terin Stock Date: Sun, 9 Mar 2025 17:47:56 +0100 Subject: [chore] remove vendor --- .../x/tools/internal/modindex/directories.go | 131 ---------- .../golang.org/x/tools/internal/modindex/index.go | 287 --------------------- .../golang.org/x/tools/internal/modindex/lookup.go | 178 ------------- .../x/tools/internal/modindex/modindex.go | 119 --------- .../x/tools/internal/modindex/symbols.go | 244 ------------------ 5 files changed, 959 deletions(-) delete mode 100644 vendor/golang.org/x/tools/internal/modindex/directories.go delete mode 100644 vendor/golang.org/x/tools/internal/modindex/index.go delete mode 100644 vendor/golang.org/x/tools/internal/modindex/lookup.go delete mode 100644 vendor/golang.org/x/tools/internal/modindex/modindex.go delete mode 100644 vendor/golang.org/x/tools/internal/modindex/symbols.go (limited to 'vendor/golang.org/x/tools/internal/modindex') diff --git a/vendor/golang.org/x/tools/internal/modindex/directories.go b/vendor/golang.org/x/tools/internal/modindex/directories.go deleted file mode 100644 index 9a963744b..000000000 --- a/vendor/golang.org/x/tools/internal/modindex/directories.go +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2024 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 modindex - -import ( - "fmt" - "log" - "os" - "path/filepath" - "regexp" - "strings" - "sync" - "time" - - "golang.org/x/mod/semver" - "golang.org/x/tools/internal/gopathwalk" -) - -type directory struct { - path string // relative to GOMODCACHE - importPath string - version string // semantic version -} - -// bestDirByImportPath returns the best directory for each import -// path, where "best" means most recent semantic version. These import -// paths are inferred from the GOMODCACHE-relative dir names in dirs. -func bestDirByImportPath(dirs []string) (map[string]directory, error) { - dirsByPath := make(map[string]directory) - for _, dir := range dirs { - importPath, version, err := dirToImportPathVersion(dir) - if err != nil { - return nil, err - } - new := directory{ - path: dir, - importPath: importPath, - version: version, - } - if old, ok := dirsByPath[importPath]; !ok || compareDirectory(new, old) < 0 { - dirsByPath[importPath] = new - } - } - return dirsByPath, nil -} - -// compareDirectory defines an ordering of path@version directories, -// by descending version, then by ascending path. -func compareDirectory(x, y directory) int { - if sign := -semver.Compare(x.version, y.version); sign != 0 { - return sign // latest first - } - return strings.Compare(string(x.path), string(y.path)) -} - -// modCacheRegexp splits a relpathpath into module, module version, and package. -var modCacheRegexp = regexp.MustCompile(`(.*)@([^/\\]*)(.*)`) - -// dirToImportPathVersion computes import path and semantic version -// from a GOMODCACHE-relative directory name. -func dirToImportPathVersion(dir string) (string, string, error) { - m := modCacheRegexp.FindStringSubmatch(string(dir)) - // m[1] is the module path - // m[2] is the version major.minor.patch(-
 1 && flds[1][1] == 'D',
-			}
-			if px.Type == Func {
-				n, err := strconv.Atoi(flds[2])
-				if err != nil {
-					continue // should never happen
-				}
-				px.Results = int16(n)
-				if len(flds) >= 4 {
-					sig := strings.Split(flds[3], " ")
-					for i := range sig {
-						// $ cannot otherwise occur. removing the spaces
-						// almost works, but for chan struct{}, e.g.
-						sig[i] = strings.Replace(sig[i], "$", " ", -1)
-					}
-					px.Sig = toFields(sig)
-				}
-			}
-			ans = append(ans, px)
-		}
-	}
-	return ans
-}
-
-func toFields(sig []string) []Field {
-	ans := make([]Field, len(sig)/2)
-	for i := range ans {
-		ans[i] = Field{Arg: sig[2*i], Type: sig[2*i+1]}
-	}
-	return ans
-}
-
-// benchmarks show this is measurably better than strings.Split
-// split into first 4 fields separated by single space
-func fastSplit(x string) []string {
-	ans := make([]string, 0, 4)
-	nxt := 0
-	start := 0
-	for i := 0; i < len(x); i++ {
-		if x[i] != ' ' {
-			continue
-		}
-		ans = append(ans, x[start:i])
-		nxt++
-		start = i + 1
-		if nxt >= 3 {
-			break
-		}
-	}
-	ans = append(ans, x[start:])
-	return ans
-}
-
-func asLexType(c byte) LexType {
-	switch c {
-	case 'C':
-		return Const
-	case 'V':
-		return Var
-	case 'T':
-		return Type
-	case 'F':
-		return Func
-	}
-	return -1
-}
diff --git a/vendor/golang.org/x/tools/internal/modindex/modindex.go b/vendor/golang.org/x/tools/internal/modindex/modindex.go
deleted file mode 100644
index 5fa285d98..000000000
--- a/vendor/golang.org/x/tools/internal/modindex/modindex.go
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2024 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 modindex contains code for building and searching an
-// [Index] of the Go module cache.
-package modindex
-
-// The directory containing the index, returned by
-// [IndexDir], contains a file index-name- that contains the name
-// of the current index. We believe writing that short file is atomic.
-// [Read] reads that file to get the file name of the index.
-// WriteIndex writes an index with a unique name and then
-// writes that name into a new version of index-name-.
-// ( stands for the CurrentVersion of the index format.)
-
-import (
-	"maps"
-	"os"
-	"path/filepath"
-	"slices"
-	"strings"
-	"time"
-
-	"golang.org/x/mod/semver"
-)
-
-// Update updates the index for the specified Go
-// module cache directory, creating it as needed.
-// On success it returns the current index.
-func Update(gomodcache string) (*Index, error) {
-	prev, err := Read(gomodcache)
-	if err != nil {
-		if !os.IsNotExist(err) {
-			return nil, err
-		}
-		prev = nil
-	}
-	return update(gomodcache, prev)
-}
-
-// update builds, writes, and returns the current index.
-//
-// If old is nil, the new index is built from all of GOMODCACHE;
-// otherwise it is built from the old index plus cache updates
-// since the previous index's time.
-func update(gomodcache string, old *Index) (*Index, error) {
-	gomodcache, err := filepath.Abs(gomodcache)
-	if err != nil {
-		return nil, err
-	}
-	new, changed, err := build(gomodcache, old)
-	if err != nil {
-		return nil, err
-	}
-	if old == nil || changed {
-		if err := write(gomodcache, new); err != nil {
-			return nil, err
-		}
-	}
-	return new, nil
-}
-
-// build returns a new index for the specified Go module cache (an
-// absolute path).
-//
-// If an old index is provided, only directories more recent than it
-// that it are scanned; older directories are provided by the old
-// Index.
-//
-// The boolean result indicates whether new entries were found.
-func build(gomodcache string, old *Index) (*Index, bool, error) {
-	// Set the time window.
-	var start time.Time // = dawn of time
-	if old != nil {
-		start = old.ValidAt
-	}
-	now := time.Now()
-	end := now.Add(24 * time.Hour) // safely in the future
-
-	// Enumerate GOMODCACHE package directories.
-	// Choose the best (latest) package for each import path.
-	pkgDirs := findDirs(gomodcache, start, end)
-	dirByPath, err := bestDirByImportPath(pkgDirs)
-	if err != nil {
-		return nil, false, err
-	}
-
-	// For each import path it might occur only in
-	// dirByPath, only in old, or in both.
-	// If both, use the semantically later one.
-	var entries []Entry
-	if old != nil {
-		for _, entry := range old.Entries {
-			dir, ok := dirByPath[entry.ImportPath]
-			if !ok || semver.Compare(dir.version, entry.Version) <= 0 {
-				// New dir is missing or not more recent; use old entry.
-				entries = append(entries, entry)
-				delete(dirByPath, entry.ImportPath)
-			}
-		}
-	}
-
-	// Extract symbol information for all the new directories.
-	newEntries := extractSymbols(gomodcache, maps.Values(dirByPath))
-	entries = append(entries, newEntries...)
-	slices.SortFunc(entries, func(x, y Entry) int {
-		if n := strings.Compare(x.PkgName, y.PkgName); n != 0 {
-			return n
-		}
-		return strings.Compare(x.ImportPath, y.ImportPath)
-	})
-
-	return &Index{
-		GOMODCACHE: gomodcache,
-		ValidAt:    now, // time before the directories were scanned
-		Entries:    entries,
-	}, len(newEntries) > 0, nil
-}
diff --git a/vendor/golang.org/x/tools/internal/modindex/symbols.go b/vendor/golang.org/x/tools/internal/modindex/symbols.go
deleted file mode 100644
index 8e9702d84..000000000
--- a/vendor/golang.org/x/tools/internal/modindex/symbols.go
+++ /dev/null
@@ -1,244 +0,0 @@
-// Copyright 2024 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 modindex
-
-import (
-	"fmt"
-	"go/ast"
-	"go/parser"
-	"go/token"
-	"go/types"
-	"iter"
-	"os"
-	"path/filepath"
-	"runtime"
-	"slices"
-	"strings"
-	"sync"
-
-	"golang.org/x/sync/errgroup"
-)
-
-// The name of a symbol contains information about the symbol:
-//  T for types, TD if the type is deprecated
-//  C for consts, CD if the const is deprecated
-//  V for vars, VD if the var is deprecated
-// and for funcs:  F  ( )*
-// any spaces in  are replaced by $s so that the fields
-// of the name are space separated. F is replaced by FD if the func
-// is deprecated.
-type symbol struct {
-	pkg  string // name of the symbols's package
-	name string // declared name
-	kind string // T, C, V, or F, followed by D if deprecated
-	sig  string // signature information, for F
-}
-
-// extractSymbols returns a (new, unordered) array of Entries, one for
-// each provided package directory, describing its exported symbols.
-func extractSymbols(cwd string, dirs iter.Seq[directory]) []Entry {
-	var (
-		mu      sync.Mutex
-		entries []Entry
-	)
-
-	var g errgroup.Group
-	g.SetLimit(max(2, runtime.GOMAXPROCS(0)/2))
-	for dir := range dirs {
-		g.Go(func() error {
-			thedir := filepath.Join(cwd, string(dir.path))
-			mode := parser.SkipObjectResolution | parser.ParseComments
-
-			// Parse all Go files in dir and extract symbols.
-			dirents, err := os.ReadDir(thedir)
-			if err != nil {
-				return nil // log this someday?
-			}
-			var syms []symbol
-			for _, dirent := range dirents {
-				if !strings.HasSuffix(dirent.Name(), ".go") ||
-					strings.HasSuffix(dirent.Name(), "_test.go") {
-					continue
-				}
-				fname := filepath.Join(thedir, dirent.Name())
-				tr, err := parser.ParseFile(token.NewFileSet(), fname, nil, mode)
-				if err != nil {
-					continue // ignore errors, someday log them?
-				}
-				syms = append(syms, getFileExports(tr)...)
-			}
-
-			// Create an entry for the package.
-			pkg, names := processSyms(syms)
-			if pkg != "" {
-				mu.Lock()
-				defer mu.Unlock()
-				entries = append(entries, Entry{
-					PkgName:    pkg,
-					Dir:        dir.path,
-					ImportPath: dir.importPath,
-					Version:    dir.version,
-					Names:      names,
-				})
-			}
-
-			return nil
-		})
-	}
-	g.Wait() // ignore error
-
-	return entries
-}
-
-func getFileExports(f *ast.File) []symbol {
-	pkg := f.Name.Name
-	if pkg == "main" || pkg == "" {
-		return nil
-	}
-	var ans []symbol
-	// should we look for //go:build ignore?
-	for _, decl := range f.Decls {
-		switch decl := decl.(type) {
-		case *ast.FuncDecl:
-			if decl.Recv != nil {
-				// ignore methods, as we are completing package selections
-				continue
-			}
-			name := decl.Name.Name
-			dtype := decl.Type
-			// not looking at dtype.TypeParams. That is, treating
-			// generic functions just like non-generic ones.
-			sig := dtype.Params
-			kind := "F"
-			if isDeprecated(decl.Doc) {
-				kind += "D"
-			}
-			result := []string{fmt.Sprintf("%d", dtype.Results.NumFields())}
-			for _, x := range sig.List {
-				// This code creates a string representing the type.
-				// TODO(pjw): it may be fragile:
-				// 1. x.Type could be nil, perhaps in ill-formed code
-				// 2. ExprString might someday change incompatibly to
-				//    include struct tags, which can be arbitrary strings
-				if x.Type == nil {
-					// Can this happen without a parse error? (Files with parse
-					// errors are ignored in getSymbols)
-					continue // maybe report this someday
-				}
-				tp := types.ExprString(x.Type)
-				if len(tp) == 0 {
-					// Can this happen?
-					continue // maybe report this someday
-				}
-				// This is only safe if ExprString never returns anything with a $
-				// The only place a $ can occur seems to be in a struct tag, which
-				// can be an arbitrary string literal, and ExprString does not presently
-				// print struct tags. So for this to happen the type of a formal parameter
-				// has to be a explicit struct, e.g. foo(x struct{a int "$"}) and ExprString
-				// would have to show the struct tag. Even testing for this case seems
-				// a waste of effort, but let's remember the possibility
-				if strings.Contains(tp, "$") {
-					continue
-				}
-				tp = strings.Replace(tp, " ", "$", -1)
-				if len(x.Names) == 0 {
-					result = append(result, "_")
-					result = append(result, tp)
-				} else {
-					for _, y := range x.Names {
-						result = append(result, y.Name)
-						result = append(result, tp)
-					}
-				}
-			}
-			sigs := strings.Join(result, " ")
-			if s := newsym(pkg, name, kind, sigs); s != nil {
-				ans = append(ans, *s)
-			}
-		case *ast.GenDecl:
-			depr := isDeprecated(decl.Doc)
-			switch decl.Tok {
-			case token.CONST, token.VAR:
-				tp := "V"
-				if decl.Tok == token.CONST {
-					tp = "C"
-				}
-				if depr {
-					tp += "D"
-				}
-				for _, sp := range decl.Specs {
-					for _, x := range sp.(*ast.ValueSpec).Names {
-						if s := newsym(pkg, x.Name, tp, ""); s != nil {
-							ans = append(ans, *s)
-						}
-					}
-				}
-			case token.TYPE:
-				tp := "T"
-				if depr {
-					tp += "D"
-				}
-				for _, sp := range decl.Specs {
-					if s := newsym(pkg, sp.(*ast.TypeSpec).Name.Name, tp, ""); s != nil {
-						ans = append(ans, *s)
-					}
-				}
-			}
-		}
-	}
-	return ans
-}
-
-func newsym(pkg, name, kind, sig string) *symbol {
-	if len(name) == 0 || !ast.IsExported(name) {
-		return nil
-	}
-	sym := symbol{pkg: pkg, name: name, kind: kind, sig: sig}
-	return &sym
-}
-
-func isDeprecated(doc *ast.CommentGroup) bool {
-	if doc == nil {
-		return false
-	}
-	// go.dev/wiki/Deprecated Paragraph starting 'Deprecated:'
-	// This code fails for /* Deprecated: */, but it's the code from
-	// gopls/internal/analysis/deprecated
-	for line := range strings.SplitSeq(doc.Text(), "\n\n") {
-		if strings.HasPrefix(line, "Deprecated:") {
-			return true
-		}
-	}
-	return false
-}
-
-// return the package name and the value for the symbols.
-// if there are multiple packages, choose one arbitrarily
-// the returned slice is sorted lexicographically
-func processSyms(syms []symbol) (string, []string) {
-	if len(syms) == 0 {
-		return "", nil
-	}
-	slices.SortFunc(syms, func(l, r symbol) int {
-		return strings.Compare(l.name, r.name)
-	})
-	pkg := syms[0].pkg
-	var names []string
-	for _, s := range syms {
-		if s.pkg != pkg {
-			// Symbols came from two files in same dir
-			// with different package declarations.
-			continue
-		}
-		var nx string
-		if s.sig != "" {
-			nx = fmt.Sprintf("%s %s %s", s.name, s.kind, s.sig)
-		} else {
-			nx = fmt.Sprintf("%s %s", s.name, s.kind)
-		}
-		names = append(names, nx)
-	}
-	return pkg, names
-}
-- 
cgit v1.2.3