Skip to content

Commit

Permalink
use scratchpad for IW working copy
Browse files Browse the repository at this point in the history
This reverts commit f5e494e.
  • Loading branch information
amunger committed Jun 9, 2023
1 parent 06ae4b6 commit 194c951
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 107 deletions.
1 change: 0 additions & 1 deletion src/vs/base/common/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export namespace Schemas {
export const vscodeNotebookCell = 'vscode-notebook-cell';
export const vscodeNotebookCellMetadata = 'vscode-notebook-cell-metadata';
export const vscodeNotebookCellOutput = 'vscode-notebook-cell-output';
export const vscodeInteractive = 'vscode-interactive';
export const vscodeInteractiveInput = 'vscode-interactive-input';

export const vscodeSettings = 'vscode-settings';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import { IInteractiveDocumentService, InteractiveDocumentService } from 'vs/work
import { InteractiveEditor } from 'vs/workbench/contrib/interactive/browser/interactiveEditor';
import { InteractiveEditorInput } from 'vs/workbench/contrib/interactive/browser/interactiveEditorInput';
import { IInteractiveHistoryService, InteractiveHistoryService } from 'vs/workbench/contrib/interactive/browser/interactiveHistoryService';
import { InteractiveWindowFileSystem } from 'vs/workbench/contrib/interactive/browser/interactiveWindowFileSystem';
import { NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
import { INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget';
Expand Down Expand Up @@ -96,9 +95,6 @@ export class InteractiveDocumentContribution extends Disposable implements IWork
cellContentMetadata: {}
};

const interactiveWindowFS = new InteractiveWindowFileSystem();
this._register(fileService.registerProvider(Schemas.vscodeInteractive, interactiveWindowFS));

const serializer: INotebookSerializer = {
options: contentOptions,
dataToNotebook: async (data: VSBuffer): Promise<NotebookData> => {
Expand Down Expand Up @@ -205,7 +201,9 @@ export class InteractiveDocumentContribution extends Disposable implements IWork
priority: RegisteredEditorPriority.exclusive
},
{
canSupportResource: uri => uri.scheme === Schemas.vscodeInteractive || (uri.scheme === Schemas.vscodeNotebookCell && extname(uri) === '.interactive'),
canSupportResource: uri =>
(uri.scheme === Schemas.untitled && extname(uri) === '.interactive') ||
(uri.scheme === Schemas.vscodeNotebookCell && extname(uri) === '.interactive'),
singlePerResource: true
},
{
Expand Down Expand Up @@ -371,7 +369,7 @@ registerAction2(class extends Action2 {
preserveFocus: typeof showOptions !== 'number' ? (showOptions?.preserveFocus ?? false) : false
};

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

counter++;
Expand Down Expand Up @@ -435,7 +433,7 @@ registerAction2(class extends Action2 {
category: interactiveWindowCategory,
keybinding: {
// when: NOTEBOOK_CELL_LIST_FOCUSED,
when: ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
when: ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
primary: KeyMod.WinCtrl | KeyCode.Enter,
win: {
primary: KeyMod.CtrlCmd | KeyCode.Enter
Expand Down Expand Up @@ -469,15 +467,14 @@ registerAction2(class extends Action2 {
const notebookEditorService = accessor.get(INotebookEditorService);
let editorControl: { notebookEditor: NotebookEditorWidget | undefined; codeEditor: CodeEditorWidget } | undefined;
if (context) {
if (context.scheme === Schemas.vscodeInteractive) {
const resourceUri = URI.revive(context);
const editors = editorService.findEditors(resourceUri).filter(id => id.editor instanceof InteractiveEditorInput && id.editor.resource?.toString() === resourceUri.toString());
if (editors.length) {
const editorInput = editors[0].editor as InteractiveEditorInput;
const currentGroup = editors[0].groupId;
const editor = await editorService.openEditor(editorInput, currentGroup);
editorControl = editor?.getControl() as { notebookEditor: NotebookEditorWidget | undefined; codeEditor: CodeEditorWidget } | undefined;
}
const resourceUri = URI.revive(context);
const editors = editorService.findEditors(resourceUri)
.filter(id => id.editor instanceof InteractiveEditorInput && id.editor.resource?.toString() === resourceUri.toString());
if (editors.length) {
const editorInput = editors[0].editor as InteractiveEditorInput;
const currentGroup = editors[0].groupId;
const editor = await editorService.openEditor(editorInput, currentGroup);
editorControl = editor?.getControl() as { notebookEditor: NotebookEditorWidget | undefined; codeEditor: CodeEditorWidget } | undefined;
}
}
else {
Expand Down Expand Up @@ -578,7 +575,7 @@ registerAction2(class extends Action2 {
f1: false,
keybinding: {
when: ContextKeyExpr.and(
ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
INTERACTIVE_INPUT_CURSOR_BOUNDARY.notEqualsTo('bottom'),
INTERACTIVE_INPUT_CURSOR_BOUNDARY.notEqualsTo('none'),
SuggestContext.Visible.toNegated()
Expand Down Expand Up @@ -617,7 +614,7 @@ registerAction2(class extends Action2 {
f1: false,
keybinding: {
when: ContextKeyExpr.and(
ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
INTERACTIVE_INPUT_CURSOR_BOUNDARY.notEqualsTo('top'),
INTERACTIVE_INPUT_CURSOR_BOUNDARY.notEqualsTo('none'),
SuggestContext.Visible.toNegated()
Expand Down Expand Up @@ -654,7 +651,7 @@ registerAction2(class extends Action2 {
id: 'interactive.scrollToTop',
title: localize('interactiveScrollToTop', 'Scroll to Top'),
keybinding: {
when: ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
when: ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
primary: KeyMod.CtrlCmd | KeyCode.Home,
mac: { primary: KeyMod.CtrlCmd | KeyCode.UpArrow },
weight: KeybindingWeight.WorkbenchContrib
Expand Down Expand Up @@ -683,7 +680,7 @@ registerAction2(class extends Action2 {
id: 'interactive.scrollToBottom',
title: localize('interactiveScrollToBottom', 'Scroll to Bottom'),
keybinding: {
when: ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
when: ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
primary: KeyMod.CtrlCmd | KeyCode.End,
mac: { primary: KeyMod.CtrlCmd | KeyCode.DownArrow },
weight: KeybindingWeight.WorkbenchContrib
Expand Down Expand Up @@ -750,9 +747,9 @@ registerAction2(class extends Action2 {
category: interactiveWindowCategory,
menu: {
id: MenuId.CommandPalette,
when: ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
when: ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
},
precondition: ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive),
precondition: ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive'),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { isEqual } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { IResolvedTextEditorModel, ITextModelService } from 'vs/editor/common/services/resolverService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IUntypedEditorInput } from 'vs/workbench/common/editor';
import { EditorInputCapabilities, IUntypedEditorInput } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { IInteractiveDocumentService } from 'vs/workbench/contrib/interactive/browser/interactiveDocumentService';
import { IInteractiveHistoryService } from 'vs/workbench/contrib/interactive/browser/interactiveHistoryService';
Expand Down Expand Up @@ -113,8 +113,10 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
this._register(this.primary.onDidChangeCapabilities(() => this._onDidChangeCapabilities.fire()));
}

override isDirty() {
return false;
override get capabilities(): EditorInputCapabilities {
return EditorInputCapabilities.Untitled
| EditorInputCapabilities.Readonly
| EditorInputCapabilities.Scratchpad;
}

private async _resolveEditorModel() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import { Iterable } from 'vs/base/common/iterator';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { Schemas } from 'vs/base/common/network';
import { isEqual } from 'vs/base/common/resources';
import { ThemeIcon } from 'vs/base/common/themables';
import { URI, UriComponents } from 'vs/base/common/uri';
Expand Down Expand Up @@ -598,7 +597,7 @@ registerAction2(class InterruptNotebook extends CancelNotebook {
when: ContextKeyExpr.and(
NOTEBOOK_HAS_SOMETHING_RUNNING,
NOTEBOOK_INTERRUPTIBLE_KERNEL,
ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive)
ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive')
),
group: 'navigation/execute'
}
Expand Down Expand Up @@ -641,7 +640,7 @@ registerAction2(class RevealRunningCellAction extends NotebookAction {
id: MenuId.InteractiveToolbar,
when: ContextKeyExpr.and(
NOTEBOOK_HAS_RUNNING_CELL,
ContextKeyExpr.equals('resourceScheme', Schemas.vscodeInteractive)
ContextKeyExpr.equals('activeEditor', 'workbench.editor.interactive')
),
group: 'navigation',
order: 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Schemas } from 'vs/base/common/network';
import { IDisposable, Disposable, DisposableStore, dispose } from 'vs/base/common/lifecycle';
import { parse } from 'vs/base/common/marshalling';
import { isEqual } from 'vs/base/common/resources';
import { extname, isEqual } from 'vs/base/common/resources';
import { assertType } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { toFormattedString } from 'vs/base/common/jsonFormatter';
Expand Down Expand Up @@ -580,7 +580,7 @@ class NotebookEditorManager implements IWorkbenchContribution {
private _openMissingDirtyNotebookEditors(models: IResolvedNotebookEditorModel[]): void {
const result: IResourceEditorInput[] = [];
for (const model of models) {
if (model.isDirty() && !this._editorService.isOpened({ resource: model.resource, typeId: NotebookEditorInput.ID, editorId: model.viewType }) && model.resource.scheme !== Schemas.vscodeInteractive) {
if (model.isDirty() && !this._editorService.isOpened({ resource: model.resource, typeId: NotebookEditorInput.ID, editorId: model.viewType }) && extname(model.resource) !== '.interactive') {
result.push({
resource: model.resource,
options: { inactive: true, preserveFocus: true, pinned: true, override: model.viewType }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getExtensionForMimeType } from 'vs/base/common/mime';
import { FileAccess, Schemas } from 'vs/base/common/network';
import { equals } from 'vs/base/common/objects';
import { isMacintosh, isWeb } from 'vs/base/common/platform';
import { dirname, isEqual, joinPath } from 'vs/base/common/resources';
import { dirname, extname, isEqual, joinPath } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import * as UUID from 'vs/base/common/uuid';
import { TokenizationRegistry } from 'vs/editor/common/languages';
Expand Down Expand Up @@ -513,7 +513,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
}

private getNotebookBaseUri() {
if (this.documentUri.scheme === Schemas.untitled || this.documentUri.scheme === Schemas.vscodeInteractive) {
if (this.documentUri.scheme === Schemas.untitled) {
const folder = this.workspaceContextService.getWorkspaceFolder(this.documentUri);
if (folder) {
return folder.uri;
Expand Down Expand Up @@ -1031,7 +1031,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
return;
}

const defaultDir = this.documentUri.scheme === Schemas.vscodeInteractive ?
const defaultDir = extname(this.documentUri) === '.interactive' ?
this.workspaceContextService.getWorkspace().folders[0]?.uri ?? await this.fileDialogService.defaultFilePath() :
dirname(this.documentUri);
let defaultName: string;
Expand Down
17 changes: 5 additions & 12 deletions src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Emitter, Event } from 'vs/base/common/event';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { filter } from 'vs/base/common/objects';
import { extname } from 'vs/base/common/resources';
import { assertType } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { IRevertOptions, ISaveOptions, IUntypedEditorInput } from 'vs/workbench/common/editor';
Expand Down Expand Up @@ -40,6 +41,7 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE

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

constructor(
readonly resource: URI,
Expand All @@ -51,16 +53,7 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
) {
super();

if (this.viewType === 'interactive') {
lifecycleService.onBeforeShutdown(async e => e.veto(this.onBeforeShutdown(), 'veto.InteractiveWindow'));
}
}

private async onBeforeShutdown() {
if (this._workingCopy?.isDirty()) {
await this._workingCopy.save();
}
return false;
this.scratchPad = viewType === 'interactive';
}

override dispose(): void {
Expand Down Expand Up @@ -126,7 +119,7 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
if (this._hasAssociatedFilePath) {
this._workingCopy = await this._workingCopyManager.resolve({ associatedResource: this.resource });
} else {
this._workingCopy = await this._workingCopyManager.resolve({ untitledResource: this.resource });
this._workingCopy = await this._workingCopyManager.resolve({ untitledResource: this.resource, isScratchpad: this.scratchPad });
}
} else {
this._workingCopy = await this._workingCopyManager.resolve(this.resource, options?.forceReadFromFile ? { reload: { async: false, force: true } } : undefined);
Expand Down Expand Up @@ -291,7 +284,7 @@ export class NotebookFileWorkingCopyModelFactory implements IStoredFileWorkingCo
metadata: {},
cells: []
};
if (resource.scheme !== Schemas.vscodeInteractive) {
if (extname(resource) !== '.interactive') {
const bytes = await streamToBuffer(stream);
data = await info.serializer.dataToNotebook(bytes);
}
Expand Down

0 comments on commit 194c951

Please sign in to comment.