parseFiles returns a parsego.File for each file handle in fhs, in the requested parse mode. For parsed files that already exists in the cache, access time will be updated. For others, parseFiles will parse and store as many results in the cache as space allows. The token.File for each resulting pa
(ctx context.Context, fset *token.FileSet, mode parser.Mode, purgeFuncBodies bool, fhs ...file.Handle)
| 317 | // If parseFiles returns an error, it still returns a slice, |
| 318 | // but with a nil entry for each file that could not be parsed. |
| 319 | func (c *parseCache) parseFiles(ctx context.Context, fset *token.FileSet, mode parser.Mode, purgeFuncBodies bool, fhs ...file.Handle) ([]*parsego.File, error) { |
| 320 | pgfs := make([]*parsego.File, len(fhs)) |
| 321 | |
| 322 | // Temporary fall-back for 32-bit systems, where reservedForParsing is too |
| 323 | // small to be viable. We don't actually support 32-bit systems, so this |
| 324 | // workaround is only for tests and can be removed when we stop running |
| 325 | // 32-bit TryBots for gopls. |
| 326 | if bits.UintSize == 32 { |
| 327 | for i, fh := range fhs { |
| 328 | var err error |
| 329 | pgfs[i], err = parseGoImpl(ctx, fset, fh, mode, purgeFuncBodies) |
| 330 | if err != nil { |
| 331 | return pgfs, err |
| 332 | } |
| 333 | } |
| 334 | return pgfs, nil |
| 335 | } |
| 336 | |
| 337 | promises, firstErr := c.startParse(mode, purgeFuncBodies, fhs...) |
| 338 | |
| 339 | // Await all parsing. |
| 340 | var g errgroup.Group |
| 341 | g.SetLimit(runtime.GOMAXPROCS(-1)) // parsing is CPU-bound. |
| 342 | for i, promise := range promises { |
| 343 | if promise == nil { |
| 344 | continue |
| 345 | } |
| 346 | i := i |
| 347 | promise := promise |
| 348 | g.Go(func() error { |
| 349 | result, err := promise.Get(ctx, nil) |
| 350 | if err != nil { |
| 351 | return err |
| 352 | } |
| 353 | pgfs[i] = result.(*parsego.File) |
| 354 | return nil |
| 355 | }) |
| 356 | } |
| 357 | |
| 358 | if err := g.Wait(); err != nil && firstErr == nil { |
| 359 | firstErr = err |
| 360 | } |
| 361 | |
| 362 | // Augment the FileSet to map all parsed files. |
| 363 | var tokenFiles []*token.File |
| 364 | for _, pgf := range pgfs { |
| 365 | if pgf == nil { |
| 366 | continue |
| 367 | } |
| 368 | tokenFiles = append(tokenFiles, pgf.Tok) |
| 369 | } |
| 370 | fset.AddExistingFiles(tokenFiles...) |
| 371 | |
| 372 | const debugIssue59080 = true |
| 373 | if debugIssue59080 { |
| 374 | for _, f := range tokenFiles { |
| 375 | pos := token.Pos(f.Base()) |
| 376 | f2 := fset.File(pos) |