Skip to content

Commit

Permalink
Clear ExportMapCache on cancellation requested
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed May 5, 2022
1 parent c8ec855 commit b999eab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/services/exportInfoMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,12 @@ namespace ts {
const compilerOptions = program.getCompilerOptions();
let moduleCount = 0;
forEachExternalModuleToImportFrom(program, host, /*useAutoImportProvider*/ true, (moduleSymbol, moduleFile, program, isFromPackageJson) => {
if (++moduleCount % 100 === 0) cancellationToken?.throwIfCancellationRequested();
if (++moduleCount % 100 === 0) {
cancellationToken?.throwIfCancellationRequested(() => {
cache.clear();
});
}

const seenExports = new Map<__String, true>();
const checker = program.getTypeChecker();
const defaultInfo = getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
Expand Down
6 changes: 4 additions & 2 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1201,8 +1201,9 @@ namespace ts {
return this.cancellationToken.isCancellationRequested();
}

public throwIfCancellationRequested(): void {
public throwIfCancellationRequested(cleanup?: () => void): void {
if (this.isCancellationRequested()) {
cleanup?.();
tracing?.instant(tracing.Phase.Session, "cancellationThrown", { kind: "CancellationTokenObject" });
throw new OperationCanceledException();
}
Expand Down Expand Up @@ -1232,8 +1233,9 @@ namespace ts {
return false;
}

public throwIfCancellationRequested(): void {
public throwIfCancellationRequested(cleanup?: () => void): void {
if (this.isCancellationRequested()) {
cleanup?.();
tracing?.instant(tracing.Phase.Session, "cancellationThrown", { kind: "ThrottledCancellationToken" });
throw new OperationCanceledException();
}
Expand Down
4 changes: 4 additions & 0 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ namespace ts {
isCancellationRequested(): boolean;
}

export interface CancellationToken {
throwIfCancellationRequested(cleanup?: () => void): void;
}

export interface InstallPackageOptions {
fileName: Path;
packageName: string;
Expand Down

0 comments on commit b999eab

Please sign in to comment.