From 89ddd9e15f699df90c3361291d0c98873f53d7fd Mon Sep 17 00:00:00 2001 From: shuo Date: Tue, 28 Nov 2023 18:56:06 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 4 ++-- package.json | 5 +++++ src/providers/FileSystemProvider/FileSystemProvider.ts | 9 +++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 73b3e1c7..46f6d72d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-objectscript", - "version": "2.10.5-SNAPSHOT", + "version": "2.10.6-SNAPSHOT", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vscode-objectscript", - "version": "2.10.5-SNAPSHOT", + "version": "2.10.6-SNAPSHOT", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 8278907b..dfb29a3c 100644 --- a/package.json +++ b/package.json @@ -1458,6 +1458,11 @@ "type": "boolean", "default": false }, + "objectscript.disableImplictCodeChange": { + "description": "Disable all implict change to any of your code.", + "type": "boolean", + "default": false + }, "objectscript.compileOnSave": { "description": "Automatically compile an InterSystems file when saved in the editor.", "type": "boolean", diff --git a/src/providers/FileSystemProvider/FileSystemProvider.ts b/src/providers/FileSystemProvider/FileSystemProvider.ts index a9d73257..eabd4862 100644 --- a/src/providers/FileSystemProvider/FileSystemProvider.ts +++ b/src/providers/FileSystemProvider/FileSystemProvider.ts @@ -28,6 +28,14 @@ export function generateFileContent( sourceContent: Buffer ): { content: string[]; enc: boolean } { const sourceLines = sourceContent.length ? new TextDecoder().decode(sourceContent).split("\n") : []; + + // since this function only changes class package line, disableImplictCodeChange completely skip this function + const disableImplictChange = config("disableImplictCodeChange"); + console.log("generateFileContent called with " + disableImplictChange); + if (disableImplictChange === true) { + return { content: sourceLines, enc: false }; + } + const fileExt = fileName.split(".").pop().toLowerCase(); const csp = fileName.startsWith("/"); if (fileExt === "cls" && !csp) { @@ -46,6 +54,7 @@ export function generateFileContent( while (sourceLines.length > 0) { const nextLine = sourceLines.shift(); if (nextLine.toLowerCase().startsWith("class ")) { + console.log("class matched on line:" + nextLine); const classLine = nextLine.split(" "); classLine[0] = "Class"; classLine[1] = className; From 937110ed3f341404c361165f7ddebedbe791097e Mon Sep 17 00:00:00 2001 From: hsyhhssyy Date: Wed, 29 Nov 2023 03:25:10 +0000 Subject: [PATCH 2/7] syntax change --- package.json | 4 ++-- src/providers/FileSystemProvider/FileSystemProvider.ts | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index dfb29a3c..d24a9907 100644 --- a/package.json +++ b/package.json @@ -1458,8 +1458,8 @@ "type": "boolean", "default": false }, - "objectscript.disableImplictCodeChange": { - "description": "Disable all implict change to any of your code.", + "objectscript.disableImplicitCodeChange": { + "description": "Disable all implicit changes to your code.", "type": "boolean", "default": false }, diff --git a/src/providers/FileSystemProvider/FileSystemProvider.ts b/src/providers/FileSystemProvider/FileSystemProvider.ts index eabd4862..9a145795 100644 --- a/src/providers/FileSystemProvider/FileSystemProvider.ts +++ b/src/providers/FileSystemProvider/FileSystemProvider.ts @@ -29,10 +29,11 @@ export function generateFileContent( ): { content: string[]; enc: boolean } { const sourceLines = sourceContent.length ? new TextDecoder().decode(sourceContent).split("\n") : []; - // since this function only changes class package line, disableImplictCodeChange completely skip this function - const disableImplictChange = config("disableImplictCodeChange"); - console.log("generateFileContent called with " + disableImplictChange); - if (disableImplictChange === true) { + // Since this function only changes the class package line, disableImplicitCodeChange should completely skip this function. + // If, in the future, this function introduces some validation or caching, the below compare-and-return logic should be re-located to a proper position. + const disableImplicitCodeChange = config("disableImplicitCodeChange"); + console.log("generateFileContent called with " + disableImplicitCodeChange); + if (disableImplicitCodeChange === true) { return { content: sourceLines, enc: false }; } From 20096b1d0aea1979dad8a2205963a587f193d625 Mon Sep 17 00:00:00 2001 From: shuo Date: Wed, 6 Dec 2023 12:21:27 +0800 Subject: [PATCH 3/7] store --- package.json | 2 +- src/extension.ts | 6 ++++++ src/providers/FileSystemProvider/FileSystemProvider.ts | 10 ---------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index d24a9907..54216a4e 100644 --- a/package.json +++ b/package.json @@ -1459,7 +1459,7 @@ "default": false }, "objectscript.disableImplicitCodeChange": { - "description": "Disable all implicit changes to your code.", + "description": "Disable all code modifications that occur without the user's explicit awareness.", "type": "boolean", "default": false }, diff --git a/src/extension.ts b/src/extension.ts index c8a86289..b3a4f5bb 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1050,6 +1050,12 @@ export async function activate(context: vscode.ExtensionContext): Promise { e.files .filter((uri) => !filesystemSchemas.includes(uri.scheme)) .filter((uri) => ["cls", "inc", "int", "mac"].includes(uri.path.split(".").pop().toLowerCase())) + // If disableImplicitCodeChange is true, disable all changes + // Be aware that if you drag and drop a file for windows expolorer into vscode, + // it will trigger create event, but the file is not actually blank. + // read file content as text and write it back to the file will corrupt it's binary structure. + // so I use filter to skip file instead of 'verbatim output'. + .filter((_) => config("disableImplicitCodeChange") !== true) .map(async (uri) => { // Determine the file name const workspace = workspaceFolderOfUri(uri); diff --git a/src/providers/FileSystemProvider/FileSystemProvider.ts b/src/providers/FileSystemProvider/FileSystemProvider.ts index 9a145795..a9d73257 100644 --- a/src/providers/FileSystemProvider/FileSystemProvider.ts +++ b/src/providers/FileSystemProvider/FileSystemProvider.ts @@ -28,15 +28,6 @@ export function generateFileContent( sourceContent: Buffer ): { content: string[]; enc: boolean } { const sourceLines = sourceContent.length ? new TextDecoder().decode(sourceContent).split("\n") : []; - - // Since this function only changes the class package line, disableImplicitCodeChange should completely skip this function. - // If, in the future, this function introduces some validation or caching, the below compare-and-return logic should be re-located to a proper position. - const disableImplicitCodeChange = config("disableImplicitCodeChange"); - console.log("generateFileContent called with " + disableImplicitCodeChange); - if (disableImplicitCodeChange === true) { - return { content: sourceLines, enc: false }; - } - const fileExt = fileName.split(".").pop().toLowerCase(); const csp = fileName.startsWith("/"); if (fileExt === "cls" && !csp) { @@ -55,7 +46,6 @@ export function generateFileContent( while (sourceLines.length > 0) { const nextLine = sourceLines.shift(); if (nextLine.toLowerCase().startsWith("class ")) { - console.log("class matched on line:" + nextLine); const classLine = nextLine.split(" "); classLine[0] = "Class"; classLine[1] = className; From f24aa35302debbf1955b3d2e066c9385c7d91c0a Mon Sep 17 00:00:00 2001 From: "Songyang.Huo" Date: Mon, 18 Dec 2023 12:49:18 +0800 Subject: [PATCH 4/7] Update package.json Co-authored-by: Brett Saviano --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 54216a4e..969f00bd 100644 --- a/package.json +++ b/package.json @@ -1458,10 +1458,10 @@ "type": "boolean", "default": false }, - "objectscript.disableImplicitCodeChange": { - "description": "Disable all code modifications that occur without the user's explicit awareness.", + "objectscript.autoAdjustName": { + "markdownDescription": "Automatically modify the class name or ROUTINE header to match the file's path when copying or creating a new file. Does not affect `isfs` files.", "type": "boolean", - "default": false + "default": true }, "objectscript.compileOnSave": { "description": "Automatically compile an InterSystems file when saved in the editor.", From 696731b138fcb0b520095d1ca3d1aa147232faff Mon Sep 17 00:00:00 2001 From: "Songyang.Huo" Date: Mon, 18 Dec 2023 12:49:26 +0800 Subject: [PATCH 5/7] Update src/extension.ts Co-authored-by: Brett Saviano --- src/extension.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index b3a4f5bb..c8a86289 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1050,12 +1050,6 @@ export async function activate(context: vscode.ExtensionContext): Promise { e.files .filter((uri) => !filesystemSchemas.includes(uri.scheme)) .filter((uri) => ["cls", "inc", "int", "mac"].includes(uri.path.split(".").pop().toLowerCase())) - // If disableImplicitCodeChange is true, disable all changes - // Be aware that if you drag and drop a file for windows expolorer into vscode, - // it will trigger create event, but the file is not actually blank. - // read file content as text and write it back to the file will corrupt it's binary structure. - // so I use filter to skip file instead of 'verbatim output'. - .filter((_) => config("disableImplicitCodeChange") !== true) .map(async (uri) => { // Determine the file name const workspace = workspaceFolderOfUri(uri); From e1fc314e5605c7b28401e726da55aa43d8ebde47 Mon Sep 17 00:00:00 2001 From: hsyhhssyy Date: Mon, 18 Dec 2023 04:53:52 +0000 Subject: [PATCH 6/7] accept suggestions --- src/extension.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index c8a86289..88ae2470 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1045,8 +1045,9 @@ export async function activate(context: vscode.ExtensionContext): Promise { RESTDebugPanel.create(context.extensionUri) ), vscode.commands.registerCommand("vscode-objectscript.exportCurrentFile", exportCurrentFile), - vscode.workspace.onDidCreateFiles((e: vscode.FileCreateEvent) => - Promise.all( + vscode.workspace.onDidCreateFiles((e: vscode.FileCreateEvent) =>{ + if (!config("autoAdjustName")) return; + return Promise.all( e.files .filter((uri) => !filesystemSchemas.includes(uri.scheme)) .filter((uri) => ["cls", "inc", "int", "mac"].includes(uri.path.split(".").pop().toLowerCase())) @@ -1079,6 +1080,7 @@ export async function activate(context: vscode.ExtensionContext): Promise { return vscode.workspace.fs.writeFile(uri, new TextEncoder().encode(newContent.content.join("\n"))); }) ) + } ), vscode.window.onDidChangeActiveTextEditor((editor: vscode.TextEditor) => { if (config("openClassContracted") && editor && editor.document.languageId === "objectscript-class") { From a3737cfe6f287ed383496716effda812c890fb75 Mon Sep 17 00:00:00 2001 From: hsyhhssyy Date: Thu, 28 Dec 2023 05:46:42 +0000 Subject: [PATCH 7/7] fix lint --- src/extension.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 88ae2470..b078b4d5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1045,7 +1045,7 @@ export async function activate(context: vscode.ExtensionContext): Promise { RESTDebugPanel.create(context.extensionUri) ), vscode.commands.registerCommand("vscode-objectscript.exportCurrentFile", exportCurrentFile), - vscode.workspace.onDidCreateFiles((e: vscode.FileCreateEvent) =>{ + vscode.workspace.onDidCreateFiles((e: vscode.FileCreateEvent) => { if (!config("autoAdjustName")) return; return Promise.all( e.files @@ -1079,9 +1079,8 @@ export async function activate(context: vscode.ExtensionContext): Promise { // Write the new content to the file return vscode.workspace.fs.writeFile(uri, new TextEncoder().encode(newContent.content.join("\n"))); }) - ) - } - ), + ); + }), vscode.window.onDidChangeActiveTextEditor((editor: vscode.TextEditor) => { if (config("openClassContracted") && editor && editor.document.languageId === "objectscript-class") { const uri: string = editor.document.uri.toString();