@@ -10,7 +10,6 @@ import * as tls from "tls";
10
10
import * as url from "url" ;
11
11
import * as util from "util" ;
12
12
import { Emitter } from "vs/base/common/event" ;
13
- import { sanitizeFilePath } from "vs/base/common/extpath" ;
14
13
import { Schemas } from "vs/base/common/network" ;
15
14
import { URI , UriComponents } from "vs/base/common/uri" ;
16
15
import { generateUuid } from "vs/base/common/uuid" ;
@@ -574,6 +573,7 @@ export class MainServer extends Server {
574
573
}
575
574
576
575
private async getRoot ( request : http . IncomingMessage , parsedUrl : url . UrlWithParsedQuery ) : Promise < Response > {
576
+ const remoteAuthority = request . headers . host as string ;
577
577
const filePath = path . join ( this . serverRoot , "browser/workbench.html" ) ;
578
578
let [ content , startPath ] = await Promise . all ( [
579
579
util . promisify ( fs . readFile ) ( filePath , "utf8" ) ,
@@ -582,14 +582,14 @@ export class MainServer extends Server {
582
582
{ path : parsedUrl . query . folder , workspace : false } ,
583
583
( await this . readSettings ( ) ) . lastVisited ,
584
584
{ path : this . options . openUri }
585
- ] ) ,
585
+ ] , remoteAuthority ) ,
586
586
this . servicesPromise ,
587
587
] ) ;
588
588
589
589
if ( startPath ) {
590
590
this . writeSettings ( {
591
591
lastVisited : {
592
- path : startPath . uri . fsPath ,
592
+ path : startPath . uri ,
593
593
workspace : startPath . workspace
594
594
} ,
595
595
} ) ;
@@ -598,14 +598,13 @@ export class MainServer extends Server {
598
598
const logger = this . services . get ( ILogService ) as ILogService ;
599
599
logger . info ( "request.url" , `"${ request . url } "` ) ;
600
600
601
- const remoteAuthority = request . headers . host as string ;
602
601
const transformer = getUriTransformer ( remoteAuthority ) ;
603
602
604
603
const environment = this . services . get ( IEnvironmentService ) as IEnvironmentService ;
605
604
const options : Options = {
606
605
WORKBENCH_WEB_CONFIGURATION : {
607
- workspaceUri : startPath && startPath . workspace ? transformer . transformOutgoing ( startPath . uri ) : undefined ,
608
- folderUri : startPath && ! startPath . workspace ? transformer . transformOutgoing ( startPath . uri ) : undefined ,
606
+ workspaceUri : startPath && startPath . workspace ? URI . parse ( startPath . uri ) : undefined ,
607
+ folderUri : startPath && ! startPath . workspace ? URI . parse ( startPath . uri ) : undefined ,
609
608
remoteAuthority,
610
609
logLevel : getLogLevel ( environment ) ,
611
610
} ,
@@ -631,21 +630,29 @@ export class MainServer extends Server {
631
630
* workspace or a directory are acceptable. Otherwise it must be a file if a
632
631
* workspace or a directory otherwise.
633
632
*/
634
- private async getFirstValidPath ( startPaths : Array < StartPath | undefined > ) : Promise < { uri : URI , workspace ?: boolean } | undefined > {
633
+ private async getFirstValidPath ( startPaths : Array < StartPath | undefined > , remoteAuthority : string ) : Promise < { uri : string , workspace ?: boolean } | undefined > {
635
634
const logger = this . services . get ( ILogService ) as ILogService ;
636
- const cwd = process . env . VSCODE_CWD || process . cwd ( ) ;
637
635
for ( let i = 0 ; i < startPaths . length ; ++ i ) {
638
636
const startPath = startPaths [ i ] ;
639
637
if ( ! startPath ) {
640
638
continue ;
641
639
}
642
640
const paths = typeof startPath . path === "string" ? [ startPath . path ] : ( startPath . path || [ ] ) ;
643
641
for ( let j = 0 ; j < paths . length ; ++ j ) {
644
- const uri = URI . file ( sanitizeFilePath ( paths [ j ] , cwd ) ) ;
642
+ const uri = url . parse ( paths [ j ] ) ;
645
643
try {
646
- const stat = await util . promisify ( fs . stat ) ( uri . fsPath ) ;
644
+ if ( ! uri . pathname ) {
645
+ throw new Error ( `${ paths [ j ] } is not valid` ) ;
646
+ }
647
+ const stat = await util . promisify ( fs . stat ) ( uri . pathname ) ;
647
648
if ( typeof startPath . workspace === "undefined" || startPath . workspace !== stat . isDirectory ( ) ) {
648
- return { uri, workspace : ! stat . isDirectory ( ) } ;
649
+ return { uri : url . format ( {
650
+ protocol : uri . protocol || "vscode-remote" ,
651
+ hostname : remoteAuthority . split ( ":" ) [ 0 ] ,
652
+ port : remoteAuthority . split ( ":" ) [ 1 ] ,
653
+ pathname : uri . pathname ,
654
+ slashes : true ,
655
+ } ) , workspace : ! stat . isDirectory ( ) } ;
649
656
}
650
657
} catch ( error ) {
651
658
logger . warn ( error . message ) ;
0 commit comments