@@ -887,18 +887,28 @@ namespace ts {
887
887
return sourceFile . parseDiagnostics ;
888
888
}
889
889
890
- function onCancel ( ) {
891
- // Because our type checker might be a bad state, we need to throw it away.
892
- // Note: we are overly aggressive here. We do not actually *have* to throw away
893
- // the "noDiagnosticsTypeChecker". However, for simplicity, i'd like to keep
894
- // the lifetimes of these two TypeCheckers the same. Also, we generally only
895
- // cancel when the user has made a change anyways. And, in that case, we (the
896
- // program instance) will get thrown away anyways. So trying to keep one of
897
- // these type checkers alive doesn't serve much purpose.
898
- noDiagnosticsTypeChecker = undefined ;
899
- diagnosticsProducingTypeChecker = undefined ;
900
- }
890
+ function runWithCancellationToken < T > ( func : ( ) => T ) : T {
891
+ try {
892
+ return func ( ) ;
893
+ }
894
+ catch ( e ) {
895
+ if ( e instanceof OperationCanceledException ) {
896
+ // We were canceled while performing the operation. Because our type checker
897
+ // might be a bad state, we need to throw it away.
898
+ //
899
+ // Note: we are overly aggressive here. We do not actually *have* to throw away
900
+ // the "noDiagnosticsTypeChecker". However, for simplicity, i'd like to keep
901
+ // the lifetimes of these two TypeCheckers the same. Also, we generally only
902
+ // cancel when the user has made a change anyways. And, in that case, we (the
903
+ // program instance) will get thrown away anyways. So trying to keep one of
904
+ // these type checkers alive doesn't serve much purpose.
905
+ noDiagnosticsTypeChecker = undefined ;
906
+ diagnosticsProducingTypeChecker = undefined ;
907
+ }
901
908
909
+ throw e ;
910
+ }
911
+ }
902
912
903
913
function getSemanticDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
904
914
return runWithCancellationToken ( ( ) => {
@@ -914,7 +924,7 @@ namespace ts {
914
924
const programDiagnosticsInFile = programDiagnostics . getDiagnostics ( sourceFile . fileName ) ;
915
925
916
926
return bindDiagnostics . concat ( checkDiagnostics , fileProcessingDiagnosticsInFile , programDiagnosticsInFile ) ;
917
- } , onCancel ) ;
927
+ } ) ;
918
928
}
919
929
920
930
function getJavaScriptSyntacticDiagnosticsForFile ( sourceFile : SourceFile ) : Diagnostic [ ] {
@@ -1093,15 +1103,15 @@ namespace ts {
1093
1103
function createDiagnosticForNode ( node : Node , message : DiagnosticMessage , arg0 ?: string | number , arg1 ?: string | number , arg2 ?: string | number ) : Diagnostic {
1094
1104
return createDiagnosticForNodeInSourceFile ( sourceFile , node , message , arg0 , arg1 , arg2 ) ;
1095
1105
}
1096
- } , onCancel ) ;
1106
+ } ) ;
1097
1107
}
1098
1108
1099
1109
function getDeclarationDiagnosticsWorker ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
1100
1110
return runWithCancellationToken ( ( ) => {
1101
1111
const resolver = getDiagnosticsProducingTypeChecker ( ) . getEmitResolver ( sourceFile , cancellationToken ) ;
1102
1112
// Don't actually write any files since we're just getting diagnostics.
1103
1113
return ts . getDeclarationDiagnostics ( getEmitHost ( noop ) , resolver , sourceFile ) ;
1104
- } , onCancel ) ;
1114
+ } ) ;
1105
1115
}
1106
1116
1107
1117
function getDeclarationDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
0 commit comments