add parameter to Interactive Execute to specify resource

This commit is contained in:
aamunger
2022-08-11 10:10:05 -07:00
parent a2a836aebf
commit 694324e3ac
3 changed files with 48 additions and 14 deletions

View File

@@ -12,7 +12,7 @@ import { Kernel, saveAllFilesAndCloseAll } from './notebook.api.test';
export type INativeInteractiveWindow = { notebookUri: vscode.Uri; inputUri: vscode.Uri; notebookEditor: vscode.NotebookEditor };
async function createInteractiveWindow(kernel: Kernel) {
const { notebookEditor } = (await vscode.commands.executeCommand(
const { notebookEditor, inputUri } = (await vscode.commands.executeCommand(
'interactive.open',
// Keep focus on the owning file if there is one
{ viewColumn: vscode.ViewColumn.Beside, preserveFocus: false },
@@ -21,7 +21,7 @@ async function createInteractiveWindow(kernel: Kernel) {
undefined
)) as unknown as INativeInteractiveWindow;
return notebookEditor;
return { notebookEditor, inputUri };
}
async function addCell(code: string, notebook: vscode.NotebookDocument) {
@@ -61,13 +61,18 @@ async function addCellAndRun(code: string, notebook: vscode.NotebookDocument, i:
await saveAllFilesAndCloseAll();
});
test('Can open an interactive window', async () => {
test('Can open an interactive window and execute from input box', async () => {
assert.ok(vscode.workspace.workspaceFolders);
const notebookEditor = await createInteractiveWindow(defaultKernel);
const { notebookEditor, inputUri } = await createInteractiveWindow(defaultKernel);
assert.ok(notebookEditor);
// Try adding a cell and running it.
await addCell('print foo', notebookEditor.notebook);
const inputBox = vscode.window.visibleTextEditors.find(
(e) => e.document.uri.path === inputUri.path
);
await inputBox!.edit((editBuilder) => {
editBuilder.insert(new vscode.Position(0, 0), 'print foo');
});
await vscode.commands.executeCommand('interactive.execute', notebookEditor.notebook.uri);
assert.strictEqual(notebookEditor.notebook.cellCount, 1);
assert.strictEqual(notebookEditor.notebook.cellAt(0).kind, vscode.NotebookCellKind.Code);
@@ -75,7 +80,7 @@ async function addCellAndRun(code: string, notebook: vscode.NotebookDocument, i:
test('Interactive window scrolls after execute', async () => {
assert.ok(vscode.workspace.workspaceFolders);
const notebookEditor = await createInteractiveWindow(defaultKernel);
const { notebookEditor } = await createInteractiveWindow(defaultKernel);
assert.ok(notebookEditor);
// Run and add a bunch of cells
@@ -90,13 +95,13 @@ async function addCellAndRun(code: string, notebook: vscode.NotebookDocument, i:
test('Interactive window has the correct kernel', async () => {
assert.ok(vscode.workspace.workspaceFolders);
const notebookEditor = await createInteractiveWindow(defaultKernel);
const { notebookEditor } = await createInteractiveWindow(defaultKernel);
assert.ok(notebookEditor);
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
// Create a new interactive window with a different kernel
const notebookEditor2 = await createInteractiveWindow(secondKernel);
const { notebookEditor: notebookEditor2 } = await createInteractiveWindow(secondKernel);
assert.ok(notebookEditor2);
// Verify the kernel is the secondary one