Skip to content

Commit 3a26cd2

Browse files
Adding comments.
1 parent 1dfcc3e commit 3a26cd2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ namespace ts {
2222
}
2323

2424
export function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker {
25+
// Cancellation that controls whether or not we can cancel in the middle of type checking.
26+
// In general cancelling is *not* safe for the type checker. We might be in the middle of
27+
// computing something, and we will leave our internals in an inconsistent state. Callers
28+
// who set the cancellation token should catch if a cancellation exception occurs, and
29+
// should throw away and create a new TypeChecker.
30+
//
31+
// Currently we only support setting the cancellation token when getting diagnostics. This
32+
// is because diagnostics can be quite expensive, and we want to allow hosts to bail out if
33+
// they no longer need the information (for example, if the user started editing again).
34+
let cancellationToken: CancellationToken;
35+
2536
let Symbol = objectAllocator.getSymbolConstructor();
2637
let Type = objectAllocator.getTypeConstructor();
2738
let Signature = objectAllocator.getSignatureConstructor();
@@ -13321,7 +13332,6 @@ namespace ts {
1332113332
}
1332213333
}
1332313334

13324-
var cancellationToken: CancellationToken;
1332513335
function getDiagnostics(sourceFile: SourceFile, ct: CancellationToken): Diagnostic[] {
1332613336
try {
1332713337
// Record the cancellation token so it can be checked later on during checkSourceElement.

src/compiler/program.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ namespace ts {
313313
if (e instanceof OperationCanceledException) {
314314
// We were canceled while performing the operation. Because our type checker
315315
// might be a bad state, we need to throw it away.
316+
//
317+
// Note: we are overly agressive here. We do not actually *have* to throw away
318+
// the "noDiagnosticsTypeChecker". However, for simplicity, i'd like to keep
319+
// the lifetimes of these two TypeCheckers the same. Also, we generally only
320+
// cancel when the user has made a change anyways. And, in that case, we (the
321+
// program instance) will get thrown away anyways. So trying to keep one of
322+
// these type checkers alive doesn't serve much purpose.
316323
noDiagnosticsTypeChecker = undefined;
317324
diagnosticsProducingTypeChecker = undefined;
318325
}

0 commit comments

Comments
 (0)