From f55ab7a53c9b6039540f53bfed0ed0f3c07bc45b Mon Sep 17 00:00:00 2001 From: Tamer Tawil Date: Tue, 24 Mar 2026 13:19:23 +0300 Subject: [PATCH] feat: show diff view before uploading settings to Gist (#508) --- fix_sync_diff.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 fix_sync_diff.py diff --git a/fix_sync_diff.py b/fix_sync_diff.py new file mode 100644 index 00000000..c8ff3fb6 --- /dev/null +++ b/fix_sync_diff.py @@ -0,0 +1,52 @@ +import re + +path = 'src/sync.ts' +with open(path, 'r') as f: + content = f.read() + +# Add a new private method to handle showing the diff +new_diff_method = """ + private async showDiff(file: File, remoteContent: string) { + const local = vscode.Uri.file(file.filePath); + const remote = vscode.Uri.file(file.filePath + ".remote"); + await G.fs.writeFile(remote.fsPath, remoteContent); + + await vscode.commands.executeCommand( + "vscode.diff", + remote, + local, + `Gist ↔ Local` + ); + } +""" + +# Inject the method into the class +content = content.replace('public async Upload()', f'{new_diff_method}\\n\\n public async Upload()') + +# Modify the Upload method to call this new diff logic +# I will find the part where it prepares the files and insert my logic +upload_logic_search = r"const files = await this.GetFiles();" +upload_logic_replace = r""" + const files = await this.GetFiles(); + + const remoteContent = await this.GetGist(); + if (remoteContent) { + for (const file of files) { + if (remoteContent.data.files[file.gistName]) { + const remoteFileContent = remoteContent.data.files[file.gistName].content; + if (file.content !== remoteFileContent) { + await this.showDiff(file, remoteFileContent); + } + } + } + } + +""" + +content = content.replace(upload_logic_search, upload_logic_search + upload_logic_replace) + + +with open(path, 'w') as f: + f.write(content) + +print("Injected diff logic into src/sync.ts")