@@ -143,6 +143,17 @@ export class Commands {
143
143
}
144
144
}
145
145
146
+ public async openFromSidebar ( treeItem : WorkspaceTreeItem ) {
147
+ if ( treeItem ) {
148
+ await openWorkspace (
149
+ treeItem . workspaceOwner ,
150
+ treeItem . workspaceName ,
151
+ treeItem . workspaceAgent ,
152
+ treeItem . workspaceFolderPath ,
153
+ )
154
+ }
155
+ }
156
+
146
157
public async open ( ...args : unknown [ ] ) : Promise < void > {
147
158
let workspaceOwner : string
148
159
let workspaceName : string
@@ -248,84 +259,14 @@ export class Commands {
248
259
workspaceAgent = ""
249
260
}
250
261
}
251
- } else if ( args . length === 2 ) {
252
- // opening a workspace from the sidebar
253
- const workspaceTreeItem = args [ 0 ] as WorkspaceTreeItem
254
- workspaceOwner = workspaceTreeItem . workspaceOwner
255
- workspaceName = workspaceTreeItem . workspaceName
256
- folderPath = workspaceTreeItem . workspaceFolderPath
257
262
} else {
258
263
workspaceOwner = args [ 0 ] as string
259
264
workspaceName = args [ 1 ] as string
260
265
// workspaceAgent is reserved for args[2], but multiple agents aren't supported yet.
261
266
folderPath = args [ 3 ] as string | undefined
262
267
}
263
268
264
- // A workspace can have multiple agents, but that's handled
265
- // when opening a workspace unless explicitly specified.
266
- let remoteAuthority = `ssh-remote+${ Remote . Prefix } ${ workspaceOwner } --${ workspaceName } `
267
- if ( workspaceAgent ) {
268
- remoteAuthority += `--${ workspaceAgent } `
269
- }
270
-
271
- let newWindow = true
272
- // Open in the existing window if no workspaces are open.
273
- if ( ! vscode . workspace . workspaceFolders ?. length ) {
274
- newWindow = false
275
- }
276
-
277
- // If a folder isn't specified, we can try to open a recently opened folder.
278
- if ( ! folderPath ) {
279
- const output : {
280
- workspaces : { folderUri : vscode . Uri ; remoteAuthority : string } [ ]
281
- } = await vscode . commands . executeCommand ( "_workbench.getRecentlyOpened" )
282
- const opened = output . workspaces . filter (
283
- // Filter out `/` since that's added below.
284
- ( opened ) => opened . folderUri ?. authority === remoteAuthority ,
285
- )
286
- if ( opened . length > 0 ) {
287
- let selected : ( typeof opened ) [ 0 ]
288
-
289
- if ( opened . length > 1 ) {
290
- const items : vscode . QuickPickItem [ ] = opened . map ( ( folder ) : vscode . QuickPickItem => {
291
- return {
292
- label : folder . folderUri . path ,
293
- }
294
- } )
295
- const item = await vscode . window . showQuickPick ( items , {
296
- title : "Select a recently opened folder" ,
297
- } )
298
- if ( ! item ) {
299
- return
300
- }
301
- selected = opened [ items . indexOf ( item ) ]
302
- } else {
303
- selected = opened [ 0 ]
304
- }
305
-
306
- folderPath = selected . folderUri . path
307
- }
308
- }
309
-
310
- if ( folderPath ) {
311
- await vscode . commands . executeCommand (
312
- "vscode.openFolder" ,
313
- vscode . Uri . from ( {
314
- scheme : "vscode-remote" ,
315
- authority : remoteAuthority ,
316
- path : folderPath ,
317
- } ) ,
318
- // Open this in a new window!
319
- newWindow ,
320
- )
321
- return
322
- }
323
-
324
- // This opens the workspace without an active folder opened.
325
- await vscode . commands . executeCommand ( "vscode.newWindow" , {
326
- remoteAuthority : remoteAuthority ,
327
- reuseWindow : ! newWindow ,
328
- } )
269
+ await openWorkspace ( workspaceOwner , workspaceName , workspaceAgent , folderPath )
329
270
}
330
271
331
272
public async updateWorkspace ( ) : Promise < void > {
@@ -346,3 +287,76 @@ export class Commands {
346
287
}
347
288
}
348
289
}
290
+
291
+ async function openWorkspace (
292
+ workspaceOwner : string ,
293
+ workspaceName : string ,
294
+ workspaceAgent : string | undefined ,
295
+ folderPath : string | undefined ,
296
+ ) {
297
+ // A workspace can have multiple agents, but that's handled
298
+ // when opening a workspace unless explicitly specified.
299
+ let remoteAuthority = `ssh-remote+${ Remote . Prefix } ${ workspaceOwner } --${ workspaceName } `
300
+ if ( workspaceAgent ) {
301
+ remoteAuthority += `--${ workspaceAgent } `
302
+ }
303
+
304
+ let newWindow = true
305
+ // Open in the existing window if no workspaces are open.
306
+ if ( ! vscode . workspace . workspaceFolders ?. length ) {
307
+ newWindow = false
308
+ }
309
+
310
+ // If a folder isn't specified, we can try to open a recently opened folder.
311
+ if ( ! folderPath ) {
312
+ const output : {
313
+ workspaces : { folderUri : vscode . Uri ; remoteAuthority : string } [ ]
314
+ } = await vscode . commands . executeCommand ( "_workbench.getRecentlyOpened" )
315
+ const opened = output . workspaces . filter (
316
+ // Filter out `/` since that's added below.
317
+ ( opened ) => opened . folderUri ?. authority === remoteAuthority ,
318
+ )
319
+ if ( opened . length > 0 ) {
320
+ let selected : ( typeof opened ) [ 0 ]
321
+
322
+ if ( opened . length > 1 ) {
323
+ const items : vscode . QuickPickItem [ ] = opened . map ( ( folder ) : vscode . QuickPickItem => {
324
+ return {
325
+ label : folder . folderUri . path ,
326
+ }
327
+ } )
328
+ const item = await vscode . window . showQuickPick ( items , {
329
+ title : "Select a recently opened folder" ,
330
+ } )
331
+ if ( ! item ) {
332
+ return
333
+ }
334
+ selected = opened [ items . indexOf ( item ) ]
335
+ } else {
336
+ selected = opened [ 0 ]
337
+ }
338
+
339
+ folderPath = selected . folderUri . path
340
+ }
341
+ }
342
+
343
+ if ( folderPath ) {
344
+ await vscode . commands . executeCommand (
345
+ "vscode.openFolder" ,
346
+ vscode . Uri . from ( {
347
+ scheme : "vscode-remote" ,
348
+ authority : remoteAuthority ,
349
+ path : folderPath ,
350
+ } ) ,
351
+ // Open this in a new window!
352
+ newWindow ,
353
+ )
354
+ return
355
+ }
356
+
357
+ // This opens the workspace without an active folder opened.
358
+ await vscode . commands . executeCommand ( "vscode.newWindow" , {
359
+ remoteAuthority : remoteAuthority ,
360
+ reuseWindow : ! newWindow ,
361
+ } )
362
+ }
0 commit comments