@@ -171,26 +171,35 @@ async function entry(): Promise<void> {
171
171
const pipeArgs : OpenCommandPipeArgs = { type : "open" , folderURIs : [ ] }
172
172
pipeArgs . forceReuseWindow = args [ "reuse-window" ]
173
173
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 = [ ]
186
189
}
190
+ pipeArgs . fileURIs . push ( fp )
187
191
}
188
192
}
189
193
if ( pipeArgs . forceNewWindow && pipeArgs . fileURIs && pipeArgs . fileURIs . length > 0 ) {
190
194
logger . error ( "new-window can only be used with folder paths" )
191
195
process . exit ( 1 )
192
196
}
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
+ {
194
203
path : "/" ,
195
204
method : "POST" ,
196
205
socketPath : process . env [ "VSCODE_IPC_HOOK_CLI" ] ,
0 commit comments