Skip to content

Commit 1eb0bf0

Browse files
committed
restore from backup
1 parent e4aba16 commit 1eb0bf0

File tree

4 files changed

+64
-14
lines changed

4 files changed

+64
-14
lines changed

src/vs/workbench/api/browser/mainThreadNotebook.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ export class MainThreadNotebooks implements MainThreadNotebookShape {
5050
options,
5151
dataToNotebook: async (data: VSBuffer): Promise<NotebookData> => {
5252
const sw = new StopWatch(true);
53-
const dto = await this._proxy.$dataToNotebook(handle, data, CancellationToken.None);
54-
const result = NotebookDto.fromNotebookDataDto(dto.value);
53+
let result: NotebookData;
54+
if (data.byteLength === 0 && viewType === 'interactive') {
55+
// we don't want any starting cells for an empty interactive window.
56+
result = NotebookDto.fromNotebookDataDto({ cells: [], metadata: {} });
57+
} else {
58+
const dto = await this._proxy.$dataToNotebook(handle, data, CancellationToken.None);
59+
result = NotebookDto.fromNotebookDataDto(dto.value);
60+
}
5561
this._logService.trace(`[NotebookSerializer] dataToNotebook DONE after ${sw.elapsed()}ms`, {
5662
viewType,
5763
extensionId: extension.id.value,

src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts

+53-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
88
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
99
import { parse } from 'vs/base/common/marshalling';
1010
import { Schemas } from 'vs/base/common/network';
11-
import { extname } from 'vs/base/common/resources';
11+
import { extname, isEqual } from 'vs/base/common/resources';
1212
import { isFalsyOrWhitespace } from 'vs/base/common/strings';
1313
import { assertType } from 'vs/base/common/types';
1414
import { URI, UriComponents } from 'vs/base/common/uri';
@@ -54,14 +54,17 @@ import { INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/no
5454
import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget';
5555
import * as icons from 'vs/workbench/contrib/notebook/browser/notebookIcons';
5656
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService';
57-
import { CellEditType, CellKind, CellUri, INTERACTIVE_WINDOW_EDITOR_ID } from 'vs/workbench/contrib/notebook/common/notebookCommon';
57+
import { CellEditType, CellKind, CellUri, INTERACTIVE_WINDOW_EDITOR_ID, NotebookWorkingCopyTypeIdentifier } from 'vs/workbench/contrib/notebook/common/notebookCommon';
5858
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
5959
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
6060
import { columnToEditorGroup } from 'vs/workbench/services/editor/common/editorGroupColumn';
6161
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
6262
import { IEditorResolverService, RegisteredEditorPriority } from 'vs/workbench/services/editor/common/editorResolverService';
6363
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
64+
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
6465
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
66+
import { IWorkingCopyIdentifier } from 'vs/workbench/services/workingCopy/common/workingCopy';
67+
import { IWorkingCopyEditorHandler, IWorkingCopyEditorService } from 'vs/workbench/services/workingCopy/common/workingCopyEditorService';
6568

6669
const interactiveWindowCategory: ILocalizedString = { value: localize('interactiveWindow', 'Interactive Window'), original: 'Interactive Window' };
6770

@@ -181,10 +184,58 @@ class InteractiveInputContentProvider implements ITextModelContentProvider {
181184
}
182185
}
183186

187+
class InteractiveWindowWorkingCopyEditorHandler extends Disposable implements IWorkbenchContribution, IWorkingCopyEditorHandler {
188+
189+
constructor(
190+
@IInstantiationService private readonly _instantiationService: IInstantiationService,
191+
@IWorkingCopyEditorService private readonly _workingCopyEditorService: IWorkingCopyEditorService,
192+
@IExtensionService private readonly _extensionService: IExtensionService,
193+
) {
194+
super();
195+
196+
this._installHandler();
197+
}
198+
199+
handles(workingCopy: IWorkingCopyIdentifier): boolean {
200+
const viewType = this._getViewType(workingCopy);
201+
return !!viewType && viewType === 'interactive';
202+
203+
}
204+
205+
isOpen(workingCopy: IWorkingCopyIdentifier, editor: EditorInput): boolean {
206+
if (!this.handles(workingCopy)) {
207+
return false;
208+
}
209+
210+
return editor instanceof InteractiveEditorInput && isEqual(workingCopy.resource, editor.resource);
211+
}
212+
213+
createEditor(workingCopy: IWorkingCopyIdentifier): EditorInput {
214+
const counter = /\/Interactive-(\d+)/.exec(workingCopy.resource.path);
215+
const inputBoxPath = counter && counter[1] ? `/InteractiveInput-${counter[1]}` : 'InteractiveInput';
216+
const inputUri = URI.from({ scheme: Schemas.vscodeInteractiveInput, path: inputBoxPath });
217+
const editorInput = InteractiveEditorInput.create(this._instantiationService, workingCopy.resource, inputUri);
218+
219+
return editorInput;
220+
}
221+
222+
private async _installHandler(): Promise<void> {
223+
await this._extensionService.whenInstalledExtensionsRegistered();
224+
225+
this._register(this._workingCopyEditorService.registerHandler(this));
226+
}
227+
228+
private _getViewType(workingCopy: IWorkingCopyIdentifier): string | undefined {
229+
return NotebookWorkingCopyTypeIdentifier.parse(workingCopy.typeId);
230+
}
231+
}
232+
233+
184234

185235
const workbenchContributionsRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
186236
workbenchContributionsRegistry.registerWorkbenchContribution(InteractiveDocumentContribution, LifecyclePhase.Ready);
187237
workbenchContributionsRegistry.registerWorkbenchContribution(InteractiveInputContentProvider, LifecyclePhase.Ready);
238+
workbenchContributionsRegistry.registerWorkbenchContribution(InteractiveWindowWorkingCopyEditorHandler, LifecyclePhase.Ready);
188239

189240
export class InteractiveEditorSerializer implements IEditorSerializer {
190241
public static readonly ID = InteractiveEditorInput.ID;

src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ export class InteractiveEditor extends EditorPane {
425425
}
426426

427427
if (model === null) {
428-
throw new Error('?');
428+
throw new Error('The Interactive Window model could not be resolved');
429429
}
430430

431431
this.#notebookWidget.value?.setParentContextKeyService(this.#contextKeyService);

src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { Emitter, Event } from 'vs/base/common/event';
1010
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
1111
import { Schemas } from 'vs/base/common/network';
1212
import { filter } from 'vs/base/common/objects';
13-
import { extname } from 'vs/base/common/resources';
1413
import { assertType } from 'vs/base/common/types';
1514
import { URI } from 'vs/base/common/uri';
1615
import { IRevertOptions, ISaveOptions, IUntypedEditorInput } from 'vs/workbench/common/editor';
@@ -280,14 +279,8 @@ export class NotebookFileWorkingCopyModelFactory implements IStoredFileWorkingCo
280279
throw new Error('CANNOT open file notebook with this provider');
281280
}
282281

283-
let data: NotebookData = {
284-
metadata: {},
285-
cells: []
286-
};
287-
if (extname(resource) !== '.interactive') {
288-
const bytes = await streamToBuffer(stream);
289-
data = await info.serializer.dataToNotebook(bytes);
290-
}
282+
const bytes = await streamToBuffer(stream);
283+
const data = await info.serializer.dataToNotebook(bytes);
291284

292285
if (token.isCancellationRequested) {
293286
throw new CancellationError();

0 commit comments

Comments
 (0)