diff --git a/go/packages/example_test.go b/go/packages/example_test.go index ad1340f3..94cf8eb0 100644 --- a/go/packages/example_test.go +++ b/go/packages/example_test.go @@ -16,7 +16,7 @@ func Example() { // Many tools pass their command-line arguments (after any flags) // uninterpreted to packages.Load so that it can interpret them // 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()...) if err != nil { fmt.Fprintf(os.Stderr, "load: %v\n", err) diff --git a/go/packages/packages.go b/go/packages/packages.go index eedd43bb..9b2a1db1 100644 --- a/go/packages/packages.go +++ b/go/packages/packages.go @@ -25,24 +25,16 @@ import ( "golang.org/x/tools/go/gcexportdata" ) -// A LoadMode specifies the amount of detail to return when loading. -// Higher-numbered modes cause Load to return more information, -// but may be slower. Load may return more information than requested. +// A LoadMode controls the amount of detail to return when loading. +// The bits below can be combined to specify which fields should be +// 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 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 LoadMode = 1 << iota @@ -74,33 +66,25 @@ const ( // NeedTypesSizes adds TypesSizes. NeedTypesSizes -) -const ( - // LoadFiles finds the packages and computes their source file lists. - // Package fields: ID, Name, Errors, GoFiles, CompiledGoFiles, and OtherFiles. + // Deprecated: LoadFiles exists for historical compatibility + // and should not be used. Please directly specify the needed fields using the Need values. LoadFiles = NeedName | NeedFiles | NeedCompiledGoFiles - // LoadImports adds import information for each package - // and its dependencies. - // Package fields added: Imports. + // Deprecated: LoadImports exists for historical compatibility + // and should not be used. Please directly specify the needed fields using the Need values. LoadImports = LoadFiles | NeedImports | NeedDeps - // LoadTypes adds type information for package-level - // declarations in the packages matching the patterns. - // 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. + // Deprecated: LoadTypes exists for historical compatibility + // and should not be used. Please directly specify the needed fields using the Need values. LoadTypes = LoadImports | NeedTypes | NeedTypesSizes - // LoadSyntax adds typed syntax trees for the packages matching the patterns. - // Package fields added: Syntax, and TypesInfo, for direct pattern matches only. + // Deprecated: LoadSyntax exists for historical compatibility + // and should not be used. Please directly specify the needed fields using the Need values. LoadSyntax = LoadTypes | NeedSyntax | NeedTypesInfo - // LoadAllSyntax adds typed syntax trees for the packages matching the patterns - // and all dependencies. - // Package fields added: Types, Fset, IllTyped, Syntax, and TypesInfo, - // for all packages in the import graph. + // Deprecated: LoadAllSyntax exists for historical compatibility + // and should not be used. Please directly specify the needed fields using the Need values. LoadAllSyntax = LoadSyntax )