File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
src/providers/FileSystemProvider Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -185,13 +185,26 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
185
185
// Weirdly, if the file exists on the server we don't actually write its content here.
186
186
// Instead we simply return as though we wrote it successfully.
187
187
// The actual writing is done by our workspace.onDidSaveTextDocument handler.
188
- // But first check a case for which we should fail the write and leave the document dirty if changed.
188
+ // But first check cases for which we should fail the write and leave the document dirty if changed.
189
189
if ( fileName . split ( "." ) . pop ( ) . toLowerCase ( ) === "cls" ) {
190
+ // Check if the class is deployed
190
191
api . actionIndex ( [ fileName ] ) . then ( ( result ) => {
191
192
if ( result . result . content [ 0 ] . content . depl ) {
192
193
throw new Error ( "Cannot overwrite a deployed class" ) ;
193
194
}
194
195
} ) ;
196
+ // Check if the class name and file name match
197
+ let clsname = "" ;
198
+ const match = content . toString ( ) . match ( / ^ [ \t ] * C l a s s [ \t ] + ( % ? [ \p{ L} \d ] + (?: \. [ \p{ L} \d ] + ) + ) / imu) ;
199
+ if ( match ) {
200
+ [ , clsname ] = match ;
201
+ }
202
+ if ( clsname === "" ) {
203
+ throw new Error ( "Cannot save a malformed class" ) ;
204
+ }
205
+ if ( fileName . slice ( 0 , - 4 ) !== clsname ) {
206
+ throw new Error ( "Cannot save an isfs class where the class name and file name do not match" ) ;
207
+ }
195
208
}
196
209
// Set a -1 mtime cache entry so the actual write by the workspace.onDidSaveTextDocument handler always overwrites.
197
210
// By the time we get here VS Code's built-in conflict resolution mechanism will already have interacted with the user.
You can’t perform that action at this time.
0 commit comments