mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
Safer way to determine whether node or browser
This commit is contained in:
15
extensions/ipynb/src/ipynbMain.browser.ts
Normal file
15
extensions/ipynb/src/ipynbMain.browser.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as main from './ipynbMain';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
return main.activate(context, true);
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
return main.deactivate();
|
||||
}
|
||||
15
extensions/ipynb/src/ipynbMain.node.ts
Normal file
15
extensions/ipynb/src/ipynbMain.node.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as main from './ipynbMain';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
return main.activate(context, false);
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
return main.deactivate();
|
||||
}
|
||||
@@ -29,8 +29,8 @@ type NotebookMetadata = {
|
||||
[propName: string]: unknown;
|
||||
};
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
const serializer = new NotebookSerializer(context);
|
||||
export function activate(context: vscode.ExtensionContext, isBrowser: boolean) {
|
||||
const serializer = new NotebookSerializer(context, isBrowser);
|
||||
keepNotebookModelStoreInSync(context);
|
||||
context.subscriptions.push(vscode.workspace.registerNotebookSerializer('jupyter-notebook', serializer, {
|
||||
transientOutputs: false,
|
||||
|
||||
@@ -17,7 +17,7 @@ export class NotebookSerializer extends vscode.Disposable implements vscode.Note
|
||||
private worker?: import('node:worker_threads').Worker;
|
||||
private tasks = new Map<string, DeferredPromise<Uint8Array>>();
|
||||
|
||||
constructor(readonly context: vscode.ExtensionContext) {
|
||||
constructor(readonly context: vscode.ExtensionContext, private readonly isBrowser: boolean) {
|
||||
super(() => { });
|
||||
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => {
|
||||
if (e.affectsConfiguration('ipynb.experimental.serialization')) {
|
||||
@@ -96,7 +96,7 @@ export class NotebookSerializer extends vscode.Disposable implements vscode.Note
|
||||
return new Uint8Array(0);
|
||||
}
|
||||
|
||||
if (this.experimentalSave) {
|
||||
if (this.experimentalSave && !this.isBrowser) {
|
||||
return this.serializeViaWorker2(data);
|
||||
}
|
||||
const serialized = serializeNotebookToString(data);
|
||||
|
||||
Reference in New Issue
Block a user