From 81f98970c410fa523483228c403c442e092c0a4e Mon Sep 17 00:00:00 2001 From: Brett Saviano Date: Tue, 18 Mar 2025 08:40:02 -0400 Subject: [PATCH] Always add Class and ROUTINE headers to new client-side files --- package.json | 2 +- src/extension.ts | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f6bf76d5..79e7fd0a 100644 --- a/package.json +++ b/package.json @@ -1476,7 +1476,7 @@ "default": false }, "objectscript.autoAdjustName": { - "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.", + "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.", "type": "boolean", "default": false }, diff --git a/src/extension.ts b/src/extension.ts index 5ddb75ba..c520740d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1232,7 +1232,6 @@ export async function activate(context: vscode.ExtensionContext): Promise { ), vscode.commands.registerCommand("vscode-objectscript.exportCurrentFile", exportCurrentFile), vscode.workspace.onDidCreateFiles((e: vscode.FileCreateEvent) => { - if (!config("autoAdjustName")) return; return Promise.all( e.files .filter(notIsfs) @@ -1242,7 +1241,15 @@ export async function activate(context: vscode.ExtensionContext): Promise { const workspace = workspaceFolderOfUri(uri); if (!workspace) { // No workspace folders are open - return null; + return; + } + const sourceContent = await vscode.workspace.fs.readFile(uri); + if ( + sourceContent.length && + !vscode.workspace.getConfiguration("objectscript").get("autoAdjustName") + ) { + // Don't modify a file with content unless the user opts in + return; } const workspacePath = uriOfWorkspaceFolder(workspace).fsPath; const filePathNoWorkspaceArr = uri.fsPath.replace(workspacePath + path.sep, "").split(path.sep); @@ -1261,7 +1268,7 @@ export async function activate(context: vscode.ExtensionContext): Promise { } const fileName = filePathNoWorkspaceArr.join("."); // Generate the new content - const newContent = generateFileContent(uri, fileName, await vscode.workspace.fs.readFile(uri)); + const newContent = generateFileContent(uri, fileName, sourceContent); // Write the new content to the file return vscode.workspace.fs.writeFile(uri, new TextEncoder().encode(newContent.content.join("\n"))); })