editors - make `resource` a required property of untitled untyped inputs (#127792)

上级 d6cfa5f8
......@@ -173,6 +173,7 @@ export class ResourcesDropHandler {
const targetGroup = resolveTargetGroup();
await this.editorService.openEditors(editors.map(editor => ({
...editor,
resource: editor.resource,
options: {
...editor.options,
pinned: true,
......
......@@ -10,7 +10,7 @@ import { onDidChangeFullscreen, isFullscreen } from 'vs/base/browser/browser';
import { IWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/common/workingCopyBackup';
import { Registry } from 'vs/platform/registry/common/platform';
import { isWindows, isLinux, isMacintosh, isWeb, isNative, isIOS } from 'vs/base/common/platform';
import { IResourceDiffEditorInput, IUntypedEditorInput, pathsToEditors } from 'vs/workbench/common/editor';
import { IUntypedEditorInput, pathsToEditors } from 'vs/workbench/common/editor';
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
import { PanelPart } from 'vs/workbench/browser/parts/panel/panelPart';
......@@ -596,12 +596,12 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
this.state.editor.restoreEditors = !!forceRestoreEditors || initialFilesToOpen === undefined;
// Files to open, diff or create
if (initialFilesToOpen !== undefined) {
if (initialFilesToOpen) {
// Files to diff is exclusive
return pathsToEditors(initialFilesToOpen.filesToDiff, fileService).then(filesToDiff => {
if (filesToDiff.length === 2) {
const diffEditorInput: IResourceDiffEditorInput[] = [{
const diffEditorInput: IUntypedEditorInput[] = [{
original: { resource: filesToDiff[0].resource },
modified: { resource: filesToDiff[1].resource },
options: { pinned: true },
......@@ -627,7 +627,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
return []; // do not open any empty untitled file if we have backups to restore
}
return [Object.create(null)]; // open empty untitled file
return [{ resource: undefined }]; // open empty untitled file
});
}
......
......@@ -292,6 +292,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
EventHelper.stop(e);
this.editorService.openEditor({
resource: undefined,
forceUntitled: true,
options: {
pinned: true,
......
......@@ -235,6 +235,7 @@ export class TabsTitleControl extends TitleControl {
EventHelper.stop(e);
this.editorService.openEditor({
resource: undefined,
forceUntitled: true,
options: {
pinned: true,
......
......@@ -292,7 +292,7 @@ export interface IUntitledTextResourceEditorInput extends IBaseTextResourceEdito
* force use the provided resource as associated path. As such, the resource will be used when saving
* the untitled editor.
*/
readonly resource?: URI;
readonly resource: URI | undefined;
}
export interface IResourceDiffEditorInput extends IBaseResourceEditorInput {
......
......@@ -141,7 +141,7 @@ export class DiffEditorInput extends SideBySideEditorInput {
const originalResourceEditorInput = this.secondary.toUntyped(group, context);
const modifiedResourceEditorInput = this.primary.toUntyped(group, context);
if (originalResourceEditorInput && modifiedResourceEditorInput) {
if (originalResourceEditorInput && modifiedResourceEditorInput && !isResourceDiffEditorInput(originalResourceEditorInput) && !isResourceDiffEditorInput(modifiedResourceEditorInput)) {
return {
label: this.name,
description: this.description,
......
......@@ -26,7 +26,7 @@ class InspectKeyMap extends EditorAction {
const keybindingService = accessor.get(IKeybindingService);
const editorService = accessor.get(IEditorService);
editorService.openEditor({ contents: keybindingService._dumpDebugInfo(), options: { pinned: true } });
editorService.openEditor({ resource: undefined, contents: keybindingService._dumpDebugInfo(), options: { pinned: true } });
}
}
......@@ -47,7 +47,7 @@ class InspectKeyMapJSON extends Action2 {
const editorService = accessor.get(IEditorService);
const keybindingService = accessor.get(IKeybindingService);
await editorService.openEditor({ contents: keybindingService._dumpDebugInfoJSON(), options: { pinned: true } });
await editorService.openEditor({ resource: undefined, contents: keybindingService._dumpDebugInfoJSON(), options: { pinned: true } });
}
}
......
......@@ -683,9 +683,9 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
const editorGroupsService = accessor.get(IEditorGroupsService);
const group = editorGroupsService.activeGroup;
await editorService.openEditor({ options: { override: args.viewType, pinned: true } }, group);
await editorService.openEditor({ resource: undefined, options: { override: args.viewType, pinned: true } }, group);
} else {
await editorService.openEditor({ options: { pinned: true } }); // untitled are always pinned
await editorService.openEditor({ resource: undefined, options: { pinned: true } }); // untitled are always pinned
}
}
});
......
......@@ -147,7 +147,7 @@ suite('Files - TextFileEditorTracker', () => {
test('dirty untitled text file model opens as editor', async function () {
const accessor = await createTracker();
const untitledTextEditor = accessor.editorService.createEditorInput({ forceUntitled: true }) as UntitledTextEditorInput;
const untitledTextEditor = accessor.editorService.createEditorInput({ resource: undefined, forceUntitled: true }) as UntitledTextEditorInput;
const model = disposables.add(await untitledTextEditor.resolve());
assert.ok(!accessor.editorService.isOpened(untitledTextEditor));
......
......@@ -332,7 +332,7 @@ class GenerateColorThemeAction extends Action {
}, null, '\t');
contents = contents.replace(/\"__/g, '//"');
return this.editorService.openEditor({ contents, mode: 'jsonc', options: { pinned: true } });
return this.editorService.openEditor({ resource: undefined, contents, mode: 'jsonc', options: { pinned: true } });
}
}
......
......@@ -19,7 +19,7 @@ import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/work
import { applyZoom } from 'vs/platform/windows/electron-sandbox/window';
import { setFullscreen, getZoomLevel } from 'vs/base/browser/browser';
import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IBaseResourceEditorInput, IResourceEditorInput } from 'vs/platform/editor/common/editor';
import { IResourceEditorInput } from 'vs/platform/editor/common/editor';
import { ipcRenderer } from 'vs/base/parts/sandbox/electron-sandbox/globals';
import { env } from 'vs/base/common/process';
import { IWorkspaceEditingService } from 'vs/workbench/services/workspaces/common/workspaceEditing';
......@@ -631,7 +631,7 @@ export class NativeWindow extends Disposable {
}
private async onOpenFiles(request: INativeOpenFileRequest): Promise<void> {
const inputs: IUntypedEditorInput[] = [];
const inputs: Array<IResourceEditorInput | IUntitledTextResourceEditorInput> = [];
const diffMode = !!(request.filesToDiff && (request.filesToDiff.length === 2));
if (!diffMode && request.filesToOpenOrCreate) {
......@@ -664,7 +664,7 @@ export class NativeWindow extends Disposable {
}
private async openResources(resources: Array<IResourceEditorInput | IUntitledTextResourceEditorInput>, diffMode: boolean): Promise<unknown> {
const editors: IBaseResourceEditorInput[] = [];
const editors: IUntypedEditorInput[] = [];
// In diffMode we open 2 resources as diff
if (diffMode && resources.length === 2 && resources[0].resource && resources[1].resource) {
......
......@@ -515,6 +515,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
//#region openEditor()
openEditor(editor: IEditorInput, options?: IEditorOptions, group?: OpenInEditorGroup): Promise<IEditorPane | undefined>;
openEditor(editor: IUntypedEditorInput, group?: OpenInEditorGroup): Promise<IEditorPane | undefined>;
openEditor(editor: IResourceEditorInput, group?: OpenInEditorGroup): Promise<IEditorPane | undefined>;
openEditor(editor: ITextResourceEditorInput | IUntitledTextResourceEditorInput, group?: OpenInEditorGroup): Promise<ITextEditorPane | undefined>;
openEditor(editor: IResourceDiffEditorInput, group?: OpenInEditorGroup): Promise<ITextDiffEditorPane | undefined>;
......@@ -642,8 +643,10 @@ export class EditorService extends Disposable implements EditorServiceImpl {
return [group, activation];
}
private doFindTargetGroup(editor: IEditorInputWithOptions | IUntypedEditorInput, preferredGroup: OpenInEditorGroup | undefined): IEditorGroup {
private doFindTargetGroup(input: IEditorInputWithOptions | IUntypedEditorInput, preferredGroup: OpenInEditorGroup | undefined): IEditorGroup {
let group: IEditorGroup | undefined;
let editor = isEditorInputWithOptions(input) ? input.editor : input;
let options = input.options;
// Group: Instance of Group
if (preferredGroup && typeof preferredGroup !== 'number') {
......@@ -661,11 +664,11 @@ export class EditorService extends Disposable implements EditorServiceImpl {
}
// Group: Unspecified without a specific index to open
else if (!editor.options || typeof editor.options.index !== 'number') {
else if (!options || typeof options.index !== 'number') {
const groupsByLastActive = this.editorGroupService.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
// Respect option to reveal an editor if it is already visible in any group
if (editor.options?.revealIfVisible) {
if (options?.revealIfVisible) {
for (const lastActiveGroup of groupsByLastActive) {
if (lastActiveGroup.isActive(editor)) {
group = lastActiveGroup;
......@@ -677,7 +680,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
// Respect option to reveal an editor if it is open (not necessarily visible)
// Still prefer to reveal an editor in a group where the editor is active though.
if (!group) {
if (editor.options?.revealIfOpened || this.configurationService.getValue<boolean>('workbench.editor.revealIfOpen')) {
if (options?.revealIfOpened || this.configurationService.getValue<boolean>('workbench.editor.revealIfOpen')) {
let groupWithInputActive: IEditorGroup | undefined = undefined;
let groupWithInputOpened: IEditorGroup | undefined = undefined;
......@@ -728,6 +731,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
openEditors(editors: IEditorInputWithOptions[], group?: OpenInEditorGroup, options?: IOpenEditorsOptions): Promise<IEditorPane[]>;
openEditors(editors: IUntypedEditorInput[], group?: OpenInEditorGroup, options?: IOpenEditorsOptions): Promise<IEditorPane[]>;
openEditors(editors: Array<IEditorInputWithOptions | IUntypedEditorInput>, group?: OpenInEditorGroup, options?: IOpenEditorsOptions): Promise<IEditorPane[]>;
async openEditors(editors: Array<IEditorInputWithOptions | IUntypedEditorInput>, preferredGroup?: OpenInEditorGroup, options?: IOpenEditorsOptions): Promise<IEditorPane[]> {
// Pass all editors to trust service to determine if
......
......@@ -175,6 +175,7 @@ export interface IEditorService {
openEditor(editor: IResourceEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditorPane | undefined>;
openEditor(editor: ITextResourceEditorInput | IUntitledTextResourceEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextEditorPane | undefined>;
openEditor(editor: IResourceDiffEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextDiffEditorPane | undefined>;
openEditor(editor: IUntypedEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditorPane | undefined>;
/**
* Open editors in an editor group.
......
......@@ -713,7 +713,7 @@ suite('EditorService', () => {
{
// untyped untitled editor, no options, no group
{
let untypedEditor: IUntitledTextResourceEditorInput = { options: { override: TEST_EDITOR_INPUT_ID } };
let untypedEditor: IUntitledTextResourceEditorInput = { resource: undefined, options: { override: TEST_EDITOR_INPUT_ID } };
let pane = await openEditor(untypedEditor);
assert.strictEqual(pane?.group, rootGroup);
......@@ -733,7 +733,7 @@ suite('EditorService', () => {
// untyped untitled editor, no options, SIDE_GROUP
{
let untypedEditor: IUntitledTextResourceEditorInput = { options: { override: TEST_EDITOR_INPUT_ID } };
let untypedEditor: IUntitledTextResourceEditorInput = { resource: undefined, options: { override: TEST_EDITOR_INPUT_ID } };
let pane = await openEditor(untypedEditor, SIDE_GROUP);
assert.strictEqual(accessor.editorGroupService.groups.length, 2);
......@@ -780,7 +780,7 @@ suite('EditorService', () => {
// untyped untitled editor, options (sticky: true, preserveFocus: true), no group
{
let untypedEditor: IUntitledTextResourceEditorInput = { options: { sticky: true, preserveFocus: true, override: TEST_EDITOR_INPUT_ID } };
let untypedEditor: IUntitledTextResourceEditorInput = { resource: undefined, options: { sticky: true, preserveFocus: true, override: TEST_EDITOR_INPUT_ID } };
let pane = await openEditor(untypedEditor);
assert.strictEqual(pane?.group, rootGroup);
......@@ -1301,7 +1301,7 @@ suite('EditorService', () => {
assert.strictEqual(contentInput.getPreferredMode(), 'text');
// Untyped Input (untitled)
input = service.createEditorInput({ options: { selection: { startLineNumber: 1, startColumn: 1 } } });
input = service.createEditorInput({ resource: undefined, options: { selection: { startLineNumber: 1, startColumn: 1 } } });
assert(input instanceof UntitledTextEditorInput);
// Untyped Input (untitled with contents)
......@@ -1313,7 +1313,7 @@ suite('EditorService', () => {
assert.strictEqual(model.textEditorModel?.getValue(), 'Hello Untitled');
// Untyped Input (untitled with mode)
input = service.createEditorInput({ mode, options: { selection: { startLineNumber: 1, startColumn: 1 } } });
input = service.createEditorInput({ resource: undefined, mode, options: { selection: { startLineNumber: 1, startColumn: 1 } } });
assert(input instanceof UntitledTextEditorInput);
model = await input.resolve() as UntitledTextEditorModel;
assert.strictEqual(model.getMode(), mode);
......@@ -1725,7 +1725,7 @@ suite('EditorService', () => {
const [, service] = await createEditorService();
// Open untitled input
let editor = await service.openEditor({});
let editor = await service.openEditor({ resource: undefined });
assert.strictEqual(service.activeEditorPane, editor);
assert.strictEqual(service.activeTextEditorControl, editor?.getControl());
......
......@@ -452,7 +452,7 @@ registerAction2(class MeasureExtHostLatencyAction extends Action2 {
const editorService = accessor.get(IEditorService);
const measurements = await Promise.all(getLatencyTestProviders().map(provider => provider.measure()));
editorService.openEditor({ contents: measurements.map(MeasureExtHostLatencyAction._print).join('\n\n'), options: { pinned: true } });
editorService.openEditor({ resource: undefined, contents: measurements.map(MeasureExtHostLatencyAction._print).join('\n\n'), options: { pinned: true } });
}
private static _print(m: ExtHostLatencyResult | null): string {
......
......@@ -108,7 +108,7 @@ suite('WorkingCopyBackupTracker (browser)', function () {
return { accessor, part, tracker, workingCopyBackupService: workingCopyBackupService, instantiationService, cleanup: () => disposables.dispose() };
}
async function untitledBackupTest(untitled: IUntitledTextResourceEditorInput = {}): Promise<void> {
async function untitledBackupTest(untitled: IUntitledTextResourceEditorInput = { resource: undefined }): Promise<void> {
const { accessor, cleanup, workingCopyBackupService } = await createTracker();
const untitledTextEditor = (await accessor.editorService.openEditor(untitled))?.input as UntitledTextEditorInput;
......@@ -137,7 +137,7 @@ suite('WorkingCopyBackupTracker (browser)', function () {
});
test('Track backups (untitled with initial contents)', function () {
return untitledBackupTest({ contents: 'Foo Bar' });
return untitledBackupTest({ resource: undefined, contents: 'Foo Bar' });
});
test('Track backups (custom)', async function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册