33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { URI } from 'vs/base/common/uri' ;
6+ import { URI , UriComponents } from 'vs/base/common/uri' ;
77import * as platform from 'vs/base/common/platform' ;
88
99export namespace Schemas {
@@ -60,18 +60,24 @@ class RemoteAuthoritiesImpl {
6060 private readonly _ports : { [ authority : string ] : number ; } ;
6161 private readonly _connectionTokens : { [ authority : string ] : string ; } ;
6262 private _preferredWebSchema : 'http' | 'https' ;
63+ private _delegate : ( ( uri : URI ) => UriComponents ) | null ;
6364
6465 constructor ( ) {
6566 this . _hosts = Object . create ( null ) ;
6667 this . _ports = Object . create ( null ) ;
6768 this . _connectionTokens = Object . create ( null ) ;
6869 this . _preferredWebSchema = 'http' ;
70+ this . _delegate = null ;
6971 }
7072
7173 public setPreferredWebSchema ( schema : 'http' | 'https' ) {
7274 this . _preferredWebSchema = schema ;
7375 }
7476
77+ public setDelegate ( delegate : ( uri : URI ) => UriComponents ) : void {
78+ this . _delegate = delegate ;
79+ }
80+
7581 public set ( authority : string , host : string , port : number ) : void {
7682 this . _hosts [ authority ] = host ;
7783 this . _ports [ authority ] = port ;
@@ -81,15 +87,20 @@ class RemoteAuthoritiesImpl {
8187 this . _connectionTokens [ authority ] = connectionToken ;
8288 }
8389
84- public rewrite ( authority : string , path : string ) : URI {
90+ public rewrite ( uri : URI ) : URI {
91+ if ( this . _delegate ) {
92+ const result = this . _delegate ( uri ) ;
93+ return URI . revive ( result ) ;
94+ }
95+ const authority = uri . authority ;
8596 const host = this . _hosts [ authority ] ;
8697 const port = this . _ports [ authority ] ;
8798 const connectionToken = this . _connectionTokens [ authority ] ;
8899 return URI . from ( {
89100 scheme : platform . isWeb ? this . _preferredWebSchema : Schemas . vscodeRemoteResource ,
90101 authority : `${ host } :${ port } ` ,
91102 path : `/vscode-remote-resource` ,
92- query : `path=${ encodeURIComponent ( path ) } &tkn=${ encodeURIComponent ( connectionToken ) } `
103+ query : `path=${ encodeURIComponent ( uri . path ) } &tkn=${ encodeURIComponent ( connectionToken ) } `
93104 } ) ;
94105 }
95106}
0 commit comments