src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts/changeCellToKind
export async function changeCellToKind(kind: CellKind, context: INotebookCellActionContext, language?: string): Promise<ICellViewModel | null> {
	const { cell, notebookEditor } = context;

	if (cell.cellKind === kind) {
		return null;
	}

	if (!notebookEditor.viewModel) {
		return null;
	}

	if (notebookEditor.viewModel.options.isReadOnly) {
		return null;
	}

	const text = cell.getText();
	const idx = notebookEditor.viewModel.getCellIndex(cell);

	if (language === undefined) {
		const availableLanguages = notebookEditor.activeKernel?.supportedLanguages ?? [];
		language = availableLanguages[0] ?? 'plaintext';
	}

	notebookEditor.textModel.applyEdits([
		{
			editType: CellEditType.Replace,
			index: idx,
			count: 1,
			cells: [{
				cellKind: kind,
				source: text,
				language: language!,
				mime: cell.mime,
				outputs: cell.model.outputs,
				metadata: cell.metadata,
			}]
		}
	], true, undefined, () => undefined, undefined, true);
	const newCell = notebookEditor.viewModel.cellAt(idx);

	if (!newCell) {
		return null;
	}

	notebookEditor.focusNotebookCell(newCell, cell.getEditState() === CellEditState.Editing ? 'editor' : 'container');

	return newCell;
}