@@ -17,6 +17,16 @@ import product from 'vs/platform/product/common/product';
17
17
import { isFolderToOpen , isWorkspaceToOpen } from 'vs/platform/windows/common/windows' ;
18
18
import { create , ICredentialsProvider , IURLCallbackProvider , IWorkbenchConstructionOptions , IWorkspace , IWorkspaceProvider } from 'vs/workbench/workbench.web.api' ;
19
19
20
+ /**
21
+ * Encode a path for opening via the folder or workspace query parameter. This
22
+ * preserves slashes so it can be edited by hand more easily.
23
+ *
24
+ * @author coder
25
+ */
26
+ export const encodePath = ( path : string ) : string => {
27
+ return path . split ( '/' ) . map ( ( p ) => encodeURIComponent ( p ) ) . join ( '/' ) ;
28
+ } ;
29
+
20
30
interface ICredential {
21
31
service : string ;
22
32
account : string ;
@@ -264,18 +274,43 @@ class WorkspaceProvider implements IWorkspaceProvider {
264
274
let workspace : IWorkspace ;
265
275
let payload = Object . create ( null ) ;
266
276
277
+ /**
278
+ * If the value begins with a slash assume it is a file path and convert it to
279
+ * use the vscode-remote scheme.
280
+ *
281
+ * @author coder
282
+ */
283
+ const toRemote = ( value : string ) : string => {
284
+ if ( value . startsWith ( "/" ) ) {
285
+ return "vscode-remote://" + value ;
286
+ }
287
+ return value
288
+ }
289
+
267
290
const query = new URL ( document . location . href ) . searchParams ;
268
291
query . forEach ( ( value , key ) => {
269
292
switch ( key ) {
270
293
271
294
// Folder
272
295
case WorkspaceProvider . QUERY_PARAM_FOLDER :
296
+ /**
297
+ * Handle URIs that we previously left unencoded and de-schemed.
298
+ *
299
+ * @author coder
300
+ */
301
+ value = toRemote ( value ) ;
273
302
workspace = { folderUri : URI . parse ( value ) } ;
274
303
foundWorkspace = true ;
275
304
break ;
276
305
277
306
// Workspace
278
307
case WorkspaceProvider . QUERY_PARAM_WORKSPACE :
308
+ /**
309
+ * Handle URIs that we previously left unencoded and de-schemed.
310
+ *
311
+ * @author coder
312
+ */
313
+ value = toRemote ( value ) ;
279
314
workspace = { workspaceUri : URI . parse ( value ) } ;
280
315
foundWorkspace = true ;
281
316
break ;
@@ -352,13 +387,27 @@ class WorkspaceProvider implements IWorkspaceProvider {
352
387
}
353
388
354
389
// Folder
390
+ /**
391
+ * Modified to print as a human-readable string for file paths.
392
+ * @author coder
393
+ */
355
394
else if ( isFolderToOpen ( workspace ) ) {
356
- targetHref = `${ document . location . origin } ${ document . location . pathname } ?${ WorkspaceProvider . QUERY_PARAM_FOLDER } =${ encodeURIComponent ( workspace . folderUri . toString ( ) ) } ` ;
395
+ const target = workspace . folderUri . scheme === Schemas . vscodeRemote
396
+ ? encodePath ( workspace . folderUri . path )
397
+ : encodeURIComponent ( workspace . folderUri . toString ( ) ) ;
398
+ targetHref = `${ document . location . origin } ${ document . location . pathname } ?${ WorkspaceProvider . QUERY_PARAM_FOLDER } =${ target } ` ;
357
399
}
358
400
359
401
// Workspace
402
+ /**
403
+ * Modified to print as a human-readable string for file paths.
404
+ * @author coder
405
+ */
360
406
else if ( isWorkspaceToOpen ( workspace ) ) {
361
- targetHref = `${ document . location . origin } ${ document . location . pathname } ?${ WorkspaceProvider . QUERY_PARAM_WORKSPACE } =${ encodeURIComponent ( workspace . workspaceUri . toString ( ) ) } ` ;
407
+ const target = workspace . workspaceUri . scheme === Schemas . vscodeRemote
408
+ ? encodePath ( workspace . workspaceUri . path )
409
+ : encodeURIComponent ( workspace . workspaceUri . toString ( ) ) ;
410
+ targetHref = `${ document . location . origin } ${ document . location . pathname } ?${ WorkspaceProvider . QUERY_PARAM_WORKSPACE } =${ target } ` ;
362
411
}
363
412
364
413
// Append payload if any
0 commit comments