Skip to content

Commit b20cdb8

Browse files
committed
Fix lifecycle issues with plot clients
1 parent e83aa96 commit b20cdb8

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

src/vs/workbench/contrib/positronPlots/browser/positronPlotsService.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -781,17 +781,26 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe
781781
this._onDidSelectPlot.fire(plotClient.id);
782782
}
783783

784+
// Dispose the plot client when this service is disposed (we own this
785+
// object)
786+
const disp = this._register(plotClient);
787+
784788
// Remove the plot from our list when it is closed
785-
this._register(plotClient.onDidClose(() => {
786-
const index = this._plots.indexOf(plotClient);
787-
if (index >= 0) {
788-
this._plots.splice(index, 1);
789+
plotClient.register({
790+
dispose: () => {
791+
const index = this._plots.indexOf(plotClient);
792+
if (index >= 0) {
793+
this._plots.splice(index, 1);
794+
}
795+
796+
// Clear the plot's metadata from storage
797+
this._storageService.remove(
798+
this.generateStorageKey(plotClient.metadata.session_id, plotClient.metadata.id, plotClient.metadata.location),
799+
StorageScope.WORKSPACE);
800+
801+
disp.dispose();
789802
}
790-
// Clear the plot's metadata from storage
791-
this._storageService.remove(
792-
this.generateStorageKey(plotClient.metadata.session_id, plotClient.metadata.id, plotClient.metadata.location),
793-
StorageScope.WORKSPACE);
794-
}));
803+
});
795804

796805
const selectPlot = () => {
797806
// Raise the Plots pane so the user can see the updated plot
@@ -803,19 +812,15 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe
803812
};
804813

805814
// Raise the plot if it's updated by the runtime
806-
this._register(plotClient.onDidRenderUpdate((_plot) => {
815+
plotClient.register(plotClient.onDidRenderUpdate((_plot) => {
807816
selectPlot();
808817
}));
809818

810819
// Focus the plot if the runtime requests it
811-
this._register(plotClient.onDidShowPlot(() => {
820+
plotClient.register(plotClient.onDidShowPlot(() => {
812821
selectPlot();
813822
}));
814-
815-
// Dispose the plot client when this service is disposed (we own this
816-
// object)
817-
this._register(plotClient);
818-
}
823+
}
819824

820825
/**
821826
* Creates a new static plot client instance and registers it with the

src/vs/workbench/services/languageRuntime/common/languageRuntimePlotClient.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Disposable } from '../../../../base/common/lifecycle.js';
6+
import { Disposable, IDisposable } from '../../../../base/common/lifecycle.js';
77
import { Event, Emitter } from '../../../../base/common/event.js';
88
import { IPositronPlotClient } from '../../positronPlots/common/positronPlots.js';
99
import { IntrinsicSize, PlotResult, PlotRenderFormat } from './positronPlotComm.js';
@@ -441,4 +441,11 @@ export class PlotClientInstance extends Disposable implements IPositronPlotClien
441441
this._closeEmitter.fire();
442442
super.dispose();
443443
}
444+
445+
/**
446+
* Register a resource for cleanup on disposal.
447+
*/
448+
public register<T extends IDisposable>(o: T): T {
449+
return this._register(o);
450+
}
444451
}

0 commit comments

Comments
 (0)