parseGoImpl parses the Go source file whose content is provided by fh.
(ctx context.Context, fset *token.FileSet, fh file.Handle, mode parser.Mode, purgeFuncBodies bool)
| 28 | |
| 29 | // parseGoImpl parses the Go source file whose content is provided by fh. |
| 30 | func parseGoImpl(ctx context.Context, fset *token.FileSet, fh file.Handle, mode parser.Mode, purgeFuncBodies bool) (*parsego.File, error) { |
| 31 | ext := filepath.Ext(fh.URI().Path()) |
| 32 | if ext != ".go" && ext != "" { // files generated by cgo have no extension |
| 33 | return nil, fmt.Errorf("cannot parse non-Go file %s", fh.URI()) |
| 34 | } |
| 35 | content, err := fh.Content() |
| 36 | if err != nil { |
| 37 | return nil, err |
| 38 | } |
| 39 | // Check for context cancellation before actually doing the parse. |
| 40 | if ctx.Err() != nil { |
| 41 | return nil, ctx.Err() |
| 42 | } |
| 43 | pgf, _ := parsego.Parse(ctx, fset, fh.URI(), content, mode, purgeFuncBodies) // ignore 'fixes' |
| 44 | return pgf, nil |
| 45 | } |