From e22964915a713686a83e88531999514cbd62326a Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 28 Oct 2019 16:25:51 -0500 Subject: [PATCH] Support opening workspaces from command line Partly addresses #1121. --- src/node/cli.ts | 2 +- src/node/server.ts | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/node/cli.ts b/src/node/cli.ts index 2b3f7791..175708e1 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -90,7 +90,7 @@ const startVscode = async (): Promise => { basePath: args["base-path"], cert: args.cert, certKey: args["cert-key"], - folderUri: extra.length > 1 ? extra[extra.length - 1] : undefined, + openUri: extra.length > 1 ? extra[extra.length - 1] : undefined, host: args.host, password: process.env.PASSWORD, }; diff --git a/src/node/server.ts b/src/node/server.ts index b3bc0ced..a6613bd2 100644 --- a/src/node/server.ts +++ b/src/node/server.ts @@ -116,7 +116,7 @@ export interface ServerOptions { readonly connectionToken?: string; readonly cert?: string; readonly certKey?: string; - readonly folderUri?: string; + readonly openUri?: string; readonly host?: string; readonly password?: string; readonly port?: number; @@ -552,9 +552,9 @@ export class MainServer extends Server { util.promisify(fs.readFile)(filePath, "utf8"), this.getFirstValidPath([ { path: parsedUrl.query.workspace, workspace: true }, - { path: parsedUrl.query.folder }, + { path: parsedUrl.query.folder, workspace: false }, (await this.readSettings()).lastVisited, - { path: this.options.folderUri } + { path: this.options.openUri } ]), this.servicesPromise, ]); @@ -598,7 +598,9 @@ export class MainServer extends Server { } /** - * Choose the first valid path. + * Choose the first valid path. If `workspace` is undefined then either a + * workspace or a directory are acceptable. Otherwise it must be a file if a + * workspace or a directory otherwise. */ private async getFirstValidPath(startPaths: Array): Promise<{ uri: URI, workspace?: boolean} | undefined> { const logger = this.services.get(ILogService) as ILogService; @@ -613,9 +615,8 @@ export class MainServer extends Server { const uri = URI.file(sanitizeFilePath(paths[j], cwd)); try { const stat = await util.promisify(fs.stat)(uri.fsPath); - // Workspace must be a file. - if (!!startPath.workspace !== stat.isDirectory()) { - return { uri, workspace: startPath.workspace }; + if (typeof startPath.workspace === "undefined" || startPath.workspace !== stat.isDirectory()) { + return { uri, workspace: !stat.isDirectory() }; } } catch (error) { logger.warn(error.message);