File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,17 @@ namespace ts {
22
22
}
23
23
24
24
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
+
25
36
let Symbol = objectAllocator.getSymbolConstructor();
26
37
let Type = objectAllocator.getTypeConstructor();
27
38
let Signature = objectAllocator.getSignatureConstructor();
@@ -13321,7 +13332,6 @@ namespace ts {
13321
13332
}
13322
13333
}
13323
13334
13324
- var cancellationToken: CancellationToken;
13325
13335
function getDiagnostics(sourceFile: SourceFile, ct: CancellationToken): Diagnostic[] {
13326
13336
try {
13327
13337
// Record the cancellation token so it can be checked later on during checkSourceElement.
Original file line number Diff line number Diff line change @@ -313,6 +313,13 @@ namespace ts {
313
313
if ( e instanceof OperationCanceledException ) {
314
314
// We were canceled while performing the operation. Because our type checker
315
315
// 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.
316
323
noDiagnosticsTypeChecker = undefined ;
317
324
diagnosticsProducingTypeChecker = undefined ;
318
325
}
You can’t perform that action at this time.
0 commit comments