Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
13 changes: 10 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
),
vscode.commands.registerCommand("vscode-objectscript.exportCurrentFile", exportCurrentFile),
vscode.workspace.onDidCreateFiles((e: vscode.FileCreateEvent) => {
if (!config("autoAdjustName")) return;
return Promise.all(
e.files
.filter(notIsfs)
Expand All @@ -1242,7 +1241,15 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
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<boolean>("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);
Expand All @@ -1261,7 +1268,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
}
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")));
})
Expand Down