@@ -26,11 +26,17 @@ import { getControllerRepo } from './run-remote-query';
2626import { processUpdatedVariantAnalysis } from './variant-analysis-processor' ;
2727import PQueue from 'p-queue' ;
2828import { createTimestampFile } from '../helpers' ;
29+ import { QueryStatus } from '../query-status' ;
30+ import * as fs from 'fs-extra' ;
31+
2932
3033export class VariantAnalysisManager extends DisposableObject implements VariantAnalysisViewManager < VariantAnalysisView > {
3134 private readonly _onVariantAnalysisAdded = this . push ( new EventEmitter < VariantAnalysis > ( ) ) ;
3235 public readonly onVariantAnalysisAdded = this . _onVariantAnalysisAdded . event ;
3336
37+ private readonly _onVariantAnalysisRemoved = this . push ( new EventEmitter < VariantAnalysis > ( ) ) ;
38+ public readonly onVariantAnalysisRemoved = this . _onVariantAnalysisRemoved . event ;
39+
3440 private readonly variantAnalysisMonitor : VariantAnalysisMonitor ;
3541 private readonly variantAnalysisResultsManager : VariantAnalysisResultsManager ;
3642 private readonly variantAnalyses = new Map < number , VariantAnalysis > ( ) ;
@@ -52,6 +58,18 @@ export class VariantAnalysisManager extends DisposableObject implements VariantA
5258 this . variantAnalysisResultsManager . onResultLoaded ( this . onRepoResultLoaded . bind ( this ) ) ;
5359 }
5460
61+ public async rehydrateVariantAnalysis ( variantAnalysis : VariantAnalysis , status : QueryStatus ) {
62+ if ( ! ( await this . variantAnalysisRecordExists ( variantAnalysis . id ) ) ) {
63+ // In this case, the variant analysis was deleted from disk, most likely because
64+ // it was purged by another workspace.
65+ this . _onVariantAnalysisRemoved . fire ( variantAnalysis ) ;
66+ } else if ( status === QueryStatus . InProgress ) {
67+ // In this case, last time we checked, the query was still in progress.
68+ // We need to setup the monitor to check for completion.
69+ await commands . executeCommand ( 'codeQL.monitorVariantAnalysis' , variantAnalysis ) ;
70+ }
71+ }
72+
5573 public async showView ( variantAnalysisId : number ) : Promise < void > {
5674 if ( ! this . views . has ( variantAnalysisId ) ) {
5775 // The view will register itself with the manager, so we don't need to do anything here.
@@ -92,6 +110,11 @@ export class VariantAnalysisManager extends DisposableObject implements VariantA
92110 await this . variantAnalysisResultsManager . loadResults ( variantAnalysisId , this . getVariantAnalysisStorageLocation ( variantAnalysisId ) , repositoryFullName ) ;
93111 }
94112
113+ private async variantAnalysisRecordExists ( variantAnalysisId : number ) : Promise < boolean > {
114+ const filePath = this . getVariantAnalysisStorageLocation ( variantAnalysisId ) ;
115+ return await fs . pathExists ( filePath ) ;
116+ }
117+
95118 private async onVariantAnalysisUpdated ( variantAnalysis : VariantAnalysis | undefined ) : Promise < void > {
96119 if ( ! variantAnalysis ) {
97120 return ;
0 commit comments