Preserve previous code cell's language when creating a new code cell from an existing context. (#18646)

This commit is contained in:
Cory Rivera
2022-03-06 21:35:57 -08:00
committed by GitHub
parent 5d0f0afdc6
commit eccb77aca3
6 changed files with 41 additions and 11 deletions

View File

@@ -1006,6 +1006,33 @@ suite('notebook model', function (): void {
assert.strictEqual(model.languageInfo.name, 'fake', 'Notebook language info is not set properly');
});
test('Should add new cell with provided cell language', async function () {
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
defaultModelOptions.contentLoader = mockContentManager.object;
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService, undoRedoService);
await model.loadContents();
const newLanguage = 'CustomCellLanguage';
let cell = model.addCell(CellTypes.Code, undefined, newLanguage);
assert.strictEqual(model.cells.length, expectedNotebookContent.cells.length + 1, 'New cell was not added to list of cells.');
assert.strictEqual(cell.language, newLanguage);
});
test('Should add new cell with default language if none is provided', async function () {
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
defaultModelOptions.contentLoader = mockContentManager.object;
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService, undoRedoService);
await model.loadContents();
let cell = model.addCell(CellTypes.Code);
assert.strictEqual(model.cells.length, expectedNotebookContent.cells.length + 1, 'New cell was not added to list of cells.');
assert.strictEqual(cell.language, expectedNotebookContent.metadata.language_info.name);
});
async function loadModelAndStartClientSession(notebookContent: nb.INotebookContents): Promise<NotebookModel> {
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentLoader);
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(notebookContent));

View File

@@ -122,7 +122,7 @@ export class NotebookModelStub implements INotebookModel {
getMetaValue(key: string) {
throw new Error('Method not implemented.');
}
addCell(cellType: CellType, index?: number): void {
addCell(cellType: CellType, index?: number, language?: string): void {
throw new Error('Method not implemented.');
}
moveCell(cellModel: ICellModel, direction: MoveDirection): void {