Skip to content

Commit

Permalink
Merge remote-tracking branch 'VSCode/main' into web-DataViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
sadasant committed Jun 17, 2022
2 parents 41d7239 + eb2d5c1 commit ef27f8b
Show file tree
Hide file tree
Showing 15 changed files with 2,323 additions and 2,198 deletions.
4,296 changes: 2,148 additions & 2,148 deletions TELEMETRY.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions news/1 Enhancements/10291.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enabled export Interactive Window for web.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@
"title": "%DataScience.exportDialogTitle%",
"shortTitle": "%DataScience.exportAsNotebook.shorttitle%",
"icon": "$(save-as)",
"enablement": "notebookType == interactive && !jupyter.webExtension",
"enablement": "notebookType == interactive",
"category": "Jupyter"
},
{
Expand All @@ -826,7 +826,7 @@
"light": "resources/light/export_to_python.svg",
"dark": "resources/dark/export_to_python.svg"
},
"enablement": "notebookType == interactive && !jupyter.webExtension",
"enablement": "notebookType == interactive",
"category": "Jupyter"
},
{
Expand Down
41 changes: 20 additions & 21 deletions src/interactive-window/interactiveWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
NotebookController,
NotebookEdit
} from 'vscode';
import { IPythonExtensionChecker } from '../platform/api/types';
import {
IApplicationShell,
ICommandManager,
Expand Down Expand Up @@ -117,11 +116,10 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
private readonly fs: IFileSystem,
private readonly configuration: IConfigurationService,
private readonly commandManager: ICommandManager,
private readonly jupyterExporter: INotebookExporter | undefined,
private readonly jupyterExporter: INotebookExporter,
private readonly workspaceService: IWorkspaceService,
private _owner: Resource,
private mode: InteractiveWindowMode,
private readonly extensionChecker: IPythonExtensionChecker,
private readonly exportDialog: IExportDialog,
private readonly notebookControllerManager: INotebookControllerManager,
private readonly serviceContainer: IServiceContainer,
Expand Down Expand Up @@ -777,13 +775,7 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
await workspace.applyEdit(edit);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-empty,@typescript-eslint/no-empty-function
public async export() {
// Export requires the python extension
if (!this.extensionChecker.isPythonExtensionInstalled) {
return this.extensionChecker.showPythonExtensionInstallRequiredPrompt();
}

const { magicCommandsAsComments } = this.configuration.getSettings(this.owningResource);
const cells = generateCellsFromNotebookDocument(this.notebookEditor.notebook, magicCommandsAsComments);

Expand All @@ -799,10 +791,6 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {

public async exportAs() {
const kernel = await this.startKernel();
// Export requires the python extension
if (!this.extensionChecker.isPythonExtensionInstalled) {
return this.extensionChecker.showPythonExtensionInstallRequiredPrompt();
}

// Pull out the metadata from our active notebook
const metadata: nbformat.INotebookMetadata = { orig_nbformat: defaultNotebookFormat.major };
Expand All @@ -818,13 +806,24 @@ export class InteractiveWindow implements IInteractiveWindowLoadable {
}

// Then run the export command with these contents
this.commandManager
.executeCommand(
Commands.Export,
this.notebookDocument,
defaultFileName,
kernel?.kernelConnectionMetadata.interpreter
)
.then(noop, noop);
if (this.isWebExtension) {
// In web, we currently only support exporting as python script
this.commandManager
.executeCommand(
Commands.ExportAsPythonScript,
this.notebookDocument,
kernel?.kernelConnectionMetadata.interpreter
)
.then(noop, noop);
} else {
this.commandManager
.executeCommand(
Commands.Export,
this.notebookDocument,
defaultFileName,
kernel?.kernelConnectionMetadata.interpreter
)
.then(noop, noop);
}
}
}
4 changes: 1 addition & 3 deletions src/interactive-window/interactiveWindowProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
ViewColumn,
window
} from 'vscode';
import { IPythonExtensionChecker } from '../platform/api/types';

import {
IApplicationShell,
Expand Down Expand Up @@ -174,11 +173,10 @@ export class InteractiveWindowProvider
this.serviceContainer.get<IFileSystem>(IFileSystem),
this.serviceContainer.get<IConfigurationService>(IConfigurationService),
commandManager,
this.serviceContainer.tryGet<INotebookExporter>(INotebookExporter),
this.serviceContainer.get<INotebookExporter>(INotebookExporter),
this.serviceContainer.get<IWorkspaceService>(IWorkspaceService),
resource,
mode,
this.serviceContainer.get<IPythonExtensionChecker>(IPythonExtensionChecker),
this.serviceContainer.get<IExportDialog>(IExportDialog),
this.notebookControllerManager,
this.serviceContainer,
Expand Down
62 changes: 60 additions & 2 deletions src/test/datascience/interactiveWindow.vscode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,39 @@ import { traceInfo } from '../../platform/logging';
import { getDisplayPath, getFilePath } from '../../platform/common/platform/fs-paths';
import { IDisposable } from '../../platform/common/types';
import { InteractiveWindowProvider } from '../../interactive-window/interactiveWindowProvider';
import { captureScreenShot, IExtensionTestApi } from '../common.node';
import { captureScreenShot, IExtensionTestApi, waitForCondition } from '../common.node';
import { initialize, IS_REMOTE_NATIVE_TEST, IS_CONDA_TEST } from '../initialize.node';
import {
closeInteractiveWindow,
createStandaloneInteractiveWindow,
insertIntoInputEditor,
installIPyKernel,
runCurrentFile,
runNewPythonFile,
setActiveInterpreter,
uninstallIPyKernel,
waitForInteractiveWindow,
waitForLastCellToComplete
} from './helpers.node';
import { closeNotebooksAndCleanUpAfterTests, startJupyterServer } from './notebook/helper.node';
import {
closeNotebooksAndCleanUpAfterTests,
defaultNotebookTestTimeout,
generateTemporaryFilePath,
hijackPrompt,
hijackSavePrompt,
startJupyterServer,
waitForTextOutput,
WindowPromptStubButtonClickOptions
} from './notebook/helper.node';
import { INotebookControllerManager } from '../../notebooks/types';
import { IInteractiveWindowProvider } from '../../interactive-window/types';
import { IInterpreterService } from '../../platform/interpreter/contracts';
import { areInterpreterPathsSame } from '../../platform/pythonEnvironments/info/interpreter';
import { IPythonApiProvider } from '../../platform/api/types';
import { isEqual } from '../../platform/vscode-path/resources';
import { PythonEnvironment } from '../../platform/pythonEnvironments/info';
import { IVSCodeNotebook } from '../../platform/common/application/types';
import { Commands } from '../../platform/common/constants';

suite(`Interactive window`, async function () {
this.timeout(120_000);
Expand Down Expand Up @@ -153,6 +167,50 @@ suite(`Interactive window`, async function () {
}
});

test('Export Interactive window to Notebook', async () => {
const activeInteractiveWindow = await createStandaloneInteractiveWindow(interactiveWindowProvider);
await waitForInteractiveWindow(activeInteractiveWindow);

// Add a few cells from the input box
await insertIntoInputEditor('print("first")');
await vscode.commands.executeCommand('interactive.execute');
await insertIntoInputEditor('print("second")');
await vscode.commands.executeCommand('interactive.execute');
await insertIntoInputEditor('print("third")');
await vscode.commands.executeCommand('interactive.execute');

await waitForLastCellToComplete(activeInteractiveWindow, 3, false);
let notebookFile = await generateTemporaryFilePath('ipynb', disposables);
const promptOptions: WindowPromptStubButtonClickOptions = {
result: notebookFile,
clickImmediately: true
};
let savePrompt = await hijackSavePrompt('Export', promptOptions, disposables);
let openFilePrompt = await hijackPrompt(
'showInformationMessage',
{ contains: 'Notebook written to' },
{ dismissPrompt: false },
disposables
);

await vscode.commands.executeCommand(Commands.InteractiveExportAsNotebook, activeInteractiveWindow.notebookUri);

await waitForCondition(() => savePrompt.displayed, defaultNotebookTestTimeout, 'save Prompt not displayed');
await waitForCondition(
() => openFilePrompt.displayed,
defaultNotebookTestTimeout,
'open file Prompt not displayed'
);

const vscodeNotebook = api.serviceContainer.get<IVSCodeNotebook>(IVSCodeNotebook);
await vscodeNotebook.openNotebookDocument(notebookFile);
let editor = await vscodeNotebook.showNotebookDocument(notebookFile, { preserveFocus: false });

const cells = editor.notebook.getCells();
assert.strictEqual(cells?.length, 3);
await waitForTextOutput(cells[0], 'first');
});

// todo@joyceerhl
// test('Verify CWD', () => { });
// test('Multiple executes go to last active window', async () => { });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ suite('DataScience Install IPyKernel (slow) (install)', function () {
// Next, lets try to run again, but select a kernel that doesn't have ipykernel.
// At this point we should get the prompt again for this new kernel.
const promptOptions: WindowPromptStubButtonClickOptions = {
text: DataScience.selectKernel(),
result: DataScience.selectKernel(),
clickImmediately: true
};
prompt = await hijackPrompt(
Expand All @@ -345,7 +345,7 @@ suite('DataScience Install IPyKernel (slow) (install)', function () {
const stub = sinon.stub(kernelSelector, 'selectKernel').callsFake(async function () {
// Now that we have selected a kernel, next time we get the prompt again, just dismiss the prompt.
promptOptions.dismissPrompt = true;
delete promptOptions.text;
delete promptOptions.result;
// In tests, things hang as the IW isn't focused.
activeInteractiveWindow.show(false).then(noop, noop);
await waitForKernelToChange({ interpreterPath: venvNoRegPath, isInteractiveController: true });
Expand Down Expand Up @@ -403,7 +403,7 @@ suite('DataScience Install IPyKernel (slow) (install)', function () {
// Now install ipykernel and ensure we can run a cell & that it runs against the right environment.
prompt.reset();
promptOptions.dismissPrompt = false;
promptOptions.text = Common.install();
promptOptions.result = Common.install();

await activeInteractiveWindow
.addCode(`import sys${EOL}print(sys.executable)`, untitledPythonFile.uri, 0)
Expand Down Expand Up @@ -636,7 +636,7 @@ suite('DataScience Install IPyKernel (slow) (install)', function () {
const prompt = await hijackPrompt(
'showInformationMessage',
{ contains: expectedPromptMessageSuffix },
{ text: DataScience.selectKernel(), clickImmediately: true },
{ result: DataScience.selectKernel(), clickImmediately: true },
disposables
);

Expand Down Expand Up @@ -750,15 +750,15 @@ suite('DataScience Install IPyKernel (slow) (install)', function () {
return hijackPrompt(
'showInformationMessage',
{ contains: expectedPromptMessageSuffix },
{ text: DataScience.selectKernel(), clickImmediately: true },
{ result: DataScience.selectKernel(), clickImmediately: true },
disposables
);
}
async function clickInstallFromIPyKernelPrompt() {
return hijackPrompt(
'showInformationMessage',
{ contains: expectedPromptMessageSuffix },
{ text: Common.install(), clickImmediately: true },
{ result: Common.install(), clickImmediately: true },
disposables
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
await hijackPrompt(
'showErrorMessage',
{ endsWith: expectedPromptMessageSuffix },
{ text: Common.install(), clickImmediately: true },
{ result: Common.install(), clickImmediately: true },
disposables
);

Expand Down
2 changes: 1 addition & 1 deletion src/test/datascience/notebook/exportFull.vscode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ suite('DataScience - VSCode Notebook - (Export) (slow)', function () {
await hijackPrompt(
'showErrorMessage',
{ endsWith: expectedPromptMessageSuffix },
{ text: Common.install(), clickImmediately: true },
{ result: Common.install(), clickImmediately: true },
disposables
);

Expand Down
Loading

0 comments on commit ef27f8b

Please sign in to comment.