提交 bfac07cd 编写于 作者: R rebornix

de-ref interactive input on interactive nb close.

上级 9cb3f15e
......@@ -21,7 +21,11 @@ export class MainThreadInteractive implements MainThreadInteractiveShape {
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostInteractive);
this._disposables.add(interactiveDocumentService.onWillAddInteractiveDocument((e) => {
this._proxy.$acceptInputDocument(e.inputUri, '\n', 'plaintext', e.notebookUri);
this._proxy.$willAddInteractiveDocument(e.inputUri, '\n', 'plaintext', e.notebookUri);
}));
this._disposables.add(interactiveDocumentService.onWillAddInteractiveDocument((e) => {
this._proxy.$willRemoveInteractiveDocument(e.inputUri, e.notebookUri);
}));
}
......
......@@ -2038,7 +2038,8 @@ export interface ExtHostNotebookKernelsShape {
}
export interface ExtHostInteractiveShape {
$acceptInputDocument(uri: UriComponents, eol: string, modeId: string, notebookUri: UriComponents): void;
$willAddInteractiveDocument(uri: UriComponents, eol: string, modeId: string, notebookUri: UriComponents): void;
$willRemoveInteractiveDocument(uri: UriComponents, notebookUri: UriComponents): void;
}
export interface ExtHostStorageShape {
......
......@@ -16,7 +16,7 @@ export class ExtHostInteractive implements ExtHostInteractiveShape {
) {
}
$acceptInputDocument(uri: UriComponents, eol: string, modeId: string, notebookUri: UriComponents) {
$willAddInteractiveDocument(uri: UriComponents, eol: string, modeId: string, notebookUri: UriComponents) {
this._textDocumentsAndEditors.acceptDocumentsAndEditorsDelta({
addedDocuments: [{
EOL: eol,
......@@ -29,4 +29,10 @@ export class ExtHostInteractive implements ExtHostInteractiveShape {
}]
});
}
$willRemoveInteractiveDocument(uri: UriComponents, notebookUri: UriComponents) {
this._textDocumentsAndEditors.acceptDocumentsAndEditorsDelta({
removedDocuments: [uri]
});
}
}
......@@ -13,13 +13,17 @@ export const IInteractiveDocumentService = createDecorator<IInteractiveDocumentS
export interface IInteractiveDocumentService {
readonly _serviceBrand: undefined;
onWillAddInteractiveDocument: Event<{ notebookUri: URI; inputUri: URI; languageId: string; }>;
onWillRemoveInteractiveDocument: Event<{ notebookUri: URI; inputUri: URI; }>;
willCreateInteractiveDocument(notebookUri: URI, inputUri: URI, languageId: string): void;
willRemoveInteractiveDocument(notebookUri: URI, inputUri: URI): void;
}
export class InteractiveDocumentService extends Disposable {
declare readonly _serviceBrand: undefined;
private readonly _onWillAddInteractiveDocument = this._register(new Emitter<{ notebookUri: URI; inputUri: URI; languageId: string; }>());
onWillAddInteractiveDocument = this._onWillAddInteractiveDocument.event;
private readonly _onWillRemoveInteractiveDocument = this._register(new Emitter<{ notebookUri: URI; inputUri: URI; }>());
onWillRemoveInteractiveDocument = this._onWillRemoveInteractiveDocument.event;
constructor() {
super();
......@@ -33,4 +37,8 @@ export class InteractiveDocumentService extends Disposable {
});
}
willRemoveInteractiveDocument(notebookUri: URI, inputUri: URI) {
}
}
......@@ -173,9 +173,16 @@ export class InteractiveEditor extends EditorPane {
if (!editorModel) {
this.#interactiveDocumentService.willCreateInteractiveDocument(input.resource!, input.inputResource, this.#notebookWidget.value?.activeKernel?.supportedLanguages[0] ?? 'plaintext');
editorModel = this.#modelService.createModel('', null, input.inputResource, false);
// willCreateInteractiveDocument refs the input model, then we should de-ref it on close.
this.#widgetDisposableStore.add({
dispose: () => {
this.#interactiveDocumentService.willRemoveInteractiveDocument(input.resource!, input.inputResource);
editorModel?.dispose();
}
});
}
this.#widgetDisposableStore.add(editorModel);
this.#codeEditorWidget.setModel(editorModel);
this.#widgetDisposableStore.add(this.#codeEditorWidget.onDidContentSizeChange(e => {
if (!e.contentHeightChanged) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册