@@ -172,26 +172,35 @@ async function entry(): Promise<void> {
172
172
const pipeArgs : OpenCommandPipeArgs = { type : "open" , folderURIs : [ ] }
173
173
pipeArgs . forceReuseWindow = args [ "reuse-window" ]
174
174
pipeArgs . forceNewWindow = args [ "new-window" ]
175
- for ( const a in args . _ ) {
176
- if ( Object . prototype . hasOwnProperty . call ( args . _ , a ) ) {
177
- try {
178
- const fp = await fs . realpath ( args . _ [ a ] )
179
- const st = await fs . stat ( fp )
180
- if ( st . isDirectory ( ) ) {
181
- pipeArgs . folderURIs = [ ...pipeArgs . folderURIs , fp ]
182
- } else {
183
- pipeArgs . fileURIs = [ ...( pipeArgs . fileURIs || [ ] ) , fp ]
184
- }
185
- } catch ( error ) {
186
- pipeArgs . fileURIs = [ ...( pipeArgs . fileURIs || [ ] ) , args . _ [ a ] ]
175
+ const isDir = async ( path : string ) : Promise < boolean > => {
176
+ try {
177
+ const st = await fs . stat ( path )
178
+ return st . isDirectory ( )
179
+ } catch ( error ) {
180
+ return false
181
+ }
182
+ }
183
+ for ( let i = 0 ; i < args . _ . length ; i ++ ) {
184
+ const fp = path . resolve ( args . _ [ i ] )
185
+ if ( await isDir ( fp ) ) {
186
+ pipeArgs . folderURIs . push ( fp )
187
+ } else {
188
+ if ( ! pipeArgs . fileURIs ) {
189
+ pipeArgs . fileURIs = [ ]
187
190
}
191
+ pipeArgs . fileURIs . push ( fp )
188
192
}
189
193
}
190
194
if ( pipeArgs . forceNewWindow && pipeArgs . fileURIs && pipeArgs . fileURIs . length > 0 ) {
191
195
logger . error ( "new-window can only be used with folder paths" )
192
196
process . exit ( 1 )
193
197
}
194
- const vscode = http . request ( {
198
+ if ( pipeArgs . folderURIs . length === 0 && ( ! pipeArgs . fileURIs || pipeArgs . fileURIs . length === 0 ) ) {
199
+ logger . error ( "open-in expects at least one file or folder argument" )
200
+ process . exit ( 1 )
201
+ }
202
+ const vscode = http . request (
203
+ {
195
204
path : "/" ,
196
205
method : "POST" ,
197
206
socketPath : process . env [ "VSCODE_IPC_HOOK_CLI" ] ,
0 commit comments