From ff3d5bb4911dbfd3f3f2851d352132bea32a71e3 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 22 Apr 2022 08:54:40 +0200 Subject: [PATCH] debt - adopt new `options` support in `IPath` cc @rebornix --- src/vs/platform/window/common/window.ts | 48 +++++++----------- .../electron-main/windowsMainService.ts | 49 +++++++++++++------ src/vs/workbench/browser/layout.ts | 21 +++++--- src/vs/workbench/browser/web.api.ts | 28 ++++++----- src/vs/workbench/common/editor.ts | 6 +-- .../environment/browser/environmentService.ts | 7 ++- .../host/browser/browserHostService.ts | 7 ++- 7 files changed, 92 insertions(+), 74 deletions(-) diff --git a/src/vs/platform/window/common/window.ts b/src/vs/platform/window/common/window.ts index dfa18a3fcda..2c9591a2bec 100644 --- a/src/vs/platform/window/common/window.ts +++ b/src/vs/platform/window/common/window.ts @@ -168,54 +168,44 @@ export function getTitleBarStyle(configurationService: IConfigurationService): ' return isLinux ? 'native' : 'custom'; // default to custom on all macOS and Windows } -export interface IPath extends IPathData { +export interface IPath extends IPathData { - // the file path to open within the instance + /** + * The file path to open within the instance + */ fileUri?: URI; } -export interface IPathData { +export interface IPathData { - // the file path to open within the instance + /** + * The file path to open within the instance + */ readonly fileUri?: UriComponents; /** * Optional editor options to apply in the file */ - readonly options?: IEditorOptions; + readonly options?: T; /** - * An optional selection to apply in the file - * - * @deprecated Use options instead + * A hint that the file exists. if true, the + * file exists, if false it does not. with + * `undefined` the state is unknown. */ - readonly selection?: { - readonly startLineNumber: number; - readonly startColumn: number; - readonly endLineNumber?: number; - readonly endColumn?: number; - }; - - // a hint that the file exists. if true, the - // file exists, if false it does not. with - // `undefined` the state is unknown. readonly exists?: boolean; - // a hint about the file type of this path. - // with `undefined` the type is unknown. + /** + * A hint about the file type of this path. + * with `undefined` the type is unknown. + */ readonly type?: FileType; - // Specifies if the file should be only be opened - // if it exists - readonly openOnlyIfExists?: boolean; - /** - * Specifies an optional id to override the editor - * used to edit the resource, e.g. custom editor. - * - * @deprecated Use options.override instead + * Specifies if the file should be only be opened + * if it exists. */ - readonly editorOverrideId?: string; + readonly openOnlyIfExists?: boolean; } export interface IPathsToWaitFor extends IPathsToWaitForData { diff --git a/src/vs/platform/windows/electron-main/windowsMainService.ts b/src/vs/platform/windows/electron-main/windowsMainService.ts index 1dbfaaf9df9..77294070103 100644 --- a/src/vs/platform/windows/electron-main/windowsMainService.ts +++ b/src/vs/platform/windows/electron-main/windowsMainService.ts @@ -50,6 +50,7 @@ import { IWorkspacesHistoryMainService } from 'vs/platform/workspaces/electron-m import { IWorkspacesManagementMainService } from 'vs/platform/workspaces/electron-main/workspacesManagementMainService'; import { ICodeWindow, UnloadReason } from 'vs/platform/window/electron-main/window'; import { IThemeMainService } from 'vs/platform/theme/electron-main/themeMainService'; +import { IEditorOptions, ITextEditorOptions } from 'vs/platform/editor/common/editor'; //#region Helper Interfaces @@ -118,23 +119,33 @@ interface IFilesToOpen { filesToWait?: IPathsToWaitFor; } -interface IPathToOpen extends IPath { +interface IPathToOpen extends IPath { - // the workspace to open + /** + * The workspace to open + */ readonly workspace?: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier; - // whether the path is considered to be transient or not - // for example, a transient workspace should not add to - // the workspaces history and should never restore + /** + * Whether the path is considered to be transient or not + * for example, a transient workspace should not add to + * the workspaces history and should never restore. + */ readonly transient?: boolean; - // the backup path to use + /** + * The backup path to use + */ readonly backupPath?: string; - // the remote authority for the Code instance to open. Undefined if not remote. + /** + * The remote authority for the Code instance to open. Undefined if not remote. + */ readonly remoteAuthority?: string; - // optional label for the recent history + /** + * Optional label for the recent history + */ label?: string; } @@ -916,7 +927,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic return this.doResolveRemoteOpenable(openable, options); } - private doResolveRemoteOpenable(openable: IWindowOpenable, options: IPathResolveOptions): IPathToOpen | undefined { + private doResolveRemoteOpenable(openable: IWindowOpenable, options: IPathResolveOptions): IPathToOpen | undefined { let uri = this.resourceFromOpenable(openable); // use remote authority from vscode @@ -932,7 +943,9 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic return { fileUri: uri.with({ path }), - selection: line ? { startLineNumber: line, startColumn: column || 1 } : undefined, + options: { + selection: line ? { startLineNumber: line, startColumn: column || 1 } : undefined + }, remoteAuthority }; } @@ -961,7 +974,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic return openable.fileUri; } - private doResolveFilePath(path: string, options: IPathResolveOptions): IPathToOpen | undefined { + private doResolveFilePath(path: string, options: IPathResolveOptions): IPathToOpen | undefined { // Extract line/col information from path let lineNumber: number | undefined; @@ -1004,7 +1017,9 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic fileUri: URI.file(path), type: FileType.File, exists: true, - selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined + options: { + selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined + } }; } @@ -1047,7 +1062,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic return undefined; } - private doResolvePathRemote(path: string, options: IPathResolveOptions): IPathToOpen | undefined { + private doResolvePathRemote(path: string, options: IPathResolveOptions): IPathToOpen | undefined { const first = path.charCodeAt(0); const remoteAuthority = options.remoteAuthority; @@ -1081,7 +1096,9 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic if (options.forceOpenWorkspaceAsFile) { return { fileUri: uri, - selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined, + options: { + selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined + }, remoteAuthority: options.remoteAuthority }; } @@ -1093,7 +1110,9 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic else if (options.gotoLineMode || posix.basename(path).indexOf('.') !== -1) { return { fileUri: uri, - selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined, + options: { + selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined + }, remoteAuthority }; } diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index 8ab1929c10f..1309b3de8e1 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -617,17 +617,22 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi return { filesToOpenOrCreate: defaultLayout.editors.map(file => { + const legacyOverride = file.openWith; + const legacySelection = file.selection && file.selection.start && isNumber(file.selection.start.line) ? { + startLineNumber: file.selection.start.line, + startColumn: isNumber(file.selection.start.column) ? file.selection.start.column : 1, + endLineNumber: isNumber(file.selection.end.line) ? file.selection.end.line : undefined, + endColumn: isNumber(file.selection.end.line) ? (isNumber(file.selection.end.column) ? file.selection.end.column : 1) : undefined, + } : undefined; + return { fileUri: URI.revive(file.uri), - selection: file.selection && file.selection.start && isNumber(file.selection.start.line) ? { - startLineNumber: file.selection.start.line, - startColumn: isNumber(file.selection.start.column) ? file.selection.start.column : 1, - endLineNumber: isNumber(file.selection.end.line) ? file.selection.end.line : undefined, - endColumn: isNumber(file.selection.end.line) ? (isNumber(file.selection.end.column) ? file.selection.end.column : 1) : undefined, - } : undefined, openOnlyIfExists: file.openOnlyIfExists, - editorOverrideId: file.openWith, - options: file.options + options: { + selection: legacySelection, + override: legacyOverride, + ...file.options // keep at the end to override legacy selection/override that may be `undefined` + } }; }) }; diff --git a/src/vs/workbench/browser/web.api.ts b/src/vs/workbench/browser/web.api.ts index 9ddbf748e47..effacb4a75f 100644 --- a/src/vs/workbench/browser/web.api.ts +++ b/src/vs/workbench/browser/web.api.ts @@ -561,39 +561,42 @@ export interface IDefaultView { readonly id: string; } +/** + * @deprecated use `IDefaultEditor.options` instead + */ export interface IPosition { readonly line: number; readonly column: number; } +/** + * @deprecated use `IDefaultEditor.options` instead + */ export interface IRange { - - /** - * The start position. It is before or equal to end position. - */ readonly start: IPosition; - - /** - * The end position. It is after or equal to start position. - */ readonly end: IPosition; } export interface IDefaultEditor { + readonly uri: UriComponents; + readonly options?: IEditorOptions; + + readonly openOnlyIfExists?: boolean; + /** - * @deprecated Use options instead + * @deprecated use `options` instead */ readonly selection?: IRange; - readonly openOnlyIfExists?: boolean; + /** - * @deprecated Use options.override instead + * @deprecated use `options.override` instead */ readonly openWith?: string; - readonly options?: IEditorOptions; } export interface IDefaultLayout { + readonly views?: IDefaultView[]; readonly editors?: IDefaultEditor[]; @@ -657,4 +660,3 @@ export interface IDevelopmentOptions { */ readonly enableSmokeTestDriver?: boolean; } - diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 3c6225571ae..b12e6477782 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -1342,11 +1342,7 @@ export async function pathsToEditors(paths: IPathData[] | undefined, fileService const options: IEditorOptions = { ...path.options, - ...{ - selection: exists ? path.selection : undefined - }, - pinned: true, - override: path.editorOverrideId + pinned: true }; let input: IResourceEditorInput | IUntitledTextResourceEditorInput; diff --git a/src/vs/workbench/services/environment/browser/environmentService.ts b/src/vs/workbench/services/environment/browser/environmentService.ts index a5499a1ef74..d41839b87ba 100644 --- a/src/vs/workbench/services/environment/browser/environmentService.ts +++ b/src/vs/workbench/services/environment/browser/environmentService.ts @@ -17,6 +17,7 @@ import { parseLineAndColumnAware } from 'vs/base/common/extpath'; import { LogLevelToString } from 'vs/platform/log/common/log'; import { isUndefined } from 'vs/base/common/types'; import { refineServiceDecorator } from 'vs/platform/instantiation/common/instantiation'; +import { ITextEditorOptions } from 'vs/platform/editor/common/editor'; export const IBrowserWorkbenchEnvironmentService = refineServiceDecorator(IEnvironmentService); @@ -295,7 +296,7 @@ export class BrowserWorkbenchEnvironmentService implements IBrowserWorkbenchEnvi } @memoize - get filesToOpenOrCreate(): IPath[] | undefined { + get filesToOpenOrCreate(): IPath[] | undefined { if (this.payload) { const fileToOpen = this.payload.get('openFile'); if (fileToOpen) { @@ -307,7 +308,9 @@ export class BrowserWorkbenchEnvironmentService implements IBrowserWorkbenchEnvi return [{ fileUri: fileUri.with({ path: pathColumnAware.path }), - selection: !isUndefined(pathColumnAware.line) ? { startLineNumber: pathColumnAware.line, startColumn: pathColumnAware.column || 1 } : undefined + options: { + selection: !isUndefined(pathColumnAware.line) ? { startLineNumber: pathColumnAware.line, startColumn: pathColumnAware.column || 1 } : undefined + } }]; } diff --git a/src/vs/workbench/services/host/browser/browserHostService.ts b/src/vs/workbench/services/host/browser/browserHostService.ts index cdc63895e27..955ba20bddf 100644 --- a/src/vs/workbench/services/host/browser/browserHostService.ts +++ b/src/vs/workbench/services/host/browser/browserHostService.ts @@ -34,6 +34,7 @@ import { isUndefined } from 'vs/base/common/types'; import { isTemporaryWorkspace, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import { Schemas } from 'vs/base/common/network'; +import { ITextEditorOptions } from 'vs/platform/editor/common/editor'; /** * A workspace to open in the workbench can either be: @@ -285,14 +286,16 @@ export class BrowserHostService extends Disposable implements IHostService { // Same Window: open via editor service in current window if (this.shouldReuse(options, true /* file */)) { - let openables: IPathData[] = []; + let openables: IPathData[] = []; // Support: --goto parameter to open on line/col if (options?.gotoLineMode) { const pathColumnAware = parseLineAndColumnAware(openable.fileUri.path); openables = [{ fileUri: openable.fileUri.with({ path: pathColumnAware.path }), - selection: !isUndefined(pathColumnAware.line) ? { startLineNumber: pathColumnAware.line, startColumn: pathColumnAware.column || 1 } : undefined + options: { + selection: !isUndefined(pathColumnAware.line) ? { startLineNumber: pathColumnAware.line, startColumn: pathColumnAware.column || 1 } : undefined + } }]; } else { openables = [openable];