Skip to content

Commit e58aed7

Browse files
authored
Cache declaration diagnostics (#1058)
1 parent c830924 commit e58aed7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

internal/compiler/program.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/microsoft/typescript-go/internal/ast"
1010
"github.com/microsoft/typescript-go/internal/binder"
1111
"github.com/microsoft/typescript-go/internal/checker"
12+
"github.com/microsoft/typescript-go/internal/collections"
1213
"github.com/microsoft/typescript-go/internal/core"
1314
"github.com/microsoft/typescript-go/internal/diagnostics"
1415
"github.com/microsoft/typescript-go/internal/module"
@@ -64,6 +65,8 @@ type Program struct {
6465

6566
// List of present unsupported extensions
6667
unsupportedExtensions []string
68+
69+
declarationDiagnosticCache collections.SyncMap[*ast.SourceFile, []*ast.Diagnostic]
6770
}
6871

6972
// FileExists implements checker.Program.
@@ -514,8 +517,15 @@ func (p *Program) getDeclarationDiagnosticsForFile(_ctx context.Context, sourceF
514517
if sourceFile.IsDeclarationFile {
515518
return []*ast.Diagnostic{}
516519
}
520+
521+
if cached, ok := p.declarationDiagnosticCache.Load(sourceFile); ok {
522+
return cached
523+
}
524+
517525
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
519529
}
520530

521531
func (p *Program) getSuggestionDiagnosticsForFile(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic {

0 commit comments

Comments
 (0)