From 890d482de05208211c83d910b0757de389c916bc Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Mon, 30 Jul 2018 16:52:55 +0200 Subject: [PATCH] revive path urls --- src/vs/platform/windows/common/windows.ts | 33 ++++++++++++++++--- src/vs/platform/windows/common/windowsIpc.ts | 1 + src/vs/workbench/electron-browser/main.ts | 34 ++++++++++++++++++-- src/vs/workbench/electron-browser/window.ts | 8 ++--- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/vs/platform/windows/common/windows.ts b/src/vs/platform/windows/common/windows.ts index 5f69dac4613..5a5dd0c6fdf 100644 --- a/src/vs/platform/windows/common/windows.ts +++ b/src/vs/platform/windows/common/windows.ts @@ -309,11 +309,28 @@ export interface IPathsToWaitFor { waitMarkerFilePath: string; } +export interface IPathData { + + // the file path to open within a Code instance + fileUri?: UriComponents; + + // the line number in the file path to open + lineNumber?: number; + + // the column number in the file path to open + columnNumber?: number; +} + +export interface IPathsToWaitForData { + paths: IPathData[]; + waitMarkerFilePath: string; +} + export interface IOpenFileRequest { - filesToOpen?: IPath[]; - filesToCreate?: IPath[]; - filesToDiff?: IPath[]; - filesToWait?: IPathsToWaitFor; + filesToOpen?: IPathData[]; + filesToCreate?: IPathData[]; + filesToDiff?: IPathData[]; + filesToWait?: IPathsToWaitForData; termProgram?: string; } @@ -321,7 +338,7 @@ export interface IAddFoldersRequest { foldersToAdd: UriComponents[]; } -export interface IWindowConfiguration extends ParsedArgs, IOpenFileRequest { +export interface IWindowConfiguration extends ParsedArgs { machineId: string; windowId: number; logLevel: LogLevel; @@ -351,6 +368,12 @@ export interface IWindowConfiguration extends ParsedArgs, IOpenFileRequest { perfStartTime?: number; perfAppReady?: number; perfWindowLoadTime?: number; + + filesToOpen?: IPath[]; + filesToCreate?: IPath[]; + filesToDiff?: IPath[]; + filesToWait?: IPathsToWaitFor; + termProgram?: string; } export interface IRunActionInWindowRequest { diff --git a/src/vs/platform/windows/common/windowsIpc.ts b/src/vs/platform/windows/common/windowsIpc.ts index 05912a7c133..30f4085be7d 100644 --- a/src/vs/platform/windows/common/windowsIpc.ts +++ b/src/vs/platform/windows/common/windowsIpc.ts @@ -278,6 +278,7 @@ export class WindowsChannelClient implements IWindowsService { return this.channel.call('getRecentlyOpened', windowId) .then(recentlyOpened => { recentlyOpened.workspaces = recentlyOpened.workspaces.map(workspace => isWorkspaceIdentifier(workspace) ? workspace : URI.revive(workspace)); + recentlyOpened.files = recentlyOpened.files.map(URI.revive); return recentlyOpened; }); } diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts index 05c7a8a054e..fb2f9584086 100644 --- a/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts @@ -15,7 +15,7 @@ import * as errors from 'vs/base/common/errors'; import * as comparer from 'vs/base/common/comparers'; import * as platform from 'vs/base/common/platform'; import * as paths from 'vs/base/common/paths'; -import uri from 'vs/base/common/uri'; +import uri, { UriComponents } from 'vs/base/common/uri'; import * as strings from 'vs/base/common/strings'; import { IWorkspaceContextService, Workspace, WorkbenchState } from 'vs/platform/workspace/common/workspace'; import { WorkspaceService } from 'vs/workbench/services/configuration/node/configurationService'; @@ -55,6 +55,8 @@ gracefulFs.gracefulify(fs); // enable gracefulFs export function startup(configuration: IWindowConfiguration): TPromise { + revive(configuration); + // Ensure others can listen to zoom level changes browser.setZoomFactor(webFrame.getZoomFactor()); @@ -75,6 +77,33 @@ export function startup(configuration: IWindowConfiguration): TPromise { return openWorkbench(configuration); } +function revive(workbench: IWindowConfiguration) { + if (workbench.folderUri) { + workbench.folderUri = uri.revive(workbench.folderUri); + } + function reviveFileUri(path: { fileUri?: UriComponents }) { + if (path.fileUri) { + path.fileUri = uri.revive(path.fileUri); + } + } + const filesToOpen = workbench.filesToOpen; + if (Array.isArray(filesToOpen)) { + filesToOpen.forEach(reviveFileUri); + } + const filesToCreate = workbench.filesToCreate; + if (Array.isArray(filesToCreate)) { + filesToCreate.forEach(reviveFileUri); + } + const filesToDiff = workbench.filesToDiff; + if (Array.isArray(filesToDiff)) { + filesToDiff.forEach(reviveFileUri); + } + const filesToWait = workbench.filesToWait; + if (filesToWait && Array.isArray(filesToWait.paths)) { + filesToWait.paths.forEach(reviveFileUri); + } +} + function openWorkbench(configuration: IWindowConfiguration): TPromise { const mainProcessClient = new ElectronIPCClient(`window:${configuration.windowId}`); const mainServices = createMainProcessServices(mainProcessClient, configuration); @@ -116,8 +145,7 @@ function openWorkbench(configuration: IWindowConfiguration): TPromise { } function createAndInitializeWorkspaceService(configuration: IWindowConfiguration, environmentService: EnvironmentService): TPromise { - const folderUri = configuration.folderUri ? uri.revive(configuration.folderUri) : null; - return validateFolderUri(folderUri, configuration.verbose).then(validatedFolderUri => { + return validateFolderUri(configuration.folderUri, configuration.verbose).then(validatedFolderUri => { const workspaceService = new WorkspaceService(environmentService); diff --git a/src/vs/workbench/electron-browser/window.ts b/src/vs/workbench/electron-browser/window.ts index b6dc2cbc7d1..6cfbb1235b9 100644 --- a/src/vs/workbench/electron-browser/window.ts +++ b/src/vs/workbench/electron-browser/window.ts @@ -18,7 +18,7 @@ import { toResource, IUntitledResourceInput } from 'vs/workbench/common/editor'; import { IEditorService, IResourceEditor } from 'vs/workbench/services/editor/common/editorService'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration'; -import { IWindowsService, IWindowService, IWindowSettings, IPath, IOpenFileRequest, IWindowsConfiguration, IAddFoldersRequest, IRunActionInWindowRequest } from 'vs/platform/windows/common/windows'; +import { IWindowsService, IWindowService, IWindowSettings, IOpenFileRequest, IWindowsConfiguration, IAddFoldersRequest, IRunActionInWindowRequest, IPathData } from 'vs/platform/windows/common/windows'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { ITitleService } from 'vs/workbench/services/title/common/titleService'; import { IWorkbenchThemeService, VS_HC_THEME, VS_DARK_THEME } from 'vs/workbench/services/themes/common/workbenchThemeService'; @@ -401,7 +401,7 @@ export class ElectronWindow extends Themable { // In wait mode, listen to changes to the editors and wait until the files // are closed that the user wants to wait for. When this happens we delete // the wait marker file to signal to the outside that editing is done. - const resourcesToWaitFor = request.filesToWait.paths.map(p => p.fileUri); + const resourcesToWaitFor = request.filesToWait.paths.map(p => URI.revive(p.fileUri)); const waitMarkerFile = URI.file(request.filesToWait.waitMarkerFilePath); const unbind = this.editorService.onDidCloseEditor(() => { if (resourcesToWaitFor.every(resource => !this.editorService.isOpen({ resource }))) { @@ -430,9 +430,9 @@ export class ElectronWindow extends Themable { }); } - private toInputs(paths: IPath[], isNew: boolean): IResourceEditor[] { + private toInputs(paths: IPathData[], isNew: boolean): IResourceEditor[] { return paths.map(p => { - const resource = p.fileUri; + const resource = URI.revive(p.fileUri); let input: IResourceInput | IUntitledResourceInput; if (isNew) { input = { filePath: resource.fsPath, options: { pinned: true } } as IUntitledResourceInput; -- GitLab