@@ -6,6 +6,7 @@ import { Directory } from "./Directory";
66import { File } from "./File" ;
77import { fireOtherStudioAction , OtherStudioAction } from "../../commands/studio" ;
88import { StudioOpenDialog } from "../../queries" ;
9+ import { redirectDotvscodeRoot } from "../../utils/index" ;
910
1011declare function setTimeout ( callback : ( ...args : any [ ] ) => void , ms : number , ...args : any [ ] ) : NodeJS . Timeout ;
1112
@@ -61,7 +62,13 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
6162 } else {
6263 filter = "*.cls,*.inc,*.mac,*.int" ;
6364 }
64- const folder = csp ? ( uri . path . endsWith ( "/" ) ? uri . path : uri . path + "/" ) : uri . path . replace ( / \/ / g, "." ) ;
65+ const folder = ! csp
66+ ? uri . path . replace ( / \/ / g, "." )
67+ : uri . path === "/"
68+ ? ""
69+ : uri . path . endsWith ( "/" )
70+ ? uri . path
71+ : uri . path + "/" ;
6572 const spec = csp ? folder + filter : folder . length > 1 ? folder . slice ( 1 ) + "/" + filter : filter ;
6673 const dir = "1" ;
6774 const orderBy = "1" ;
@@ -72,18 +79,48 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
7279 return api
7380 . actionQuery ( sql , [ spec , dir , orderBy , system , flat , notStudio , generated ] )
7481 . then ( ( data ) => data . result . content || [ ] )
75- . then ( ( data ) =>
76- data . map ( ( item : StudioOpenDialog ) => {
77- const name = item . Name ;
82+ . then ( ( data ) => {
83+ const results = data . map ( ( item : StudioOpenDialog ) => {
84+ // Handle how query returns web apps
85+ const name = item . Name . split ( "/" ) [ 0 ] ;
7886 const fullName = folder === "" ? name : folder + "/" + name ;
7987 if ( item . Type === "10" || item . Type === "9" ) {
8088 parent . entries . set ( name , new Directory ( name , fullName ) ) ;
8189 return [ name , vscode . FileType . Directory ] ;
8290 } else {
8391 return [ name , vscode . FileType . File ] ;
8492 }
85- } )
86- )
93+ } ) ;
94+ if ( ! csp || results . length ) {
95+ return results ;
96+ }
97+ //TODO further request(s) to get the next level in CSP app names
98+ // e.g. folder root is isfs://server/?ns=USER&csp
99+ // and USER namespace is the home of /csp/app1 and /csp/app2
100+ // Initial expand showed the csp folder.
101+ // Expand of that came here and asked Studio dialog query for /csp/*
102+ // but this doesn't return app1 and app2 folders.
103+ return api
104+ . actionQuery ( sql , [ "/*.CSPALL" , dir , orderBy , system , flat , notStudio , generated ] )
105+ . then ( ( data ) => data . result . content || [ ] )
106+ . then ( ( data ) => {
107+ return results ;
108+ /*
109+ const results = data.map((item: StudioOpenDialog) => {
110+ // Handle how query returns web apps
111+ const name = item.Name.split("/")[0];
112+ const fullName = folder === "" ? name : folder + "/" + name;
113+ if (item.Type === "10" || item.Type === "9") {
114+ parent.entries.set(name, new Directory(name, fullName));
115+ return [name, vscode.FileType.Directory];
116+ } else {
117+ return [name, vscode.FileType.File];
118+ }
119+ });
120+ return results;
121+ */
122+ } ) ;
123+ } )
87124 . catch ( ( error ) => {
88125 error && console . error ( error ) ;
89126 } ) ;
@@ -138,16 +175,17 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
138175 overwrite : boolean ;
139176 }
140177 ) : void | Thenable < void > {
141- if ( uri . path . match ( / \/ \. [ ^ / ] * \/ / ) ) {
178+ uri = redirectDotvscodeRoot ( uri ) ;
179+ if ( uri . path . startsWith ( "/." ) ) {
142180 throw vscode . FileSystemError . NoPermissions ( "dot-folders not supported by server" ) ;
143181 }
182+ const api = new AtelierAPI ( uri ) ;
144183 const { query } = url . parse ( decodeURIComponent ( uri . toString ( ) ) , true ) ;
145184 const csp = query . csp === "" || query . csp === "1" ;
146185 const fileName = csp ? uri . path : uri . path . slice ( 1 ) . replace ( / \/ / g, "." ) ;
147186 if ( fileName . startsWith ( "." ) ) {
148187 return ;
149188 }
150- const api = new AtelierAPI ( uri ) ;
151189 return this . _lookupAsFile ( uri ) . then (
152190 ( ) => {
153191 // Weirdly, if the file exists on the server we don't actually write its content here.
@@ -274,15 +312,16 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
274312
275313 // Fetch from server and cache it
276314 private async _lookupAsFile ( uri : vscode . Uri ) : Promise < File > {
277- // Reject attempts to access files in .-folders such as .vscode and .git
278- if ( uri . path . match ( / \/ \. [ ^ / ] * \/ / ) ) {
279- throw vscode . FileSystemError . FileNotFound ( "dot-folders not supported by server" ) ;
315+ uri = redirectDotvscodeRoot ( uri ) ;
316+ if ( uri . path . startsWith ( "/." ) ) {
317+ throw vscode . FileSystemError . NoPermissions ( "dot-folders not supported by server" ) ;
280318 }
319+
320+ const api = new AtelierAPI ( uri ) ;
281321 const { query } = url . parse ( decodeURIComponent ( uri . toString ( ) ) , true ) ;
282322 const csp = query . csp === "" || query . csp === "1" ;
283323 const fileName = csp ? uri . path : uri . path . slice ( 1 ) . replace ( / \/ / g, "." ) ;
284324 const name = path . basename ( uri . path ) ;
285- const api = new AtelierAPI ( uri ) ;
286325 return api
287326 . getDoc ( fileName )
288327 . then ( ( data ) => data . result )
0 commit comments