Skip to content

Commit 30fd1a6

Browse files
committed
Address code-review
* Change loop to indexed `for` loop * Moved isDirectory check to IsDir local func, to prevent continue in loop and messy try/catch * Cleaned up white space issue with patch
1 parent b8a57f3 commit 30fd1a6

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

ci/dev/vscode.patch

+3-2
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,8 @@ index 0000000000..16ed214d94
12961296
+ type: 'cli';
12971297
+ args: Args;
12981298
+}
1299-
+ export interface OpenCommandPipeArgs {
1299+
+
1300+
+export interface OpenCommandPipeArgs {
13001301
+ type: 'open';
13011302
+ fileURIs?: string[];
13021303
+ folderURIs: string[];
@@ -1306,7 +1307,7 @@ index 0000000000..16ed214d94
13061307
+ gotoLineMode?: boolean;
13071308
+ forceReuseWindow?: boolean;
13081309
+ waitMarkerFilePath?: string;
1309-
+ }
1310+
+}
13101311
+
13111312
+export type CodeServerMessage = InitMessage | SocketMessage | CliMessage;
13121313
+

src/node/entry.ts

+22-13
Original file line numberDiff line numberDiff line change
@@ -171,26 +171,35 @@ async function entry(): Promise<void> {
171171
const pipeArgs: OpenCommandPipeArgs = { type: "open", folderURIs: [] }
172172
pipeArgs.forceReuseWindow = args["reuse-window"]
173173
pipeArgs.forceNewWindow = args["new-window"]
174-
for (const a in args._) {
175-
if (Object.prototype.hasOwnProperty.call(args._, a)) {
176-
try {
177-
const fp = await fs.realpath(args._[a])
178-
const st = await fs.stat(fp)
179-
if (st.isDirectory()) {
180-
pipeArgs.folderURIs = [...pipeArgs.folderURIs, fp]
181-
} else {
182-
pipeArgs.fileURIs = [...(pipeArgs.fileURIs || []), fp]
183-
}
184-
} catch (error) {
185-
pipeArgs.fileURIs = [...(pipeArgs.fileURIs || []), args._[a]]
174+
const isDir = async (path: string): Promise<boolean> => {
175+
try {
176+
const st = await fs.stat(path)
177+
return st.isDirectory()
178+
} catch (error) {
179+
return false
180+
}
181+
}
182+
for (let i = 0; i < args._.length; i++) {
183+
const fp = path.resolve(args._[i])
184+
if (await isDir(fp)) {
185+
pipeArgs.folderURIs.push(fp)
186+
} else {
187+
if (!pipeArgs.fileURIs) {
188+
pipeArgs.fileURIs = []
186189
}
190+
pipeArgs.fileURIs.push(fp)
187191
}
188192
}
189193
if (pipeArgs.forceNewWindow && pipeArgs.fileURIs && pipeArgs.fileURIs.length > 0) {
190194
logger.error("new-window can only be used with folder paths")
191195
process.exit(1)
192196
}
193-
const vscode = http.request({
197+
if (pipeArgs.folderURIs.length === 0 && (!pipeArgs.fileURIs || pipeArgs.fileURIs.length === 0)) {
198+
logger.error("open-in expects at least one file or folder argument")
199+
process.exit(1)
200+
}
201+
const vscode = http.request(
202+
{
194203
path: "/",
195204
method: "POST",
196205
socketPath: process.env["VSCODE_IPC_HOOK_CLI"],

0 commit comments

Comments
 (0)