MCPcopy
hub / github.com/golang/tools / Load

Function Load

go/packages/packages.go:261–290  ·  view source on GitHub ↗

Load loads and returns the Go packages named by the given patterns. The cfg parameter specifies loading options; nil behaves the same as an empty [Config]. The [Config.Mode] field is a set of bits that determine what kinds of information should be computed and returned. Modes that require more inf

(cfg *Config, patterns ...string)

Source from the content-addressed store, hash-verified

259// proceeding with further analysis. The [PrintErrors] function is
260// provided for convenient display of all errors.
261func Load(cfg *Config, patterns ...string) ([]*Package, error) {
262 ld := newLoader(cfg)
263 response, external, err := defaultDriver(&ld.Config, patterns...)
264 if err != nil {
265 return nil, err
266 }
267
268 ld.sizes = types.SizesFor(response.Compiler, response.Arch)
269 if ld.sizes == nil && ld.Config.Mode&(NeedTypes|NeedTypesSizes|NeedTypesInfo) != 0 {
270 // Type size information is needed but unavailable.
271 if external {
272 // An external driver may fail to populate the Compiler/GOARCH fields,
273 // especially since they are relatively new (see #63700).
274 // Provide a sensible fallback in this case.
275 ld.sizes = types.SizesFor("gc", runtime.GOARCH)
276 if ld.sizes == nil { // gccgo-only arch
277 ld.sizes = types.SizesFor("gc", "amd64")
278 }
279 } else {
280 // Go list should never fail to deliver accurate size information.
281 // Reject the whole Load since the error is the same for every package.
282 return nil, fmt.Errorf("can't determine type sizes for compiler %q on GOARCH %q",
283 response.Compiler, response.Arch)
284 }
285 }
286
287 ld.externalDriver = external
288
289 return ld.refine(response)
290}
291
292// defaultDriver is a driver that implements go/packages' fallback behavior.
293// It will try to request to an external driver, if one exists. If there's

Callers 15

TestMatchingPortsStdlibFunction · 0.92
loadMethod · 0.92
loadPackagesFunction · 0.92
LoadFunction · 0.92
TestTemplatesFunction · 0.92
collectIdentifiersFunction · 0.92
loadAPIFunction · 0.92
TestFunction · 0.92

Calls 4

newLoaderFunction · 0.85
defaultDriverFunction · 0.85
refineMethod · 0.80
ErrorfMethod · 0.65

Tested by 15

TestMatchingPortsStdlibFunction · 0.74
loadPackagesFunction · 0.74
TestTemplatesFunction · 0.74
collectIdentifiersFunction · 0.74
TestFunction · 0.74
testOverlayXTestsFunction · 0.74
testOverlayFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…