From 8d9331a57c26242bac2ea009eb43c58ad99cac2e Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Mon, 13 Aug 2018 12:09:34 +0200 Subject: [PATCH] incorperate review comments --- src/vs/code/electron-main/app.ts | 2 +- src/vs/code/electron-main/launch.ts | 2 +- src/vs/code/electron-main/windows.ts | 8 ++--- src/vs/code/node/args.ts | 33 ------------------- src/vs/platform/environment/node/argv.ts | 27 +++++++++++++++ .../electron-main/historyMainService.ts | 4 +-- src/vs/platform/windows/common/windows.ts | 19 ++++------- src/vs/platform/windows/common/windowsIpc.ts | 10 +++--- src/vs/workbench/electron-browser/main.ts | 31 ++++++----------- 9 files changed, 56 insertions(+), 80 deletions(-) delete mode 100644 src/vs/code/node/args.ts diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index a26e6c79c39..be65769bfce 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -65,7 +65,7 @@ import { MenubarService } from 'vs/platform/menubar/electron-main/menubarService import { MenubarChannel } from 'vs/platform/menubar/common/menubarIpc'; import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay'; import { CodeMenu } from 'vs/code/electron-main/menus'; -import { hasArgs } from 'vs/code/node/args'; +import { hasArgs } from 'vs/platform/environment/node/argv'; import { RunOnceScheduler } from 'vs/base/common/async'; export class CodeApplication { diff --git a/src/vs/code/electron-main/launch.ts b/src/vs/code/electron-main/launch.ts index b3bf915f9a9..a3affdb0597 100644 --- a/src/vs/code/electron-main/launch.ts +++ b/src/vs/code/electron-main/launch.ts @@ -20,7 +20,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import URI, { UriComponents } from 'vs/base/common/uri'; import { BrowserWindow } from 'electron'; import { Event } from 'vs/base/common/event'; -import { hasArgs } from 'vs/code/node/args'; +import { hasArgs } from 'vs/platform/environment/node/argv'; export const ID = 'launchService'; export const ILaunchService = createDecorator(ID); diff --git a/src/vs/code/electron-main/windows.ts b/src/vs/code/electron-main/windows.ts index 7a450e46ca6..4c2cbfdf499 100644 --- a/src/vs/code/electron-main/windows.ts +++ b/src/vs/code/electron-main/windows.ts @@ -14,7 +14,7 @@ import { IBackupMainService } from 'vs/platform/backup/common/backup'; import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment'; import { IStateService } from 'vs/platform/state/common/state'; import { CodeWindow, defaultWindowState } from 'vs/code/electron-main/window'; -import { asArray, hasArgs } from 'vs/code/node/args'; +import { hasArgs, asArray } from 'vs/platform/environment/node/argv'; import { ipcMain as ipc, screen, BrowserWindow, dialog, systemPreferences, app } from 'electron'; import { IPathWithLineAndColumn, parseLineAndColumnAware } from 'vs/code/node/paths'; import { ILifecycleService, UnloadReason, IWindowUnloadEvent } from 'vs/platform/lifecycle/electron-main/lifecycleMain'; @@ -423,7 +423,7 @@ export class WindowsManager implements IWindowsMainService { // Make sure to pass focus to the most relevant of the windows if we open multiple if (usedWindows.length > 1) { - let focusLastActive = this.windowsState.lastActiveWindow && !openConfig.forceEmpty && !hasArgs(openConfig.cli._) && !hasArgs(openConfig.cli['file-uri']) && !hasArgs(openConfig.cli['folder-uri']) && !hasArgs(openConfig.urisToOpen); + let focusLastActive = this.windowsState.lastActiveWindow && !openConfig.forceEmpty && !hasArgs(openConfig.cli._) && !hasArgs(openConfig.cli['file-uri']) && !hasArgs(openConfig.cli['folder-uri']) && !(openConfig.urisToOpen && openConfig.urisToOpen.length); let focusLastOpened = true; let focusLastWindow = true; @@ -999,12 +999,12 @@ export class WindowsManager implements IWindowsMainService { try { let uri = URI.parse(arg); if (!uri.scheme) { - console.log(`Invalid URI string, scheme missing: ${arg}`); + this.logService.error(`Invalid URI input string, scheme missing: ${arg}`); return null; } return uri; } catch (e) { - console.log(`Invalid URI string, scheme missing: ${e.message}`); + this.logService.error(`Invalid URI input string: ${arg}, ${e.message}`); } return null; } diff --git a/src/vs/code/node/args.ts b/src/vs/code/node/args.ts deleted file mode 100644 index feff5c5b405..00000000000 --- a/src/vs/code/node/args.ts +++ /dev/null @@ -1,33 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -'use strict'; - -/** - * Converts an argument into an array - * @param arg a argument value. Can be undefined, en entry or an array - */ -export function asArray(arg: T | T[] | undefined): T[] { - if (arg) { - if (Array.isArray(arg)) { - return arg; - } - return [arg]; - } - return []; -} - -/** - * Returns whether an argument is present. - */ -export function hasArgs(arg: T | T[] | undefined): boolean { - if (arg) { - if (Array.isArray(arg)) { - return !!arg.length; - } - return true; - } - return false; -} \ No newline at end of file diff --git a/src/vs/platform/environment/node/argv.ts b/src/vs/platform/environment/node/argv.ts index 386b12f597c..2d834829c24 100644 --- a/src/vs/platform/environment/node/argv.ts +++ b/src/vs/platform/environment/node/argv.ts @@ -236,3 +236,30 @@ ${formatOptions(extensionsHelp, columns)} ${ localize('troubleshooting', "Troubleshooting")}: ${formatOptions(troubleshootingHelp, columns)}`; } + +/** + * Converts an argument into an array + * @param arg a argument value. Can be undefined, an entry or an array + */ +export function asArray(arg: string | string[] | undefined): string[] { + if (arg) { + if (Array.isArray(arg)) { + return arg; + } + return [arg]; + } + return []; +} + +/** + * Returns whether an argument is present. + */ +export function hasArgs(arg: string | string[] | undefined): boolean { + if (arg) { + if (Array.isArray(arg)) { + return !!arg.length; + } + return true; + } + return false; +} \ No newline at end of file diff --git a/src/vs/platform/history/electron-main/historyMainService.ts b/src/vs/platform/history/electron-main/historyMainService.ts index 2ae5cf2041a..47f31f09499 100644 --- a/src/vs/platform/history/electron-main/historyMainService.ts +++ b/src/vs/platform/history/electron-main/historyMainService.ts @@ -350,7 +350,7 @@ export class HistoryMainService implements IHistoryMainService { for (let item of app.getJumpListSettings().removedItems) { const args = item.args; if (args) { - const match = /^--folderUri\s+"([^"]+)"$/.exec(args); + const match = /^--folder-uri\s+"([^"]+)"$/.exec(args); if (match) { if (args[0] === '-') { toRemove.push(URI.parse(match[1])); @@ -373,7 +373,7 @@ export class HistoryMainService implements IHistoryMainService { let args; if (isSingleFolderWorkspaceIdentifier(workspace)) { description = nls.localize('folderDesc', "{0} {1}", getBaseLabel(workspace), this.uriDisplayService.getLabel(dirname(workspace))); - args = `--folderUri "${workspace.toString()}"`; + args = `--folder-uri "${workspace.toString()}"`; } else { description = nls.localize('codeWorkspace', "Code Workspace"); args = `"${workspace.configPath}"`; diff --git a/src/vs/platform/windows/common/windows.ts b/src/vs/platform/windows/common/windows.ts index f00a214d5c5..8daee9d9578 100644 --- a/src/vs/platform/windows/common/windows.ts +++ b/src/vs/platform/windows/common/windows.ts @@ -292,20 +292,18 @@ export enum ReadyState { READY } -export interface IPath { +export interface IPath extends IPathData { // the file path to open within a Code instance fileUri?: URI; - - // the line number in the file path to open - lineNumber?: number; - - // the column number in the file path to open - columnNumber?: number; } -export interface IPathsToWaitFor { +export interface IPathsToWaitFor extends IPathsToWaitForData { paths: IPath[]; +} + +export interface IPathsToWaitForData { + paths: IPathData[]; waitMarkerFilePath: string; } @@ -321,11 +319,6 @@ export interface IPathData { columnNumber?: number; } -export interface IPathsToWaitForData { - paths: IPathData[]; - waitMarkerFilePath: string; -} - export interface IOpenFileRequest { filesToOpen?: IPathData[]; filesToCreate?: IPathData[]; diff --git a/src/vs/platform/windows/common/windowsIpc.ts b/src/vs/platform/windows/common/windowsIpc.ts index c884a48217c..a23fd06d07a 100644 --- a/src/vs/platform/windows/common/windowsIpc.ts +++ b/src/vs/platform/windows/common/windowsIpc.ts @@ -12,7 +12,7 @@ import { IWindowsService, INativeOpenDialogOptions, IEnterWorkspaceResult, Crash import { IWorkspaceIdentifier, IWorkspaceFolderCreationData, ISingleFolderWorkspaceIdentifier, isWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces'; import { IRecentlyOpened } from 'vs/platform/history/common/history'; import { ISerializableCommandAction } from 'vs/platform/actions/common/actions'; -import URI from 'vs/base/common/uri'; +import URI, { UriComponents } from 'vs/base/common/uri'; import { ParsedArgs } from 'vs/platform/environment/common/environment'; export interface IWindowsChannel extends IChannel { @@ -40,8 +40,8 @@ export interface IWindowsChannel extends IChannel { call(command: 'saveAndEnterWorkspace', arg: [number, string]): TPromise; call(command: 'toggleFullScreen', arg: number): TPromise; call(command: 'setRepresentedFilename', arg: [number, string]): TPromise; - call(command: 'addRecentlyOpened', arg: URI[]): TPromise; - call(command: 'removeFromRecentlyOpened', arg: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | URI)[]): TPromise; + call(command: 'addRecentlyOpened', arg: UriComponents[]): TPromise; + call(command: 'removeFromRecentlyOpened', arg: (IWorkspaceIdentifier | UriComponents | string)[]): TPromise; call(command: 'clearRecentlyOpened'): TPromise; call(command: 'getRecentlyOpened', arg: number): TPromise; call(command: 'newWindowTab'): TPromise; @@ -139,9 +139,9 @@ export class WindowsChannel implements IWindowsChannel { case 'saveAndEnterWorkspace': return this.service.saveAndEnterWorkspace(arg[0], arg[1]); case 'toggleFullScreen': return this.service.toggleFullScreen(arg); case 'setRepresentedFilename': return this.service.setRepresentedFilename(arg[0], arg[1]); - case 'addRecentlyOpened': return this.service.addRecentlyOpened(arg); + case 'addRecentlyOpened': return this.service.addRecentlyOpened(arg.map(URI.revive)); case 'removeFromRecentlyOpened': { - let paths: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | URI)[] = arg; + let paths: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | URI | string)[] = arg; if (Array.isArray(paths)) { paths = paths.map(path => isWorkspaceIdentifier(path) ? path : URI.revive(path)); } diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts index fb2f9584086..f2b0cf0d3a5 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, { UriComponents } from 'vs/base/common/uri'; +import uri 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'; @@ -81,27 +81,16 @@ 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 filesToWaitPaths = workbench.filesToWait && workbench.filesToWait.paths; + [filesToWaitPaths, workbench.filesToOpen, workbench.filesToCreate, workbench.filesToDiff].forEach(paths => { + if (Array.isArray(paths)) { + paths.forEach(path => { + 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 {