change cell language with cell change events.

This commit is contained in:
rebornix
2021-02-16 19:41:30 -08:00
parent b3f8737839
commit 79b8259abb
2 changed files with 110 additions and 20 deletions

View File

@@ -135,7 +135,7 @@ suite('Notebook API tests', function () {
id: 'mainKernel',
label: 'Notebook Test Kernel',
isPreferred: true,
supportedLanguages: ['typescript'],
supportedLanguages: ['typescript', 'javascript'],
executeAllCells: async (_document: vscode.NotebookDocument) => {
const edit = new vscode.WorkspaceEdit();
@@ -174,7 +174,7 @@ suite('Notebook API tests', function () {
id: 'secondaryKernel',
label: 'Notebook Secondary Test Kernel',
isPreferred: false,
supportedLanguages: ['typescript'],
supportedLanguages: ['typescript', 'javascript'],
executeAllCells: async (_document: vscode.NotebookDocument) => {
const edit = new vscode.WorkspaceEdit();
edit.replaceNotebookCellOutput(_document.uri, 0, [new vscode.NotebookCellOutput([
@@ -471,6 +471,30 @@ suite('Notebook API tests', function () {
await saveFileAndCloseAll(resource);
});
test('change cell language', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookCoreTest');
assert.strictEqual(vscode.window.activeNotebookEditor?.document.cells[0].language, 'typescript');
assert.strictEqual(vscode.window.activeNotebookEditor?.document.cells[0].cellKind, vscode.NotebookCellKind.Code);
await withEvent(vscode.notebook.onDidChangeCellLanguage, async event => {
await vscode.commands.executeCommand('notebook.cell.changeLanguage', { start: 0, end: 1 }, 'javascript');
await event;
assert.strictEqual(vscode.window.activeNotebookEditor?.document.cells[0].language, 'javascript');
});
// switch to markdown will change the cell kind
await withEvent(vscode.notebook.onDidChangeNotebookCells, async event => {
await vscode.commands.executeCommand('notebook.cell.changeLanguage', { start: 0, end: 1 }, 'markdown');
await event;
assert.strictEqual(vscode.window.activeNotebookEditor?.document.cells[0].language, 'markdown');
assert.strictEqual(vscode.window.activeNotebookEditor?.document.cells[0].cellKind, vscode.NotebookCellKind.Markdown);
});
await saveAllFilesAndCloseAll(resource);
});
test('edit API (replaceCells)', async function () {
assertInitalState();
const resource = await createRandomFile('', undefined, '.vsctestnb');