1
1
import * as path from "path" ;
2
2
import * as vscode from "vscode" ;
3
+ import * as url from "url" ;
3
4
import { AtelierAPI } from "../../api" ;
4
5
import { Directory } from "./Directory" ;
5
6
import { File } from "./File" ;
@@ -26,17 +27,36 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
26
27
public async readDirectory ( uri : vscode . Uri ) : Promise < [ string , vscode . FileType ] [ ] > {
27
28
const api = new AtelierAPI ( uri ) ;
28
29
const parent = await this . _lookupAsDirectory ( uri ) ;
29
- const sql = `CALL %Library.RoutineMgr_StudioOpenDialog(?,,,,,,0)` ;
30
- const folder = uri . path === "/" ? "/" : uri . path . replace ( / \/ / g, "." ) + "/" ;
31
- const spec = folder . slice ( 1 ) + "*.cls,*.inc,*.int,*.mac" ;
30
+ const sql = `CALL %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)` ;
31
+ const { query } = url . parse ( decodeURIComponent ( uri . toString ( ) ) , true ) ;
32
+ const type = String ( query && query . type ) . toLowerCase ( ) || "all" ;
33
+ const csp = query . csp === "" || query . csp === "1" ;
34
+ let filter = query . filter || "" ;
35
+ if ( csp ) {
36
+ filter = filter || "*" ;
37
+ } else if ( type === "rtn" ) {
38
+ filter = "*.inc,*.int,*.mac" ;
39
+ } else if ( type === "cls" ) {
40
+ filter = "*.cls" ;
41
+ } else {
42
+ filter = query . filter || "*.cls,*.inc,*.int,*.mac" ;
43
+ }
44
+ const folder = csp ? ( uri . path . endsWith ( "/" ) ? uri . path : uri . path + "/" ) : uri . path . replace ( / \/ / g, "." ) ;
45
+ const spec = csp ? folder + filter : folder . slice ( 1 ) + filter ;
46
+ const dir = "1" ;
47
+ const orderBy = "1" ;
48
+ const system = api . ns === "%SYS" ? "1" : "0" ;
49
+ const flat = String ( query . flat ) || "0" ;
50
+ const notStudio = "0" ;
51
+ const generated = String ( query . generated ) || "0" ;
32
52
return api
33
- . actionQuery ( sql , [ spec ] )
53
+ . actionQuery ( sql , [ spec , dir , orderBy , system , flat , notStudio , generated ] )
34
54
. then ( data => data . result . content || [ ] )
35
55
. then ( data =>
36
56
data . map ( item => {
37
57
const name = item . Name ;
38
58
const fullName = folder === "" ? name : folder + "/" + name ;
39
- if ( item . IsDirectory . length ) {
59
+ if ( item . Type === "10" || item . Type === "9" ) {
40
60
parent . entries . set ( name , new Directory ( name , fullName ) ) ;
41
61
return [ name , vscode . FileType . Directory ] ;
42
62
} else {
@@ -76,7 +96,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
76
96
overwrite : boolean ;
77
97
}
78
98
) : void | Thenable < void > {
79
- const fileName = uri . path . slice ( 1 ) . replace ( / \/ / g, "." ) ;
99
+ const { query } = url . parse ( decodeURIComponent ( uri . toString ( ) ) , true ) ;
100
+ const csp = query . csp === "" || query . csp === "1" ;
101
+ const fileName = csp ? uri . path : uri . path . slice ( 1 ) . replace ( / \/ / g, "." ) ;
80
102
if ( fileName . startsWith ( "." ) ) {
81
103
return ;
82
104
}
@@ -143,10 +165,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
143
165
}
144
166
145
167
private async _lookupAsFile ( uri : vscode . Uri ) : Promise < File > {
146
- // if (!uri.path.match(/\.\w+$/)) {
147
- // return Promise.resolve(new Directory(uri.path))
148
- // }
149
- const fileName = uri . path . slice ( 1 ) . replace ( / \/ / g, "." ) ;
168
+ const { query } = url . parse ( decodeURIComponent ( uri . toString ( ) ) , true ) ;
169
+ const csp = query . csp === "" || query . csp === "1" ;
170
+ const fileName = csp ? uri . path : uri . path . slice ( 1 ) . replace ( / \/ / g, "." ) ;
150
171
if ( fileName . startsWith ( "." ) ) {
151
172
throw vscode . FileSystemError . FileNotFound ( ) ;
152
173
}
@@ -155,7 +176,16 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
155
176
return api
156
177
. getDoc ( fileName )
157
178
. then ( data => data . result )
158
- . then ( ( { ts, content } ) => new File ( name , fileName , ts , content . join ( "\n" ) . length , content . join ( "\n" ) ) )
179
+ . then (
180
+ ( { ts, content } ) =>
181
+ new File (
182
+ name ,
183
+ fileName ,
184
+ ts ,
185
+ Array . isArray ( content ) ? content . join ( "\n" ) . length : content . length ,
186
+ Array . isArray ( content ) ? content . join ( "\n" ) : content
187
+ )
188
+ )
159
189
. then ( entry =>
160
190
this . _lookupParentDirectory ( uri ) . then ( parent => {
161
191
parent . entries . set ( name , entry ) ;
0 commit comments