Skip to content

Commit fa854de

Browse files
committed
URI for waitMarkerFilePath
1 parent d5152c6 commit fa854de

16 files changed

Lines changed: 131 additions & 72 deletions

File tree

src/vs/code/electron-main/app.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,16 +575,43 @@ export class CodeApplication extends Disposable {
575575
const hasFolderURIs = hasArgs(args['folder-uri']);
576576
const hasFileURIs = hasArgs(args['file-uri']);
577577
const noRecentEntry = args['skip-add-to-recently-opened'] === true;
578+
const waitMarkerFileURI = args.wait && args.waitMarkerFilePath ? URI.file(args.waitMarkerFilePath) : undefined;
578579

579580
if (args['new-window'] && !hasCliArgs && !hasFolderURIs && !hasFileURIs) {
580-
return this.windowsMainService.open({ context, cli: args, forceNewWindow: true, forceEmpty: true, noRecentEntry, initialStartup: true }); // new window if "-n" was used without paths
581+
// new window if "-n" was used without paths
582+
return this.windowsMainService.open({
583+
context,
584+
cli: args,
585+
forceNewWindow: true,
586+
forceEmpty: true,
587+
noRecentEntry,
588+
waitMarkerFileURI,
589+
initialStartup: true
590+
});
581591
}
582592

583593
if (macOpenFiles && macOpenFiles.length && !hasCliArgs && !hasFolderURIs && !hasFileURIs) {
584-
return this.windowsMainService.open({ context: OpenContext.DOCK, cli: args, urisToOpen: macOpenFiles.map(file => ({ uri: URI.file(file) })), noRecentEntry, initialStartup: true }); // mac: open-file event received on startup
594+
// mac: open-file event received on startup
595+
return this.windowsMainService.open({
596+
context: OpenContext.DOCK,
597+
cli: args,
598+
urisToOpen: macOpenFiles.map(file => ({ uri: URI.file(file) })),
599+
noRecentEntry,
600+
waitMarkerFileURI,
601+
initialStartup: true
602+
});
585603
}
586604

587-
return this.windowsMainService.open({ context, cli: args, forceNewWindow: args['new-window'] || (!hasCliArgs && args['unity-launch']), diffMode: args.diff, noRecentEntry, initialStartup: true }); // default: read paths from cli
605+
// default: read paths from cli
606+
return this.windowsMainService.open({
607+
context,
608+
cli: args,
609+
forceNewWindow: args['new-window'] || (!hasCliArgs && args['unity-launch']),
610+
diffMode: args.diff,
611+
noRecentEntry,
612+
waitMarkerFileURI,
613+
initialStartup: true
614+
});
588615
}
589616

590617
private afterWindowOpen(accessor: ServicesAccessor): void {

src/vs/code/electron-main/main.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { app, dialog } from 'electron';
88
import { assign } from 'vs/base/common/objects';
99
import * as platform from 'vs/base/common/platform';
1010
import product from 'vs/platform/product/node/product';
11-
import { parseMainProcessArgv, createWaitMarkerFile } from 'vs/platform/environment/node/argvHelper';
12-
import { addArg } from 'vs/platform/environment/node/argv';
11+
import { parseMainProcessArgv } from 'vs/platform/environment/node/argvHelper';
12+
import { addArg, createWaitMarkerFile } from 'vs/platform/environment/node/argv';
1313
import { mkdirp } from 'vs/base/node/pfs';
1414
import { validatePaths } from 'vs/code/node/paths';
1515
import { LifecycleService, ILifecycleService } from 'vs/platform/lifecycle/electron-main/lifecycleMain';
@@ -357,20 +357,13 @@ function main(): void {
357357
// Note: we are not doing this if the wait marker has been already
358358
// added as argument. This can happen if Code was started from CLI.
359359
if (args.wait && !args.waitMarkerFilePath) {
360-
createWaitMarkerFile(args.verbose).then(waitMarkerFilePath => {
361-
if (waitMarkerFilePath) {
362-
addArg(process.argv, '--waitMarkerFilePath', waitMarkerFilePath);
363-
args.waitMarkerFilePath = waitMarkerFilePath;
364-
}
365-
366-
startup(args);
367-
});
368-
}
369-
370-
// Otherwise just startup normally
371-
else {
372-
startup(args);
360+
const waitMarkerFilePath = createWaitMarkerFile(args.verbose);
361+
if (waitMarkerFilePath) {
362+
addArg(process.argv, '--waitMarkerFilePath', waitMarkerFilePath);
363+
args.waitMarkerFilePath = waitMarkerFilePath;
364+
}
373365
}
366+
startup(args);
374367
}
375368

376369
main();

src/vs/code/electron-main/windows.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ export class WindowsManager implements IWindowsMainService {
421421
}
422422

423423
// When run with --wait, make sure we keep the paths to wait for
424-
if (fileInputs && openConfig.cli.wait && openConfig.cli.waitMarkerFilePath) {
425-
fileInputs.filesToWait = { paths: [...fileInputs.filesToDiff, ...fileInputs.filesToOpen, ...fileInputs.filesToCreate], waitMarkerFileUri: URI.file(openConfig.cli.waitMarkerFilePath) };
424+
if (fileInputs && openConfig.waitMarkerFileURI) {
425+
fileInputs.filesToWait = { paths: [...fileInputs.filesToDiff, ...fileInputs.filesToOpen, ...fileInputs.filesToCreate], waitMarkerFileUri: openConfig.waitMarkerFileURI };
426426
}
427427

428428
//
@@ -506,8 +506,9 @@ export class WindowsManager implements IWindowsMainService {
506506
// If we got started with --wait from the CLI, we need to signal to the outside when the window
507507
// used for the edit operation is closed or loaded to a different folder so that the waiting
508508
// process can continue. We do this by deleting the waitMarkerFilePath.
509-
if (openConfig.context === OpenContext.CLI && openConfig.cli.wait && openConfig.cli.waitMarkerFilePath && usedWindows.length === 1 && usedWindows[0]) {
510-
this.waitForWindowCloseOrLoad(usedWindows[0].id).then(() => fs.unlink(openConfig.cli.waitMarkerFilePath!, _error => undefined));
509+
const waitMarkerFileURI = openConfig.waitMarkerFileURI;
510+
if (openConfig.context === OpenContext.CLI && waitMarkerFileURI && usedWindows.length === 1 && usedWindows[0]) {
511+
this.waitForWindowCloseOrLoad(usedWindows[0].id).then(() => fs.unlink(waitMarkerFileURI.fsPath, _error => undefined));
511512
}
512513

513514
return usedWindows;
@@ -1216,7 +1217,16 @@ export class WindowsManager implements IWindowsMainService {
12161217
}
12171218

12181219
// Open it
1219-
this.open({ context: openConfig.context, cli: openConfig.cli, forceNewWindow: true, forceEmpty: !cliArgs.length && !folderUris.length && !fileUris.length, userEnv: openConfig.userEnv, noRecentEntry: true });
1220+
const openArgs: IOpenConfiguration = {
1221+
context: openConfig.context,
1222+
cli: openConfig.cli,
1223+
forceNewWindow: true,
1224+
forceEmpty: !cliArgs.length && !folderUris.length && !fileUris.length,
1225+
userEnv: openConfig.userEnv,
1226+
noRecentEntry: true,
1227+
waitMarkerFileURI: openConfig.waitMarkerFileURI
1228+
};
1229+
this.open(openArgs);
12201230
}
12211231

12221232
private openInBrowserWindow(options: IOpenBrowserWindowOptions): ICodeWindow {

src/vs/code/node/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import { spawn, ChildProcess } from 'child_process';
77
import { assign } from 'vs/base/common/objects';
8-
import { buildHelpMessage, buildVersionMessage, addArg } from 'vs/platform/environment/node/argv';
9-
import { parseCLIProcessArgv, createWaitMarkerFile } from 'vs/platform/environment/node/argvHelper';
8+
import { buildHelpMessage, buildVersionMessage, addArg, createWaitMarkerFile } from 'vs/platform/environment/node/argv';
9+
import { parseCLIProcessArgv } from 'vs/platform/environment/node/argvHelper';
1010
import { ParsedArgs } from 'vs/platform/environment/common/environment';
1111
import product from 'vs/platform/product/node/product';
1212
import pkg from 'vs/platform/product/node/package';
@@ -229,7 +229,7 @@ export async function main(argv: string[]): Promise<any> {
229229
// is closed and then exit the waiting process.
230230
let waitMarkerFilePath: string | undefined;
231231
if (args.wait) {
232-
waitMarkerFilePath = await createWaitMarkerFile(verbose);
232+
waitMarkerFilePath = createWaitMarkerFile(verbose);
233233
if (waitMarkerFilePath) {
234234
addArg(argv, '--waitMarkerFilePath', waitMarkerFilePath);
235235
}

src/vs/platform/environment/node/argv.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import * as minimist from 'minimist';
77
import * as os from 'os';
88
import { localize } from 'vs/nls';
99
import { ParsedArgs } from 'vs/platform/environment/common/environment';
10+
import { join } from 'path';
11+
import { writeFileSync } from 'fs';
1012

1113
/**
1214
* This code is also used by standalone cli's. Avoid adding any other dependencies.
@@ -253,4 +255,21 @@ export function addArg(argv: string[], ...args: string[]): string[] {
253255
}
254256

255257
return argv;
258+
}
259+
260+
export function createWaitMarkerFile(verbose?: boolean): string | undefined {
261+
const randomWaitMarkerPath = join(os.tmpdir(), Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10));
262+
263+
try {
264+
writeFileSync(randomWaitMarkerPath, '');
265+
if (verbose) {
266+
console.log(`Marker file for --wait created: ${randomWaitMarkerPath}`);
267+
}
268+
return randomWaitMarkerPath;
269+
} catch (err) {
270+
if (verbose) {
271+
console.error(`Failed to create marker file for --wait: ${err}`);
272+
}
273+
return undefined;
274+
}
256275
}

src/vs/platform/environment/node/argvHelper.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as assert from 'assert';
7-
import { tmpdir } from 'os';
87
import { firstIndex } from 'vs/base/common/arrays';
98
import { localize } from 'vs/nls';
109
import { ParsedArgs } from '../common/environment';
1110
import { MIN_MAX_MEMORY_SIZE_MB } from 'vs/platform/files/common/files';
1211
import { parseArgs } from 'vs/platform/environment/node/argv';
13-
import { join } from 'vs/base/common/path';
14-
import { writeFile } from 'vs/base/node/pfs';
1512

1613
function validate(args: ParsedArgs): ParsedArgs {
1714
if (args.goto) {
@@ -60,21 +57,3 @@ export function parseCLIProcessArgv(processArgv: string[]): ParsedArgs {
6057

6158
return validate(parseArgs(args));
6259
}
63-
64-
export function createWaitMarkerFile(verbose?: boolean): Promise<string> {
65-
const randomWaitMarkerPath = join(tmpdir(), Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10));
66-
67-
return writeFile(randomWaitMarkerPath, '').then(() => {
68-
if (verbose) {
69-
console.log(`Marker file for --wait created: ${randomWaitMarkerPath}`);
70-
}
71-
72-
return randomWaitMarkerPath;
73-
}, error => {
74-
if (verbose) {
75-
console.error(`Failed to create marker file for --wait: ${error}`);
76-
}
77-
78-
return Promise.resolve(undefined);
79-
});
80-
}

src/vs/platform/launch/electron-main/launchService.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,11 @@ export class LaunchService implements ILaunchService {
163163
const context = !!userEnv['VSCODE_CLI'] ? OpenContext.CLI : OpenContext.DESKTOP;
164164
let usedWindows: ICodeWindow[] = [];
165165

166+
const waitMarkerFileURI = args.wait && args.waitMarkerFilePath ? URI.file(args.waitMarkerFilePath) : undefined;
167+
166168
// Special case extension development
167169
if (!!args.extensionDevelopmentPath) {
168-
this.windowsMainService.openExtensionDevelopmentHostWindow(args.extensionDevelopmentPath, { context, cli: args, userEnv });
170+
this.windowsMainService.openExtensionDevelopmentHostWindow(args.extensionDevelopmentPath, { context, cli: args, userEnv, waitMarkerFileURI });
169171
}
170172

171173
// Start without file/folder arguments
@@ -199,7 +201,14 @@ export class LaunchService implements ILaunchService {
199201
}
200202

201203
if (openNewWindow) {
202-
usedWindows = this.windowsMainService.open({ context, cli: args, userEnv, forceNewWindow: true, forceEmpty: true });
204+
usedWindows = this.windowsMainService.open({
205+
context,
206+
cli: args,
207+
userEnv,
208+
forceNewWindow: true,
209+
forceEmpty: true,
210+
waitMarkerFileURI
211+
});
203212
} else {
204213
usedWindows = [this.windowsMainService.focusLastActive(args, context)];
205214
}
@@ -216,17 +225,18 @@ export class LaunchService implements ILaunchService {
216225
forceReuseWindow: args['reuse-window'],
217226
diffMode: args.diff,
218227
addMode: args.add,
219-
noRecentEntry: !!args['skip-add-to-recently-opened']
228+
noRecentEntry: !!args['skip-add-to-recently-opened'],
229+
waitMarkerFileURI
220230
});
221231
}
222232

223233
// If the other instance is waiting to be killed, we hook up a window listener if one window
224234
// is being used and only then resolve the startup promise which will kill this second instance.
225235
// In addition, we poll for the wait marker file to be deleted to return.
226-
if (args.wait && args.waitMarkerFilePath && usedWindows.length === 1 && usedWindows[0]) {
236+
if (waitMarkerFileURI && usedWindows.length === 1 && usedWindows[0]) {
227237
return Promise.race([
228238
this.windowsMainService.waitForWindowCloseOrLoad(usedWindows[0].id),
229-
whenDeleted(args.waitMarkerFilePath)
239+
whenDeleted(waitMarkerFileURI.fsPath)
230240
]).then(() => undefined, () => undefined);
231241
}
232242

src/vs/platform/windows/common/windows.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export interface IWindowsService {
149149
toggleSharedProcess(): Promise<void>;
150150

151151
// Global methods
152-
openWindow(windowId: number, uris: IURIToOpen[], options?: IOpenSettings): Promise<void>;
152+
openWindow(windowId: number, uris: IURIToOpen[], options: IOpenSettings): Promise<void>;
153153
openNewWindow(options?: INewWindowOptions): Promise<void>;
154154
showWindow(windowId: number): Promise<void>;
155155
getWindows(): Promise<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]>;
@@ -183,6 +183,7 @@ export interface IOpenSettings {
183183
diffMode?: boolean;
184184
addMode?: boolean;
185185
noRecentEntry?: boolean;
186+
waitMarkerFileURI?: URI;
186187
args?: ParsedArgs;
187188
}
188189

src/vs/platform/windows/electron-browser/windowService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class WindowService extends Disposable implements IWindowService {
9898
return this.windowsService.enterWorkspace(this.windowId, path);
9999
}
100100

101-
openWindow(uris: IURIToOpen[], options?: IOpenSettings): Promise<void> {
101+
openWindow(uris: IURIToOpen[], options: IOpenSettings = {}): Promise<void> {
102102
if (!!this.configuration.remoteAuthority) {
103103
uris.forEach(u => u.label = u.label || this.getRecentLabel(u, !!(options && options.forceOpenWorkspaceAsFile)));
104104
}

src/vs/platform/windows/electron-browser/windowsService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { Event } from 'vs/base/common/event';
77
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
8-
import { IWindowsService, INativeOpenDialogOptions, IEnterWorkspaceResult, CrashReporterStartOptions, IMessageBoxResult, MessageBoxOptions, SaveDialogOptions, OpenDialogOptions, IDevToolsOptions, INewWindowOptions, IURIToOpen } from 'vs/platform/windows/common/windows';
8+
import { IWindowsService, INativeOpenDialogOptions, IEnterWorkspaceResult, CrashReporterStartOptions, IMessageBoxResult, MessageBoxOptions, SaveDialogOptions, OpenDialogOptions, IDevToolsOptions, INewWindowOptions, IURIToOpen, IOpenSettings } from 'vs/platform/windows/common/windows';
99
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, reviveWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
1010
import { IRecentlyOpened, IRecent, isRecentWorkspace } from 'vs/platform/history/common/history';
1111
import { ISerializableCommandAction } from 'vs/platform/actions/common/actions';
@@ -186,7 +186,7 @@ export class WindowsService implements IWindowsService {
186186
return this.channel.call('toggleSharedProcess');
187187
}
188188

189-
openWindow(windowId: number, uris: IURIToOpen[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean, args?: ParsedArgs }): Promise<void> {
189+
openWindow(windowId: number, uris: IURIToOpen[], options: IOpenSettings): Promise<void> {
190190
return this.channel.call('openWindow', [windowId, uris, options]);
191191
}
192192

0 commit comments

Comments
 (0)