|
16 | 16 |
|
17 | 17 | import { CancellationToken } from 'vscode-languageserver'; |
18 | 18 |
|
19 | | -import { OperationCanceledException, throwIfCancellationRequested } from '../common/cancellationUtils'; |
| 19 | +import { invalidateTypeCacheIfCanceled, throwIfCancellationRequested } from '../common/cancellationUtils'; |
20 | 20 | import { appendArray } from '../common/collectionUtils'; |
21 | 21 | import { DiagnosticLevel } from '../common/configOptions'; |
22 | 22 | import { ConsoleInterface } from '../common/console'; |
@@ -14330,7 +14330,7 @@ export function createTypeEvaluator( |
14330 | 14330 | let functionType = FunctionType.createInstance('', '', '', FunctionTypeFlags.PartiallyEvaluated); |
14331 | 14331 | functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node); |
14332 | 14332 |
|
14333 | | - try { |
| 14333 | + return invalidateTypeCacheIfCanceled(() => { |
14334 | 14334 | // Pre-cache the incomplete function type in case the evaluation of the |
14335 | 14335 | // lambda depends on itself. |
14336 | 14336 | writeTypeCache(node, { type: functionType, isIncomplete: true }, EvaluatorFlags.None); |
@@ -14494,15 +14494,7 @@ export function createTypeEvaluator( |
14494 | 14494 | } |
14495 | 14495 |
|
14496 | 14496 | return { type: functionType, isIncomplete, typeErrors }; |
14497 | | - } catch (e) { |
14498 | | - if (OperationCanceledException.is(e)) { |
14499 | | - // If the work was canceled before the function type was updated, the |
14500 | | - // function type in the type cache is in an invalid, partially-constructed state. |
14501 | | - e.isTypeCacheInvalid = true; |
14502 | | - } |
14503 | | - |
14504 | | - throw e; |
14505 | | - } |
| 14497 | + }); |
14506 | 14498 | } |
14507 | 14499 |
|
14508 | 14500 | function getTypeOfComprehension( |
@@ -16523,7 +16515,7 @@ export function createTypeEvaluator( |
16523 | 16515 | classType.details.flags |= ClassTypeFlags.PartiallyEvaluated; |
16524 | 16516 | classType.details.declaration = classDecl; |
16525 | 16517 |
|
16526 | | - try { |
| 16518 | + return invalidateTypeCacheIfCanceled(() => { |
16527 | 16519 | writeTypeCache(node, { type: classType }, /* flags */ undefined); |
16528 | 16520 | writeTypeCache(node.name, { type: classType }, /* flags */ undefined); |
16529 | 16521 |
|
@@ -17225,15 +17217,7 @@ export function createTypeEvaluator( |
17225 | 17217 | writeTypeCache(node, { type: decoratedType }, EvaluatorFlags.None); |
17226 | 17218 |
|
17227 | 17219 | return { classType, decoratedType }; |
17228 | | - } catch (e) { |
17229 | | - if (OperationCanceledException.is(e)) { |
17230 | | - // If the work was canceled before the class types were updated, the |
17231 | | - // class type in the type cache is in an invalid, partially-constructed state. |
17232 | | - e.isTypeCacheInvalid = true; |
17233 | | - } |
17234 | | - |
17235 | | - throw e; |
17236 | | - } |
| 17220 | + }); |
17237 | 17221 | } |
17238 | 17222 |
|
17239 | 17223 | // Determines whether the type parameters has a default that refers to another |
@@ -17888,7 +17872,7 @@ export function createTypeEvaluator( |
17888 | 17872 | setSymbolResolutionPartialType(functionSymbol.symbol, functionDecl, functionType); |
17889 | 17873 | } |
17890 | 17874 |
|
17891 | | - try { |
| 17875 | + return invalidateTypeCacheIfCanceled(() => { |
17892 | 17876 | writeTypeCache(node.name, { type: functionType }, /* flags */ undefined); |
17893 | 17877 |
|
17894 | 17878 | // Is this an "__init__" method within a pseudo-generic class? If so, |
@@ -18275,15 +18259,7 @@ export function createTypeEvaluator( |
18275 | 18259 | writeTypeCache(node.name, { type: functionType }, EvaluatorFlags.None); |
18276 | 18260 |
|
18277 | 18261 | return functionType; |
18278 | | - } catch (e) { |
18279 | | - if (OperationCanceledException.is(e)) { |
18280 | | - // If the work was canceled before the function type was updated, the |
18281 | | - // function type in the type cache is in an invalid, partially-constructed state. |
18282 | | - e.isTypeCacheInvalid = true; |
18283 | | - } |
18284 | | - |
18285 | | - throw e; |
18286 | | - } |
| 18262 | + }); |
18287 | 18263 | } |
18288 | 18264 |
|
18289 | 18265 | function markParamAccessed(param: ParameterNode) { |
|
0 commit comments