Skip to content

Commit 00bc6ed

Browse files
authored
Always add Class and ROUTINE headers to new client-side files (#1515)
1 parent 270b35d commit 00bc6ed

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@
14761476
"default": false
14771477
},
14781478
"objectscript.autoAdjustName": {
1479-
"markdownDescription": "Automatically modify the class name or ROUTINE header of a file in a client-side workspace folder to match the file's path when copying or creating a new file. Uses the `#objectscript.export#` settings to determine the new name.",
1479+
"markdownDescription": "Automatically modify the class name or ROUTINE header of a file in a client-side workspace folder to match the file's path when copying or moving a file. Uses the `#objectscript.export#` settings to determine the new name.",
14801480
"type": "boolean",
14811481
"default": false
14821482
},

src/extension.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
12321232
),
12331233
vscode.commands.registerCommand("vscode-objectscript.exportCurrentFile", exportCurrentFile),
12341234
vscode.workspace.onDidCreateFiles((e: vscode.FileCreateEvent) => {
1235-
if (!config("autoAdjustName")) return;
12361235
return Promise.all(
12371236
e.files
12381237
.filter(notIsfs)
@@ -1242,7 +1241,15 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
12421241
const workspace = workspaceFolderOfUri(uri);
12431242
if (!workspace) {
12441243
// No workspace folders are open
1245-
return null;
1244+
return;
1245+
}
1246+
const sourceContent = await vscode.workspace.fs.readFile(uri);
1247+
if (
1248+
sourceContent.length &&
1249+
!vscode.workspace.getConfiguration("objectscript").get<boolean>("autoAdjustName")
1250+
) {
1251+
// Don't modify a file with content unless the user opts in
1252+
return;
12461253
}
12471254
const workspacePath = uriOfWorkspaceFolder(workspace).fsPath;
12481255
const filePathNoWorkspaceArr = uri.fsPath.replace(workspacePath + path.sep, "").split(path.sep);
@@ -1261,7 +1268,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
12611268
}
12621269
const fileName = filePathNoWorkspaceArr.join(".");
12631270
// Generate the new content
1264-
const newContent = generateFileContent(uri, fileName, await vscode.workspace.fs.readFile(uri));
1271+
const newContent = generateFileContent(uri, fileName, sourceContent);
12651272
// Write the new content to the file
12661273
return vscode.workspace.fs.writeFile(uri, new TextEncoder().encode(newContent.content.join("\n")));
12671274
})

0 commit comments

Comments
 (0)