mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Dispose underlying text model when disposing notebook editor model (#19955)
This commit is contained in:
@@ -15,6 +15,7 @@ import * as uuid from 'uuid';
|
|||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { tryDeleteFile } from './testUtils';
|
import { tryDeleteFile } from './testUtils';
|
||||||
import { CellTypes } from '../../contracts/content';
|
import { CellTypes } from '../../contracts/content';
|
||||||
|
import { NBFORMAT, NBFORMAT_MINOR } from '../../common/constants';
|
||||||
|
|
||||||
describe('notebookUtils Tests', function (): void {
|
describe('notebookUtils Tests', function (): void {
|
||||||
let notebookUtils: NotebookUtils = new NotebookUtils();
|
let notebookUtils: NotebookUtils = new NotebookUtils();
|
||||||
@@ -91,6 +92,34 @@ describe('notebookUtils Tests', function (): void {
|
|||||||
await notebookUtils.openNotebook();
|
await notebookUtils.openNotebook();
|
||||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should have been called');
|
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should have been called');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('closing and opening an untitled notebook shows correct contents', async function (): Promise<void> {
|
||||||
|
await notebookUtils.newNotebook();
|
||||||
|
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
||||||
|
await notebookUtils.newNotebook({
|
||||||
|
initialContent: {
|
||||||
|
cells: [{
|
||||||
|
source: 'test content',
|
||||||
|
cell_type: 'markdown'
|
||||||
|
}],
|
||||||
|
metadata: {
|
||||||
|
kernelspec: {
|
||||||
|
name: 'SQL',
|
||||||
|
language: 'sql',
|
||||||
|
display_name: 'SQL'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
nbformat: NBFORMAT,
|
||||||
|
nbformat_minor: NBFORMAT_MINOR
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let activeEditor = azdata.nb.activeNotebookEditor;
|
||||||
|
let cells = activeEditor.document.cells;
|
||||||
|
// We currently can't retrieve the cell source from the extension API, but all we care
|
||||||
|
// about is that the notebook doesn't open as empty again, so just check the number of
|
||||||
|
// cells here.
|
||||||
|
should(cells.length).be.greaterThan(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('runActiveCell', function () {
|
describe('runActiveCell', function () {
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ export class NotebookEditorModel extends EditorModel {
|
|||||||
}, err => undefined);
|
}, err => undefined);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
this._register(this.textEditorModel);
|
||||||
if (this.textEditorModel instanceof UntitledTextEditorModel) {
|
if (this.textEditorModel instanceof UntitledTextEditorModel) {
|
||||||
this._register(this.textEditorModel.onDidChangeDirty(e => {
|
this._register(this.textEditorModel.onDidChangeDirty(e => {
|
||||||
let dirty = this.textEditorModel instanceof TextResourceEditorModel ? false : this.textEditorModel.isDirty();
|
let dirty = this.textEditorModel instanceof TextResourceEditorModel ? false : this.textEditorModel.isDirty();
|
||||||
@@ -420,6 +421,7 @@ export abstract class NotebookInput extends EditorInput implements INotebookInpu
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const textEditorModelReference = await this.textModelService.createModelReference(this.resource);
|
const textEditorModelReference = await this.textModelService.createModelReference(this.resource);
|
||||||
|
this._register(textEditorModelReference);
|
||||||
textEditorModelReference.object.textEditorModel.onBeforeAttached();
|
textEditorModelReference.object.textEditorModel.onBeforeAttached();
|
||||||
await textEditorModelReference.object.resolve();
|
await textEditorModelReference.object.resolve();
|
||||||
textOrUntitledEditorModel = textEditorModelReference.object as TextFileEditorModel | TextResourceEditorModel;
|
textOrUntitledEditorModel = textEditorModelReference.object as TextFileEditorModel | TextResourceEditorModel;
|
||||||
|
|||||||
Reference in New Issue
Block a user