@@ -14,6 +14,46 @@ declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...a
1414
1515export type Entry = File | Directory ;
1616
17+ export function generateFileContent ( fileName : string , sourceContent : Buffer ) : { content : string [ ] ; enc : boolean } {
18+ const sourceLines = sourceContent . toString ( ) . split ( "\n" ) ;
19+ const fileExt = fileName . split ( "." ) . pop ( ) . toLowerCase ( ) ;
20+ if ( fileExt === "cls" ) {
21+ const className = fileName . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
22+ const content : string [ ] = [ ] ;
23+ const preamble : string [ ] = [ ] ;
24+
25+ // If content was provided (e.g. when copying a file), use all lines except for
26+ // the Class x.y one. Replace that with one to match fileName.
27+ while ( sourceLines . length > 0 ) {
28+ const nextLine = sourceLines . shift ( ) ;
29+ if ( nextLine . startsWith ( "Class " ) ) {
30+ content . push ( ...preamble , `Class ${ className } ` , ...sourceLines ) ;
31+ break ;
32+ }
33+ preamble . push ( nextLine ) ;
34+ }
35+ if ( content . length === 0 ) {
36+ content . push ( `Class ${ className } ` , "{" , "}" ) ;
37+ }
38+ return {
39+ content,
40+ enc : false ,
41+ } ;
42+ } else if ( [ "int" , "inc" , "mac" ] . includes ( fileExt ) ) {
43+ sourceLines . shift ( ) ;
44+ const routineName = fileName . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
45+ const routineType = `[ type = ${ fileExt } ]` ;
46+ return {
47+ content : [ `ROUTINE ${ routineName } ${ routineType } ` , ...sourceLines ] ,
48+ enc : false ,
49+ } ;
50+ }
51+ return {
52+ content : [ sourceContent . toString ( "base64" ) ] ,
53+ enc : true ,
54+ } ;
55+ }
56+
1757export class FileSystemProvider implements vscode . FileSystemProvider {
1858 private superRoot = new Directory ( "" , "" ) ;
1959
@@ -151,46 +191,6 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
151191 } ) ;
152192 }
153193
154- private generateFileContent ( fileName : string , sourceContent : Buffer ) : { content : string [ ] ; enc : boolean } {
155- const sourceLines = sourceContent . toString ( ) . split ( "\n" ) ;
156- const fileExt = fileName . split ( "." ) . pop ( ) . toLowerCase ( ) ;
157- if ( fileExt === "cls" ) {
158- const className = fileName . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
159- const content : string [ ] = [ ] ;
160- const preamble : string [ ] = [ ] ;
161-
162- // If content was provided (e.g. when copying a file), use all lines except for
163- // the Class x.y one. Replace that with one to match fileName.
164- while ( sourceLines . length > 0 ) {
165- const nextLine = sourceLines . shift ( ) ;
166- if ( nextLine . startsWith ( "Class " ) ) {
167- content . push ( ...preamble , `Class ${ className } ` , ...sourceLines ) ;
168- break ;
169- }
170- preamble . push ( nextLine ) ;
171- }
172- if ( content . length === 0 ) {
173- content . push ( `Class ${ className } ` , "{" , "}" ) ;
174- }
175- return {
176- content,
177- enc : false ,
178- } ;
179- } else if ( [ "int" , "inc" , "mac" ] . includes ( fileExt ) ) {
180- sourceLines . shift ( ) ;
181- const routineName = fileName . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
182- const routineType = `[ type = ${ fileExt } ]` ;
183- return {
184- content : [ `ROUTINE ${ routineName } ${ routineType } ` , ...sourceLines ] ,
185- enc : false ,
186- } ;
187- }
188- return {
189- content : [ sourceContent . toString ( "base64" ) ] ,
190- enc : true ,
191- } ;
192- }
193-
194194 public writeFile (
195195 uri : vscode . Uri ,
196196 content : Buffer ,
@@ -250,7 +250,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
250250 }
251251 // File doesn't exist on the server, and we are allowed to create it.
252252 // Create content (typically a stub).
253- const newContent = this . generateFileContent ( fileName , content ) ;
253+ const newContent = generateFileContent ( fileName , content ) ;
254254
255255 // Write it to the server
256256 return api
0 commit comments