-
-
Notifications
You must be signed in to change notification settings - Fork 407
Expand file tree
/
Copy pathfix_sync_diff.py
More file actions
52 lines (41 loc) · 1.61 KB
/
fix_sync_diff.py
File metadata and controls
52 lines (41 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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")