|
9 | 9 | "github.com/microsoft/typescript-go/internal/ast"
|
10 | 10 | "github.com/microsoft/typescript-go/internal/binder"
|
11 | 11 | "github.com/microsoft/typescript-go/internal/checker"
|
| 12 | + "github.com/microsoft/typescript-go/internal/collections" |
12 | 13 | "github.com/microsoft/typescript-go/internal/core"
|
13 | 14 | "github.com/microsoft/typescript-go/internal/diagnostics"
|
14 | 15 | "github.com/microsoft/typescript-go/internal/module"
|
@@ -64,6 +65,8 @@ type Program struct {
|
64 | 65 |
|
65 | 66 | // List of present unsupported extensions
|
66 | 67 | unsupportedExtensions []string
|
| 68 | + |
| 69 | + declarationDiagnosticCache collections.SyncMap[*ast.SourceFile, []*ast.Diagnostic] |
67 | 70 | }
|
68 | 71 |
|
69 | 72 | // FileExists implements checker.Program.
|
@@ -514,8 +517,15 @@ func (p *Program) getDeclarationDiagnosticsForFile(_ctx context.Context, sourceF
|
514 | 517 | if sourceFile.IsDeclarationFile {
|
515 | 518 | return []*ast.Diagnostic{}
|
516 | 519 | }
|
| 520 | + |
| 521 | + if cached, ok := p.declarationDiagnosticCache.Load(sourceFile); ok { |
| 522 | + return cached |
| 523 | + } |
| 524 | + |
517 | 525 | host := &emitHost{program: p}
|
518 |
| - return getDeclarationDiagnostics(host, host.GetEmitResolver(sourceFile, true), sourceFile) |
| 526 | + diagnostics := getDeclarationDiagnostics(host, host.GetEmitResolver(sourceFile, true), sourceFile) |
| 527 | + diagnostics, _ = p.declarationDiagnosticCache.LoadOrStore(sourceFile, diagnostics) |
| 528 | + return diagnostics |
519 | 529 | }
|
520 | 530 |
|
521 | 531 | func (p *Program) getSuggestionDiagnosticsForFile(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic {
|
|
0 commit comments