1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-27 20:55:25 +00:00

Support opening workspaces from command line

Partly addresses #1121.
This commit is contained in:
Asher 2019-10-28 16:25:51 -05:00
parent 197d0b6ca9
commit e22964915a
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
2 changed files with 9 additions and 8 deletions

View File

@ -90,7 +90,7 @@ const startVscode = async (): Promise<void | void[]> => {
basePath: args["base-path"], basePath: args["base-path"],
cert: args.cert, cert: args.cert,
certKey: args["cert-key"], 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, host: args.host,
password: process.env.PASSWORD, password: process.env.PASSWORD,
}; };

View File

@ -116,7 +116,7 @@ export interface ServerOptions {
readonly connectionToken?: string; readonly connectionToken?: string;
readonly cert?: string; readonly cert?: string;
readonly certKey?: string; readonly certKey?: string;
readonly folderUri?: string; readonly openUri?: string;
readonly host?: string; readonly host?: string;
readonly password?: string; readonly password?: string;
readonly port?: number; readonly port?: number;
@ -552,9 +552,9 @@ export class MainServer extends Server {
util.promisify(fs.readFile)(filePath, "utf8"), util.promisify(fs.readFile)(filePath, "utf8"),
this.getFirstValidPath([ this.getFirstValidPath([
{ path: parsedUrl.query.workspace, workspace: true }, { path: parsedUrl.query.workspace, workspace: true },
{ path: parsedUrl.query.folder }, { path: parsedUrl.query.folder, workspace: false },
(await this.readSettings()).lastVisited, (await this.readSettings()).lastVisited,
{ path: this.options.folderUri } { path: this.options.openUri }
]), ]),
this.servicesPromise, 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<StartPath | undefined>): Promise<{ uri: URI, workspace?: boolean} | undefined> { private async getFirstValidPath(startPaths: Array<StartPath | undefined>): Promise<{ uri: URI, workspace?: boolean} | undefined> {
const logger = this.services.get(ILogService) as ILogService; 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)); const uri = URI.file(sanitizeFilePath(paths[j], cwd));
try { try {
const stat = await util.promisify(fs.stat)(uri.fsPath); const stat = await util.promisify(fs.stat)(uri.fsPath);
// Workspace must be a file. if (typeof startPath.workspace === "undefined" || startPath.workspace !== stat.isDirectory()) {
if (!!startPath.workspace !== stat.isDirectory()) { return { uri, workspace: !stat.isDirectory() };
return { uri, workspace: startPath.workspace };
} }
} catch (error) { } catch (error) {
logger.warn(error.message); logger.warn(error.message);