Skip to content

Commit e229649

Browse files
committed
Support opening workspaces from command line
Partly addresses #1121.
1 parent 197d0b6 commit e229649

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/node/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const startVscode = async (): Promise<void | void[]> => {
9090
basePath: args["base-path"],
9191
cert: args.cert,
9292
certKey: args["cert-key"],
93-
folderUri: extra.length > 1 ? extra[extra.length - 1] : undefined,
93+
openUri: extra.length > 1 ? extra[extra.length - 1] : undefined,
9494
host: args.host,
9595
password: process.env.PASSWORD,
9696
};

src/node/server.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export interface ServerOptions {
116116
readonly connectionToken?: string;
117117
readonly cert?: string;
118118
readonly certKey?: string;
119-
readonly folderUri?: string;
119+
readonly openUri?: string;
120120
readonly host?: string;
121121
readonly password?: string;
122122
readonly port?: number;
@@ -552,9 +552,9 @@ export class MainServer extends Server {
552552
util.promisify(fs.readFile)(filePath, "utf8"),
553553
this.getFirstValidPath([
554554
{ path: parsedUrl.query.workspace, workspace: true },
555-
{ path: parsedUrl.query.folder },
555+
{ path: parsedUrl.query.folder, workspace: false },
556556
(await this.readSettings()).lastVisited,
557-
{ path: this.options.folderUri }
557+
{ path: this.options.openUri }
558558
]),
559559
this.servicesPromise,
560560
]);
@@ -598,7 +598,9 @@ export class MainServer extends Server {
598598
}
599599

600600
/**
601-
* Choose the first valid path.
601+
* Choose the first valid path. If `workspace` is undefined then either a
602+
* workspace or a directory are acceptable. Otherwise it must be a file if a
603+
* workspace or a directory otherwise.
602604
*/
603605
private async getFirstValidPath(startPaths: Array<StartPath | undefined>): Promise<{ uri: URI, workspace?: boolean} | undefined> {
604606
const logger = this.services.get(ILogService) as ILogService;
@@ -613,9 +615,8 @@ export class MainServer extends Server {
613615
const uri = URI.file(sanitizeFilePath(paths[j], cwd));
614616
try {
615617
const stat = await util.promisify(fs.stat)(uri.fsPath);
616-
// Workspace must be a file.
617-
if (!!startPath.workspace !== stat.isDirectory()) {
618-
return { uri, workspace: startPath.workspace };
618+
if (typeof startPath.workspace === "undefined" || startPath.workspace !== stat.isDirectory()) {
619+
return { uri, workspace: !stat.isDirectory() };
619620
}
620621
} catch (error) {
621622
logger.warn(error.message);

0 commit comments

Comments
 (0)