Skip to content

Commit 5b21722

Browse files
committed
Close view when variant analyis is deleted from query history
This will close the variant analysis view when the corresponding variant analysis history item is deleted from the query history. This required some extra code to handle `dispose` being called on the view to ensure this actually disposes the panel, but we can now call `dispose()` on the view to close it.
1 parent 25a9ee1 commit 5b21722

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

extensions/ql-vscode/src/abstract-webview.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from 'vscode';
1010
import * as path from 'path';
1111

12-
import { DisposableObject } from './pure/disposable-object';
12+
import { DisposableObject, DisposeHandler } from './pure/disposable-object';
1313
import { tmpDir } from './helpers';
1414
import { getHtmlForWebview, WebviewMessage, WebviewView } from './interface-utils';
1515

@@ -126,4 +126,9 @@ export abstract class AbstractWebview<ToMessage extends WebviewMessage, FromMess
126126
protected postMessage(msg: ToMessage): Thenable<boolean> {
127127
return this.getPanel().webview.postMessage(msg);
128128
}
129+
130+
public dispose(disposeHandler?: DisposeHandler) {
131+
this.panel?.dispose();
132+
super.dispose(disposeHandler);
133+
}
129134
}

extensions/ql-vscode/src/remote-queries/variant-analysis-manager.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { createTimestampFile, showAndLogErrorMessage } from '../helpers';
2727
import { QueryStatus } from '../query-status';
2828
import * as fs from 'fs-extra';
2929

30-
3130
export class VariantAnalysisManager extends DisposableObject implements VariantAnalysisViewManager<VariantAnalysisView> {
3231
private readonly _onVariantAnalysisAdded = this.push(new EventEmitter<VariantAnalysis>());
3332
public readonly onVariantAnalysisAdded = this._onVariantAnalysisAdded.event;
@@ -75,6 +74,9 @@ export class VariantAnalysisManager extends DisposableObject implements VariantA
7574
this.variantAnalysisResultsManager.removeAnalysisResults(variantAnalysis);
7675
await this.removeStorageDirectory(variantAnalysis.id);
7776
this.variantAnalyses.delete(variantAnalysis.id);
77+
78+
// This will automatically unregister the view
79+
this.views.get(variantAnalysis.id)?.dispose();
7880
}
7981

8082
private async removeStorageDirectory(variantAnalysisId: number) {
@@ -88,7 +90,7 @@ export class VariantAnalysisManager extends DisposableObject implements VariantA
8890
}
8991
if (!this.views.has(variantAnalysisId)) {
9092
// The view will register itself with the manager, so we don't need to do anything here.
91-
this.push(new VariantAnalysisView(this.ctx, variantAnalysisId, this));
93+
this.track(new VariantAnalysisView(this.ctx, variantAnalysisId, this));
9294
}
9395

9496
const variantAnalysisView = this.views.get(variantAnalysisId)!;
@@ -106,6 +108,7 @@ export class VariantAnalysisManager extends DisposableObject implements VariantA
106108

107109
public unregisterView(view: VariantAnalysisView): void {
108110
this.views.delete(view.variantAnalysisId);
111+
this.disposeAndStopTracking(view);
109112
}
110113

111114
public getView(variantAnalysisId: number): VariantAnalysisView | undefined {

0 commit comments

Comments
 (0)