Skip to content

Commit df56b23

Browse files
committed
Fix handling folder-uris along with _ paths
1 parent c2d5f3b commit df56b23

5 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/vs/base/common/labels.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function getBaseLabel(resource: URI | string): string {
8484
resource = URI.file(resource);
8585
}
8686

87-
const base = pathsBasename(resource.path) || resource.path /* can be empty string if '/' is passed in */;
87+
const base = pathsBasename(resource.path) || (resource.scheme === Schemas.file ? resource.fsPath : resource.path) /* can be empty string if '/' is passed in */;
8888

8989
// convert c: => C:
9090
if (hasDriveLetter(base)) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,9 @@ export class CodeApplication {
462462
// Open our first window
463463
const macOpenFiles = (<any>global).macOpenFiles as string[];
464464
const context = !!process.env['VSCODE_CLI'] ? OpenContext.CLI : OpenContext.DESKTOP;
465-
if (args['new-window'] && args._.length === 0) {
465+
if (args['new-window'] && args._.length === 0 && (args['folder-uri'] || []).length === 0) {
466466
this.windowsMainService.open({ context, cli: args, forceNewWindow: true, forceEmpty: true, initialStartup: true }); // new window if "-n" was used without paths
467-
} else if (macOpenFiles && macOpenFiles.length && (!args._ || !args._.length)) {
467+
} else if (macOpenFiles && macOpenFiles.length && (!args._ || !args._.length || !args['folder-uri'] || !args['folder-uri'].length)) {
468468
this.windowsMainService.open({ context: OpenContext.DOCK, cli: args, urisToOpen: macOpenFiles.map(file => URI.file(file)), initialStartup: true }); // mac: open-file event received on startup
469469
} else {
470470
this.windowsMainService.open({ context, cli: args, forceNewWindow: args['new-window'] || (!args._.length && args['unity-launch']), diffMode: args.diff, initialStartup: true }); // default: read paths from cli

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class LaunchService implements ILaunchService {
178178
}
179179

180180
// Start without file/folder arguments
181-
else if (args._.length === 0) {
181+
else if (args._.length === 0 && (args['folder-uri'] || []).length === 0) {
182182
let openNewWindow = false;
183183

184184
// Force new window

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ export class WindowsManager implements IWindowsMainService {
421421
// Make sure to pass focus to the most relevant of the windows if we open multiple
422422
if (usedWindows.length > 1) {
423423

424-
let focusLastActive = this.windowsState.lastActiveWindow && !openConfig.forceEmpty && !openConfig.cli._.length && (!openConfig.urisToOpen || !openConfig.urisToOpen.length);
424+
let focusLastActive = this.windowsState.lastActiveWindow && !openConfig.forceEmpty && !openConfig.cli._.length && !(openConfig.cli['folder-uri'] || []).length && !(openConfig.urisToOpen || []).length;
425425
let focusLastOpened = true;
426426
let focusLastWindow = true;
427427

@@ -789,7 +789,7 @@ export class WindowsManager implements IWindowsMainService {
789789
}
790790

791791
// Extract paths: from CLI
792-
else if (openConfig.cli._.length > 0 || openConfig.cli['folder-uri']) {
792+
else if (openConfig.cli._.length > 0 || (openConfig.cli['folder-uri'] || []).length > 0) {
793793
windowsToOpen = this.doExtractPathsFromCLI(openConfig.cli);
794794
isCommandLineOrAPICall = true;
795795
}
@@ -848,7 +848,7 @@ export class WindowsManager implements IWindowsMainService {
848848
const pathsToOpen = [];
849849

850850
// folder uris
851-
if (cli['folder-uri']) {
851+
if (cli['folder-uri'] && cli['folder-uri'].length) {
852852
const arg = cli['folder-uri'];
853853
const folderUris: string[] = typeof arg === 'string' ? [arg] : arg;
854854
pathsToOpen.push(...arrays.coalesce(folderUris.map(candidate => this.parseUri(URI.parse(candidate), { ignoreFileNotFound: true, gotoLineMode: cli.goto }))));
@@ -1087,15 +1087,15 @@ export class WindowsManager implements IWindowsMainService {
10871087
}
10881088

10891089
// Fill in previously opened workspace unless an explicit path is provided and we are not unit testing
1090-
if (openConfig.cli._.length === 0 && !openConfig.cli.extensionTestsPath) {
1090+
if (openConfig.cli._.length === 0 && (openConfig.cli['folder-uri'] || []).length === 0 && !openConfig.cli.extensionTestsPath) {
10911091
const extensionDevelopmentWindowState = this.windowsState.lastPluginDevelopmentHostWindow;
10921092
const workspaceToOpen = extensionDevelopmentWindowState && (extensionDevelopmentWindowState.workspace || extensionDevelopmentWindowState.folderUri);
10931093
if (workspaceToOpen) {
10941094
if (isSingleFolderWorkspaceIdentifier(workspaceToOpen)) {
10951095
if (workspaceToOpen.scheme === Schemas.file) {
10961096
openConfig.cli._ = [workspaceToOpen.fsPath];
10971097
} else {
1098-
// TODO:sandy handle other URIs
1098+
openConfig.cli['folder-uri'] = [workspaceToOpen.toString()];
10991099
}
11001100
} else {
11011101
openConfig.cli._ = [workspaceToOpen.configPath];
@@ -1116,7 +1116,7 @@ export class WindowsManager implements IWindowsMainService {
11161116
}
11171117

11181118
// Open it
1119-
this.open({ context: openConfig.context, cli: openConfig.cli, forceNewWindow: true, forceEmpty: openConfig.cli._.length === 0, userEnv: openConfig.userEnv });
1119+
this.open({ context: openConfig.context, cli: openConfig.cli, forceNewWindow: true, forceEmpty: openConfig.cli._.length === 0 && (openConfig.cli['folder-uri'] || []).length === 0, userEnv: openConfig.userEnv });
11201120
}
11211121

11221122
private openInBrowserWindow(options: IOpenBrowserWindowOptions): ICodeWindow {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const options: minimist.Opts = {
1818
'locale',
1919
'user-data-dir',
2020
'extensions-dir',
21+
'folder-uri',
2122
'extensionDevelopmentPath',
2223
'extensionTestsPath',
2324
'install-extension',
@@ -144,6 +145,7 @@ export function parseArgs(args: string[]): ParsedArgs {
144145

145146
const optionsHelp: { [name: string]: string; } = {
146147
'-d, --diff <file> <file>': localize('diff', "Compare two files with each other."),
148+
'--folder-uri <uri>': localize('folder uri', "Opens a window with given folder uri(s)"),
147149
'-a, --add <dir>': localize('add', "Add folder(s) to the last active window."),
148150
'-g, --goto <file:line[:character]>': localize('goto', "Open a file at the path on the specified line and character position."),
149151
'-n, --new-window': localize('newWindow', "Force to open a new window."),

0 commit comments

Comments
 (0)