@@ -143,24 +143,42 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
143
143
} ) ;
144
144
}
145
145
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" ) ;
147
148
const fileExt = fileName . split ( "." ) . pop ( ) . toLowerCase ( ) ;
148
149
if ( fileExt === "cls" ) {
149
150
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
+ }
150
167
return {
151
- content : [ `Class ${ className } {}` ] ,
168
+ content,
152
169
enc : false ,
153
170
} ;
154
171
} else if ( [ "int" , "inc" , "mac" ] . includes ( fileExt ) ) {
172
+ sourceLines . shift ( ) ;
155
173
const routineName = fileName . split ( "." ) . slice ( 0 , - 1 ) . join ( "." ) ;
156
174
const routineType = `[ type = ${ fileExt } ]` ;
157
175
return {
158
- content : [ `ROUTINE ${ routineName } ${ routineType } ` ] ,
176
+ content : [ `ROUTINE ${ routineName } ${ routineType } ` , ... sourceLines ] ,
159
177
enc : false ,
160
178
} ;
161
179
}
162
180
return {
163
- content : [ content . toString ( "base64" ) ] ,
181
+ content : [ sourceContent . toString ( "base64" ) ] ,
164
182
enc : true ,
165
183
} ;
166
184
}
@@ -266,27 +284,31 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
266
284
return ;
267
285
}
268
286
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 ;
272
304
}
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
+ ) ;
280
306
}
281
307
282
308
public rename ( oldUri : vscode . Uri , newUri : vscode . Uri , options : { overwrite : boolean } ) : void | Thenable < void > {
283
309
throw new Error ( "Not implemented" ) ;
284
310
return ;
285
311
}
286
- public copy ?( source : vscode . Uri , destination : vscode . Uri , options : { overwrite : boolean } ) : void | Thenable < void > {
287
- throw new Error ( "Not implemented" ) ;
288
- return ;
289
- }
290
312
291
313
public watch ( uri : vscode . Uri ) : vscode . Disposable {
292
314
return new vscode . Disposable ( ( ) => {
0 commit comments