@@ -143,24 +143,42 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
143143 } ) ;
144144 }
145145
146- private generateFileContent ( fileName : string , content : Buffer ) : { content : string [ ] ; enc : boolean } {
146+ private generateFileContent ( fileName : string , sourceContent : Buffer ) : { content : string [ ] ; enc : boolean } {
147+ const sourceLines = sourceContent . toString ( ) . split ( "\n" ) ;
147148 const fileExt = fileName . split ( "." ) . pop ( ) . toLowerCase ( ) ;
148149 if ( fileExt === "cls" ) {
149150 const className = fileName . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
151+ const content : string [ ] = [ ] ;
152+ const preamble : string [ ] = [ ] ;
153+
154+ // If content was provided (e.g. when copying a file), use all lines except for
155+ // the Class x.y one. Replace that with one to match fileName.
156+ while ( sourceLines . length > 0 ) {
157+ const nextLine = sourceLines . shift ( ) ;
158+ if ( nextLine . startsWith ( "Class " ) ) {
159+ content . push ( ...preamble , `Class ${ className } ` , ...sourceLines ) ;
160+ break ;
161+ }
162+ preamble . push ( nextLine ) ;
163+ }
164+ if ( content . length === 0 ) {
165+ content . push ( `Class ${ className } ` , "{" , "}" ) ;
166+ }
150167 return {
151- content : [ `Class ${ className } {}` ] ,
168+ content,
152169 enc : false ,
153170 } ;
154171 } else if ( [ "int" , "inc" , "mac" ] . includes ( fileExt ) ) {
172+ sourceLines . shift ( ) ;
155173 const routineName = fileName . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
156174 const routineType = `[ type = ${ fileExt } ]` ;
157175 return {
158- content : [ `ROUTINE ${ routineName } ${ routineType } ` ] ,
176+ content : [ `ROUTINE ${ routineName } ${ routineType } ` , ... sourceLines ] ,
159177 enc : false ,
160178 } ;
161179 }
162180 return {
163- content : [ content . toString ( "base64" ) ] ,
181+ content : [ sourceContent . toString ( "base64" ) ] ,
164182 enc : true ,
165183 } ;
166184 }
@@ -266,27 +284,31 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
266284 return ;
267285 }
268286 const api = new AtelierAPI ( uri ) ;
269- return api . deleteDoc ( fileName ) . then ( ( response ) => {
270- if ( response . result . ext ) {
271- fireOtherStudioAction ( OtherStudioAction . DeletedDocument , uri , response . result . ext ) ;
287+ return api . deleteDoc ( fileName ) . then (
288+ ( response ) => {
289+ if ( response . result . ext ) {
290+ fireOtherStudioAction ( OtherStudioAction . DeletedDocument , uri , response . result . ext ) ;
291+ }
292+ // Remove entry from our cache
293+ this . _lookupParentDirectory ( uri ) . then ( ( parent ) => {
294+ const name = path . basename ( uri . path ) ;
295+ parent . entries . delete ( name ) ;
296+ } ) ;
297+ this . _fireSoon ( { type : vscode . FileChangeType . Deleted , uri } ) ;
298+ } ,
299+ ( error ) => {
300+ if ( error . statusCode === 200 && error . errorText !== "" ) {
301+ error . message = error . errorText ;
302+ }
303+ throw error ;
272304 }
273- // Remove entry from our cache
274- this . _lookupParentDirectory ( uri ) . then ( ( parent ) => {
275- const name = path . basename ( uri . path ) ;
276- parent . entries . delete ( name ) ;
277- } ) ;
278- this . _fireSoon ( { type : vscode . FileChangeType . Deleted , uri } ) ;
279- } ) ;
305+ ) ;
280306 }
281307
282308 public rename ( oldUri : vscode . Uri , newUri : vscode . Uri , options : { overwrite : boolean } ) : void | Thenable < void > {
283309 throw new Error ( "Not implemented" ) ;
284310 return ;
285311 }
286- public copy ?( source : vscode . Uri , destination : vscode . Uri , options : { overwrite : boolean } ) : void | Thenable < void > {
287- throw new Error ( "Not implemented" ) ;
288- return ;
289- }
290312
291313 public watch ( uri : vscode . Uri ) : vscode . Disposable {
292314 return new vscode . Disposable ( ( ) => {
0 commit comments