collectDiagnostics collects diagnostics from a single file or all files. If sourceFile is non-nil, returns diagnostics for just that file. If sourceFile is nil, returns diagnostics for all files in the program.
(ctx context.Context, sourceFile *ast.SourceFile, concurrent bool, collect func(context.Context, *ast.SourceFile) []*ast.Diagnostic)
| 537 | // If sourceFile is non-nil, returns diagnostics for just that file. |
| 538 | // If sourceFile is nil, returns diagnostics for all files in the program. |
| 539 | func (p *Program) collectDiagnostics(ctx context.Context, sourceFile *ast.SourceFile, concurrent bool, collect func(context.Context, *ast.SourceFile) []*ast.Diagnostic) []*ast.Diagnostic { |
| 540 | var result []*ast.Diagnostic |
| 541 | if sourceFile != nil { |
| 542 | result = collect(ctx, sourceFile) |
| 543 | } else { |
| 544 | diagnostics := p.collectDiagnosticsFromFiles(ctx, p.files, concurrent, collect) |
| 545 | result = slices.Concat(diagnostics...) |
| 546 | } |
| 547 | return SortAndDeduplicateDiagnostics(result) |
| 548 | } |
| 549 | |
| 550 | func (p *Program) collectDiagnosticsFromFiles(ctx context.Context, sourceFiles []*ast.SourceFile, concurrent bool, collect func(context.Context, *ast.SourceFile) []*ast.Diagnostic) [][]*ast.Diagnostic { |
| 551 | diagnostics := make([][]*ast.Diagnostic, len(sourceFiles)) |
no test coverage detected