@@ -617,6 +617,35 @@ export async function shellWithDocker(): Promise<vscode.Terminal> {
617
617
return terminal ;
618
618
}
619
619
620
+ interface WSServerRootFolderData {
621
+ redirectDotvscode : boolean ;
622
+ }
623
+
624
+ const wsServerRootFolders = new Map < string , WSServerRootFolderData > ( ) ;
625
+
626
+ /**
627
+ * Add uri to the wsServerRootFolders map if eligible
628
+ */
629
+ export async function addWsServerRootFolderData ( uri : vscode . Uri ) : Promise < void > {
630
+ if ( ! schemas . includes ( uri . scheme ) ) {
631
+ return ;
632
+ }
633
+ const value : WSServerRootFolderData = {
634
+ redirectDotvscode : true ,
635
+ } ;
636
+ if ( isCSPFile ( uri ) && ! [ "" , "/" ] . includes ( uri . path ) ) {
637
+ // A CSP-type root folder for a specific webapp that already has a .vscode/settings.json file must not redirect .vscode/* references
638
+ const api = new AtelierAPI ( uri ) ;
639
+ api
640
+ . headDoc ( `${ uri . path } ${ ! uri . path . endsWith ( "/" ) ? "/" : "" } .vscode/settings.json` )
641
+ . then ( ( ) => {
642
+ value . redirectDotvscode = false ;
643
+ } )
644
+ . catch ( ( ) => { } ) ;
645
+ }
646
+ wsServerRootFolders . set ( uri . toString ( ) , value ) ;
647
+ }
648
+
620
649
/**
621
650
* Alter isfs-type uri.path of /.vscode/* files or subdirectories.
622
651
* Rewrite `/.vscode/path/to/file` as `/_vscode/XYZ/path/to/file`
@@ -633,13 +662,18 @@ export function redirectDotvscodeRoot(uri: vscode.Uri): vscode.Uri {
633
662
if ( ! schemas . includes ( uri . scheme ) ) {
634
663
return uri ;
635
664
}
636
- const dotMatch = uri . path . match ( / ^ \/ ( \. [ ^ / ] * ) ( \/ .* ) ? $ / ) ;
637
- if ( dotMatch && dotMatch [ 1 ] === ".vscode" ) {
665
+ const dotMatch = uri . path . match ( / ^ ( .* ) \/ \. v s c o d e ( \/ .* ) ? $ / ) ;
666
+ if ( dotMatch ) {
667
+ const dotvscodeRoot = uri . with ( { path : dotMatch [ 1 ] || "/" } ) ;
668
+ if ( ! wsServerRootFolders . get ( dotvscodeRoot . toString ( ) ) ?. redirectDotvscode ) {
669
+ return uri ;
670
+ }
638
671
let namespace : string ;
672
+ const andCSP = ! isCSPFile ( uri ) ? "&csp" : "" ;
639
673
const nsMatch = `&${ uri . query } &` . match ( / & n s = ( [ ^ & ] + ) & / ) ;
640
674
if ( nsMatch ) {
641
675
namespace = nsMatch [ 1 ] . toUpperCase ( ) ;
642
- const newQueryString = ( ( "&" + uri . query ) . replace ( `ns=${ namespace } ` , "ns=%SYS" ) + "&csp" ) . slice ( 1 ) ;
676
+ const newQueryString = ( ( "&" + uri . query ) . replace ( `ns=${ namespace } ` , "ns=%SYS" ) + andCSP ) . slice ( 1 ) ;
643
677
return uri . with ( { path : `/_vscode/${ namespace } ${ dotMatch [ 2 ] || "" } ` , query : newQueryString } ) ;
644
678
} else {
645
679
const parts = uri . authority . split ( ":" ) ;
@@ -648,7 +682,7 @@ export function redirectDotvscodeRoot(uri: vscode.Uri): vscode.Uri {
648
682
return uri . with ( {
649
683
authority : `${ parts [ 0 ] } :%SYS` ,
650
684
path : `/_vscode/${ namespace } ${ dotMatch [ 2 ] || "" } ` ,
651
- query : uri . query + "&csp" ,
685
+ query : uri . query + andCSP ,
652
686
} ) ;
653
687
}
654
688
}
0 commit comments