@@ -167,18 +167,22 @@ export class VscodeHttpProvider extends HttpProvider {
167
167
}
168
168
169
169
private async getRoot ( request : http . IncomingMessage , route : Route ) : Promise < HttpResponse > {
170
+ const remoteAuthority = request . headers . host as string
170
171
const settings = await this . settings . read ( )
171
- const startPath = await this . getFirstValidPath ( [
172
- { url : route . query . workspace , workspace : true } ,
173
- { url : route . query . folder , workspace : false } ,
174
- settings . lastVisited ,
175
- this . args . _ && this . args . _ . length > 0 ? { url : this . urlify ( this . args . _ [ 0 ] ) } : undefined ,
176
- ] )
172
+ const startPath = await this . getFirstValidPath (
173
+ [
174
+ { url : route . query . workspace , workspace : true } ,
175
+ { url : route . query . folder , workspace : false } ,
176
+ settings . lastVisited ,
177
+ this . args . _ && this . args . _ . length > 0 ? { url : this . args . _ [ 0 ] } : undefined ,
178
+ ] ,
179
+ remoteAuthority
180
+ )
177
181
const [ response , options ] = await Promise . all ( [
178
182
await this . getUtf8Resource ( this . rootPath , `src/node/vscode/workbench${ ! this . isDev ? "-build" : "" } .html` ) ,
179
183
this . initialize ( {
180
184
args : this . args ,
181
- remoteAuthority : request . headers . host as string ,
185
+ remoteAuthority,
182
186
startPath,
183
187
} ) ,
184
188
] )
@@ -217,7 +221,8 @@ export class VscodeHttpProvider extends HttpProvider {
217
221
* workspace or a directory otherwise.
218
222
*/
219
223
private async getFirstValidPath (
220
- startPaths : Array < { url ?: string | string [ ] ; workspace ?: boolean } | undefined >
224
+ startPaths : Array < { url ?: string | string [ ] ; workspace ?: boolean } | undefined > ,
225
+ remoteAuthority : string
221
226
) : Promise < StartPath | undefined > {
222
227
for ( let i = 0 ; i < startPaths . length ; ++ i ) {
223
228
const startPath = startPaths [ i ]
@@ -226,14 +231,23 @@ export class VscodeHttpProvider extends HttpProvider {
226
231
}
227
232
const paths = typeof startPath . url === "string" ? [ startPath . url ] : startPath . url || [ ]
228
233
for ( let j = 0 ; j < paths . length ; ++ j ) {
229
- const u = url . parse ( paths [ j ] )
234
+ const uri = url . parse ( paths [ j ] )
230
235
try {
231
- if ( ! u . pathname ) {
236
+ if ( ! uri . pathname ) {
232
237
throw new Error ( `${ paths [ j ] } is not a valid URL` )
233
238
}
234
- const stat = await fs . stat ( u . pathname )
239
+ const stat = await fs . stat ( uri . pathname )
235
240
if ( typeof startPath . workspace === "undefined" || startPath . workspace !== stat . isDirectory ( ) ) {
236
- return { url : u . href , workspace : ! stat . isDirectory ( ) }
241
+ return {
242
+ url : url . format ( {
243
+ protocol : uri . protocol || "vscode-remote" ,
244
+ hostname : remoteAuthority . split ( ":" ) [ 0 ] ,
245
+ port : remoteAuthority . split ( ":" ) [ 1 ] ,
246
+ pathname : uri . pathname ,
247
+ slashes : true ,
248
+ } ) ,
249
+ workspace : ! stat . isDirectory ( ) ,
250
+ }
237
251
}
238
252
} catch ( error ) {
239
253
logger . warn ( error . message )
@@ -242,8 +256,4 @@ export class VscodeHttpProvider extends HttpProvider {
242
256
}
243
257
return undefined
244
258
}
245
-
246
- private urlify ( p : string ) : string {
247
- return "vscode-remote://host" + path . resolve ( p )
248
- }
249
259
}
0 commit comments