debt - adopt new options support in IPath

cc @rebornix
This commit is contained in:
Benjamin Pasero
2022-04-22 08:54:40 +02:00
parent 72b4be55fa
commit ff3d5bb491
7 changed files with 92 additions and 74 deletions

View File

@@ -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<T = IEditorOptions> extends IPathData<T> {
// the file path to open within the instance
/**
* The file path to open within the instance
*/
fileUri?: URI;
}
export interface IPathData {
export interface IPathData<T = IEditorOptions> {
// 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 {

View File

@@ -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<T = IEditorOptions> extends IPath<T> {
// 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<ITextEditorOptions> | 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<ITextEditorOptions> | 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<ITextEditorOptions> | 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
};
}

View File

@@ -617,17 +617,22 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
return {
filesToOpenOrCreate: defaultLayout.editors.map<IPath>(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`
}
};
})
};

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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, IBrowserWorkbenchEnvironmentService>(IEnvironmentService);
@@ -295,7 +296,7 @@ export class BrowserWorkbenchEnvironmentService implements IBrowserWorkbenchEnvi
}
@memoize
get filesToOpenOrCreate(): IPath[] | undefined {
get filesToOpenOrCreate(): IPath<ITextEditorOptions>[] | 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
}
}];
}

View File

@@ -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<ITextEditorOptions>[] = [];
// 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];