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

Method parseFiles

gopls/internal/cache/parse_cache.go:319–389  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
319func (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)

Callers 13

parseImportsFunction · 0.45
SymbolsMethod · 0.45
typerefDataMethod · 0.45
checkPackageMethod · 0.45
metadataChangesFunction · 0.45
BuiltinFileMethod · 0.45
TestParseCacheFunction · 0.45
TestParseCache_ReparsingFunction · 0.45

Calls 10

startParseMethod · 0.95
GoMethod · 0.95
parseGoImplFunction · 0.85
appendFunction · 0.85
BaseMethod · 0.80
GetMethod · 0.65
PosMethod · 0.65
WaitMethod · 0.45
FileMethod · 0.45
SizeMethod · 0.45

Tested by 5

TestParseCacheFunction · 0.36
TestParseCache_ReparsingFunction · 0.36