Skip to content

Commit 3b921a8

Browse files
committed
use scratchpad for IW working copy
This reverts commit f5e494e.
1 parent a0a662c commit 3b921a8

File tree

8 files changed

+37
-107
lines changed

8 files changed

+37
-107
lines changed

src/vs/base/common/network.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export namespace Schemas {
6060
export const vscodeNotebookCell = 'vscode-notebook-cell';
6161
export const vscodeNotebookCellMetadata = 'vscode-notebook-cell-metadata';
6262
export const vscodeNotebookCellOutput = 'vscode-notebook-cell-output';
63-
export const vscodeInteractive = 'vscode-interactive';
6463
export const vscodeInteractiveInput = 'vscode-interactive-input';
6564

6665
export const vscodeSettings = 'vscode-settings';

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

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import { IInteractiveDocumentService, InteractiveDocumentService } from 'vs/work
5151
import { InteractiveEditor } from 'vs/workbench/contrib/interactive/browser/interactiveEditor';
5252
import { InteractiveEditorInput } from 'vs/workbench/contrib/interactive/browser/interactiveEditorInput';
5353
import { IInteractiveHistoryService, InteractiveHistoryService } from 'vs/workbench/contrib/interactive/browser/interactiveHistoryService';
54-
import { InteractiveWindowFileSystem } from 'vs/workbench/contrib/interactive/browser/interactiveWindowFileSystem';
5554
import { NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
5655
import { INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
5756
import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget';
@@ -96,9 +95,6 @@ export class InteractiveDocumentContribution extends Disposable implements IWork
9695
cellContentMetadata: {}
9796
};
9897

99-
const interactiveWindowFS = new InteractiveWindowFileSystem();
100-
this._register(fileService.registerProvider(Schemas.vscodeInteractive, interactiveWindowFS));
101-
10298
const serializer: INotebookSerializer = {
10399
options: contentOptions,
104100
dataToNotebook: async (data: VSBuffer): Promise<NotebookData> => {
@@ -205,7 +201,9 @@ export class InteractiveDocumentContribution extends Disposable implements IWork
205201
priority: RegisteredEditorPriority.exclusive
206202
},
207203
{
208-
canSupportResource: uri => uri.scheme === Schemas.vscodeInteractive || (uri.scheme === Schemas.vscodeNotebookCell && extname(uri) === '.interactive'),
204+
canSupportResource: uri =>
205+
(uri.scheme === Schemas.untitled && extname(uri) === '.interactive') ||
206+
(uri.scheme === Schemas.vscodeNotebookCell && extname(uri) === '.interactive'),
209207
singlePerResource: true
210208
},
211209
{
@@ -371,7 +369,7 @@ registerAction2(class extends Action2 {
371369
preserveFocus: typeof showOptions !== 'number' ? (showOptions?.preserveFocus ?? false) : false
372370
};
373371

374-
if (resource && resource.scheme === Schemas.vscodeInteractive) {
372+
if (resource && extname(resource) === '.interactive') {
375373
logService.debug('Open interactive window from resource:', resource.toString());
376374
const resourceUri = URI.revive(resource);
377375
const editors = editorService.findEditors(resourceUri).filter(id => id.editor instanceof InteractiveEditorInput && id.editor.resource?.toString() === resourceUri.toString());
@@ -401,7 +399,7 @@ registerAction2(class extends Action2 {
401399
let inputUri: URI | undefined = undefined;
402400
let counter = 1;
403401
do {
404-
notebookUri = URI.from({ scheme: Schemas.vscodeInteractive, path: `/Interactive-${counter}.interactive` });
402+
notebookUri = URI.from({ scheme: Schemas.untitled, path: `/Interactive-${counter}.interactive` });
405403
inputUri = URI.from({ scheme: Schemas.vscodeInteractiveInput, path: `/InteractiveInput-${counter}` });
406404

407405
counter++;
@@ -435,7 +433,7 @@ registerAction2(class extends Action2 {
435433
category: interactiveWindowCategory,
436434
keybinding: {
437435
// when: NOTEBOOK_CELL_LIST_FOCUSED,
438-
when: ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
436+
when: ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
439437
primary: KeyMod.WinCtrl | KeyCode.Enter,
440438
win: {
441439
primary: KeyMod.CtrlCmd | KeyCode.Enter
@@ -469,15 +467,14 @@ registerAction2(class extends Action2 {
469467
const notebookEditorService = accessor.get(INotebookEditorService);
470468
let editorControl: { notebookEditor: NotebookEditorWidget | undefined; codeEditor: CodeEditorWidget } | undefined;
471469
if (context) {
472-
if (context.scheme === Schemas.vscodeInteractive) {
473-
const resourceUri = URI.revive(context);
474-
const editors = editorService.findEditors(resourceUri).filter(id => id.editor instanceof InteractiveEditorInput && id.editor.resource?.toString() === resourceUri.toString());
475-
if (editors.length) {
476-
const editorInput = editors[0].editor as InteractiveEditorInput;
477-
const currentGroup = editors[0].groupId;
478-
const editor = await editorService.openEditor(editorInput, currentGroup);
479-
editorControl = editor?.getControl() as { notebookEditor: NotebookEditorWidget | undefined; codeEditor: CodeEditorWidget } | undefined;
480-
}
470+
const resourceUri = URI.revive(context);
471+
const editors = editorService.findEditors(resourceUri)
472+
.filter(id => id.editor instanceof InteractiveEditorInput && id.editor.resource?.toString() === resourceUri.toString());
473+
if (editors.length) {
474+
const editorInput = editors[0].editor as InteractiveEditorInput;
475+
const currentGroup = editors[0].groupId;
476+
const editor = await editorService.openEditor(editorInput, currentGroup);
477+
editorControl = editor?.getControl() as { notebookEditor: NotebookEditorWidget | undefined; codeEditor: CodeEditorWidget } | undefined;
481478
}
482479
}
483480
else {
@@ -578,7 +575,7 @@ registerAction2(class extends Action2 {
578575
f1: false,
579576
keybinding: {
580577
when: ContextKeyExpr.and(
581-
ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
578+
ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
582579
INTERACTIVE_INPUT_CURSOR_BOUNDARY.notEqualsTo('bottom'),
583580
INTERACTIVE_INPUT_CURSOR_BOUNDARY.notEqualsTo('none'),
584581
SuggestContext.Visible.toNegated()
@@ -617,7 +614,7 @@ registerAction2(class extends Action2 {
617614
f1: false,
618615
keybinding: {
619616
when: ContextKeyExpr.and(
620-
ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
617+
ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
621618
INTERACTIVE_INPUT_CURSOR_BOUNDARY.notEqualsTo('top'),
622619
INTERACTIVE_INPUT_CURSOR_BOUNDARY.notEqualsTo('none'),
623620
SuggestContext.Visible.toNegated()
@@ -654,7 +651,7 @@ registerAction2(class extends Action2 {
654651
id: 'interactive.scrollToTop',
655652
title: localize('interactiveScrollToTop', 'Scroll to Top'),
656653
keybinding: {
657-
when: ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
654+
when: ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
658655
primary: KeyMod.CtrlCmd | KeyCode.Home,
659656
mac: { primary: KeyMod.CtrlCmd | KeyCode.UpArrow },
660657
weight: KeybindingWeight.WorkbenchContrib
@@ -683,7 +680,7 @@ registerAction2(class extends Action2 {
683680
id: 'interactive.scrollToBottom',
684681
title: localize('interactiveScrollToBottom', 'Scroll to Bottom'),
685682
keybinding: {
686-
when: ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
683+
when: ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
687684
primary: KeyMod.CtrlCmd | KeyCode.End,
688685
mac: { primary: KeyMod.CtrlCmd | KeyCode.DownArrow },
689686
weight: KeybindingWeight.WorkbenchContrib
@@ -750,9 +747,9 @@ registerAction2(class extends Action2 {
750747
category: interactiveWindowCategory,
751748
menu: {
752749
id: MenuId.CommandPalette,
753-
when: ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
750+
when: ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
754751
},
755-
precondition: ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
752+
precondition: ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
756753
});
757754
}
758755

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { isEqual } from 'vs/base/common/resources';
1111
import { URI } from 'vs/base/common/uri';
1212
import { IResolvedTextEditorModel, ITextModelService } from 'vs/editor/common/services/resolverService';
1313
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
14-
import { IUntypedEditorInput } from 'vs/workbench/common/editor';
14+
import { EditorInputCapabilities, IUntypedEditorInput } from 'vs/workbench/common/editor';
1515
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
1616
import { IInteractiveDocumentService } from 'vs/workbench/contrib/interactive/browser/interactiveDocumentService';
1717
import { IInteractiveHistoryService } from 'vs/workbench/contrib/interactive/browser/interactiveHistoryService';
@@ -113,8 +113,10 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
113113
this._register(this.primary.onDidChangeCapabilities(() => this._onDidChangeCapabilities.fire()));
114114
}
115115

116-
override isDirty() {
117-
return false;
116+
override get capabilities(): EditorInputCapabilities {
117+
return EditorInputCapabilities.Untitled
118+
| EditorInputCapabilities.Readonly
119+
| EditorInputCapabilities.Scratchpad;
118120
}
119121

120122
private async _resolveEditorModel() {

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

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { Iterable } from 'vs/base/common/iterator';
77
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
8-
import { Schemas } from 'vs/base/common/network';
98
import { isEqual } from 'vs/base/common/resources';
109
import { ThemeIcon } from 'vs/base/common/themables';
1110
import { URI, UriComponents } from 'vs/base/common/uri';
@@ -598,7 +597,7 @@ registerAction2(class InterruptNotebook extends CancelNotebook {
598597
when: ContextKeyExpr.and(
599598
NOTEBOOK_HAS_SOMETHING_RUNNING,
600599
NOTEBOOK_INTERRUPTIBLE_KERNEL,
601-
ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive)
600+
ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive')
602601
),
603602
group: 'navigation/execute'
604603
}
@@ -641,7 +640,7 @@ registerAction2(class RevealRunningCellAction extends NotebookAction {
641640
id: MenuId.InteractiveToolbar,
642641
when: ContextKeyExpr.and(
643642
NOTEBOOK_HAS_RUNNING_CELL,
644-
ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive)
643+
ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive')
645644
),
646645
group: 'navigation',
647646
order: 10

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { Schemas } from 'vs/base/common/network';
77
import { IDisposable, Disposable, DisposableStore, dispose } from 'vs/base/common/lifecycle';
88
import { parse } from 'vs/base/common/marshalling';
9-
import { isEqual } from 'vs/base/common/resources';
9+
import { extname, isEqual } from 'vs/base/common/resources';
1010
import { assertType } from 'vs/base/common/types';
1111
import { URI } from 'vs/base/common/uri';
1212
import { toFormattedString } from 'vs/base/common/jsonFormatter';
@@ -580,7 +580,7 @@ class NotebookEditorManager implements IWorkbenchContribution {
580580
private _openMissingDirtyNotebookEditors(models: IResolvedNotebookEditorModel[]): void {
581581
const result: IResourceEditorInput[] = [];
582582
for (const model of models) {
583-
if (model.isDirty() && !this._editorService.isOpened({ resource: model.resource, typeId: NotebookEditorInput.ID, editorId: model.viewType }) && model.resource.scheme !== Schemas.vscodeInteractive) {
583+
if (model.isDirty() && !this._editorService.isOpened({ resource: model.resource, typeId: NotebookEditorInput.ID, editorId: model.viewType }) && extname(model.resource) !== '.interactive') {
584584
result.push({
585585
resource: model.resource,
586586
options: { inactive: true, preserveFocus: true, pinned: true, override: model.viewType }

src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getExtensionForMimeType } from 'vs/base/common/mime';
1313
import { FileAccess, Schemas } from 'vs/base/common/network';
1414
import { equals } from 'vs/base/common/objects';
1515
import { isMacintosh, isWeb } from 'vs/base/common/platform';
16-
import { dirname, isEqual, joinPath } from 'vs/base/common/resources';
16+
import { dirname, extname, isEqual, joinPath } from 'vs/base/common/resources';
1717
import { URI } from 'vs/base/common/uri';
1818
import * as UUID from 'vs/base/common/uuid';
1919
import { TokenizationRegistry } from 'vs/editor/common/languages';
@@ -513,7 +513,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
513513
}
514514

515515
private getNotebookBaseUri() {
516-
if (this.documentUri.scheme === Schemas.untitled || this.documentUri.scheme === Schemas.vscodeInteractive) {
516+
if (this.documentUri.scheme === Schemas.untitled) {
517517
const folder = this.workspaceContextService.getWorkspaceFolder(this.documentUri);
518518
if (folder) {
519519
return folder.uri;
@@ -1031,7 +1031,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
10311031
return;
10321032
}
10331033

1034-
const defaultDir = this.documentUri.scheme === Schemas.vscodeInteractive ?
1034+
const defaultDir = extname(this.documentUri) === '.interactive' ?
10351035
this.workspaceContextService.getWorkspace().folders[0]?.uri ?? await this.fileDialogService.defaultFilePath() :
10361036
dirname(this.documentUri);
10371037
let defaultName: string;

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ 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';
1314
import { assertType } from 'vs/base/common/types';
1415
import { URI } from 'vs/base/common/uri';
1516
import { IRevertOptions, ISaveOptions, IUntypedEditorInput } from 'vs/workbench/common/editor';
@@ -40,6 +41,7 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
4041

4142
private _workingCopy?: IStoredFileWorkingCopy<NotebookFileWorkingCopyModel> | IUntitledFileWorkingCopy<NotebookFileWorkingCopyModel>;
4243
private readonly _workingCopyListeners = this._register(new DisposableStore());
44+
private readonly scratchPad: boolean;
4345

4446
constructor(
4547
readonly resource: URI,
@@ -51,16 +53,7 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
5153
) {
5254
super();
5355

54-
if (this.viewType === 'interactive') {
55-
lifecycleService.onBeforeShutdown(async e => e.veto(this.onBeforeShutdown(), 'veto.InteractiveWindow'));
56-
}
57-
}
58-
59-
private async onBeforeShutdown() {
60-
if (this._workingCopy?.isDirty()) {
61-
await this._workingCopy.save();
62-
}
63-
return false;
56+
this.scratchPad = viewType === 'interactive';
6457
}
6558

6659
override dispose(): void {
@@ -126,7 +119,7 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
126119
if (this._hasAssociatedFilePath) {
127120
this._workingCopy = await this._workingCopyManager.resolve({ associatedResource: this.resource });
128121
} else {
129-
this._workingCopy = await this._workingCopyManager.resolve({ untitledResource: this.resource });
122+
this._workingCopy = await this._workingCopyManager.resolve({ untitledResource: this.resource, isScratchpad: this.scratchPad });
130123
}
131124
} else {
132125
this._workingCopy = await this._workingCopyManager.resolve(this.resource, options?.forceReadFromFile ? { reload: { async: false, force: true } } : undefined);
@@ -291,7 +284,7 @@ export class NotebookFileWorkingCopyModelFactory implements IStoredFileWorkingCo
291284
metadata: {},
292285
cells: []
293286
};
294-
if (resource.scheme !== Schemas.vscodeInteractive) {
287+
if (extname(resource) !== '.interactive') {
295288
const bytes = await streamToBuffer(stream);
296289
data = await info.serializer.dataToNotebook(bytes);
297290
}

0 commit comments

Comments
 (0)