go/packages: officially deprecate LoadX values in favor of NeedX values
Update doc to specify that users should request the fields needed in the Package struct by using the NeedX bits directly. Change-Id: I9213827fa7e5d01800d79173fe5161f39ffda85e Reviewed-on: https://go-review.googlesource.com/c/tools/+/173959 Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
aa71c3f324
commit
d5577298ec
|
@ -16,7 +16,7 @@ func Example() {
|
||||||
// Many tools pass their command-line arguments (after any flags)
|
// Many tools pass their command-line arguments (after any flags)
|
||||||
// uninterpreted to packages.Load so that it can interpret them
|
// uninterpreted to packages.Load so that it can interpret them
|
||||||
// according to the conventions of the underlying build system.
|
// according to the conventions of the underlying build system.
|
||||||
cfg := &packages.Config{Mode: packages.LoadSyntax}
|
cfg := &packages.Config{Mode: packages.NeedFiles | packages.NeedSyntax}
|
||||||
pkgs, err := packages.Load(cfg, flag.Args()...)
|
pkgs, err := packages.Load(cfg, flag.Args()...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "load: %v\n", err)
|
fmt.Fprintf(os.Stderr, "load: %v\n", err)
|
||||||
|
|
|
@ -25,24 +25,16 @@ import (
|
||||||
"golang.org/x/tools/go/gcexportdata"
|
"golang.org/x/tools/go/gcexportdata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A LoadMode specifies the amount of detail to return when loading.
|
// A LoadMode controls the amount of detail to return when loading.
|
||||||
// Higher-numbered modes cause Load to return more information,
|
// The bits below can be combined to specify which fields should be
|
||||||
// but may be slower. Load may return more information than requested.
|
// filled in the result packages.
|
||||||
|
// The zero value is a special case, equivalent to combining
|
||||||
|
// the NeedName, NeedFiles, and NeedCompiledGoFiles bits.
|
||||||
|
// ID and Errors (if present) will always be filled.
|
||||||
|
// Load may return more information than requested.
|
||||||
type LoadMode int
|
type LoadMode int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// The following constants are used to specify which fields of the Package
|
|
||||||
// should be filled when loading is done. As a special case to provide
|
|
||||||
// backwards compatibility, a LoadMode of 0 is equivalent to LoadFiles.
|
|
||||||
// For all other LoadModes, the bits below specify which fields will be filled
|
|
||||||
// in the result packages.
|
|
||||||
// WARNING: This part of the go/packages API is EXPERIMENTAL. It might
|
|
||||||
// be changed or removed up until April 15 2019. After that date it will
|
|
||||||
// be frozen.
|
|
||||||
// TODO(matloob): Remove this comment on April 15.
|
|
||||||
|
|
||||||
// ID and Errors (if present) will always be filled.
|
|
||||||
|
|
||||||
// NeedName adds Name and PkgPath.
|
// NeedName adds Name and PkgPath.
|
||||||
NeedName LoadMode = 1 << iota
|
NeedName LoadMode = 1 << iota
|
||||||
|
|
||||||
|
@ -74,33 +66,25 @@ const (
|
||||||
|
|
||||||
// NeedTypesSizes adds TypesSizes.
|
// NeedTypesSizes adds TypesSizes.
|
||||||
NeedTypesSizes
|
NeedTypesSizes
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
// Deprecated: LoadFiles exists for historical compatibility
|
||||||
// LoadFiles finds the packages and computes their source file lists.
|
// and should not be used. Please directly specify the needed fields using the Need values.
|
||||||
// Package fields: ID, Name, Errors, GoFiles, CompiledGoFiles, and OtherFiles.
|
|
||||||
LoadFiles = NeedName | NeedFiles | NeedCompiledGoFiles
|
LoadFiles = NeedName | NeedFiles | NeedCompiledGoFiles
|
||||||
|
|
||||||
// LoadImports adds import information for each package
|
// Deprecated: LoadImports exists for historical compatibility
|
||||||
// and its dependencies.
|
// and should not be used. Please directly specify the needed fields using the Need values.
|
||||||
// Package fields added: Imports.
|
|
||||||
LoadImports = LoadFiles | NeedImports | NeedDeps
|
LoadImports = LoadFiles | NeedImports | NeedDeps
|
||||||
|
|
||||||
// LoadTypes adds type information for package-level
|
// Deprecated: LoadTypes exists for historical compatibility
|
||||||
// declarations in the packages matching the patterns.
|
// and should not be used. Please directly specify the needed fields using the Need values.
|
||||||
// Package fields added: Types, TypesSizes, Fset, and IllTyped.
|
|
||||||
// This mode uses type information provided by the build system when
|
|
||||||
// possible, and may fill in the ExportFile field.
|
|
||||||
LoadTypes = LoadImports | NeedTypes | NeedTypesSizes
|
LoadTypes = LoadImports | NeedTypes | NeedTypesSizes
|
||||||
|
|
||||||
// LoadSyntax adds typed syntax trees for the packages matching the patterns.
|
// Deprecated: LoadSyntax exists for historical compatibility
|
||||||
// Package fields added: Syntax, and TypesInfo, for direct pattern matches only.
|
// and should not be used. Please directly specify the needed fields using the Need values.
|
||||||
LoadSyntax = LoadTypes | NeedSyntax | NeedTypesInfo
|
LoadSyntax = LoadTypes | NeedSyntax | NeedTypesInfo
|
||||||
|
|
||||||
// LoadAllSyntax adds typed syntax trees for the packages matching the patterns
|
// Deprecated: LoadAllSyntax exists for historical compatibility
|
||||||
// and all dependencies.
|
// and should not be used. Please directly specify the needed fields using the Need values.
|
||||||
// Package fields added: Types, Fset, IllTyped, Syntax, and TypesInfo,
|
|
||||||
// for all packages in the import graph.
|
|
||||||
LoadAllSyntax = LoadSyntax
|
LoadAllSyntax = LoadSyntax
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue