MCPcopy
hub / github.com/codeaashu/claude-code / notifyVscodeSnapshotFilesUpdated

Function notifyVscodeSnapshotFilesUpdated

src/utils/fileHistory.ts:1054–1098  ·  view source on GitHub ↗

* Notifies VSCode about files that have changed between snapshots. * Compares the previous snapshot with the new snapshot and sends file_updated * notifications for any files whose content has changed. * Fire-and-forget (void-dispatched from fileHistoryMakeSnapshot).

(
  oldState: FileHistoryState,
  newState: FileHistoryState,
)

Source from the content-addressed store, hash-verified

1052 * Fire-and-forget (void-dispatched from fileHistoryMakeSnapshot).
1053 */
1054async function notifyVscodeSnapshotFilesUpdated(
1055 oldState: FileHistoryState,
1056 newState: FileHistoryState,
1057): Promise<void> {
1058 const oldSnapshot = oldState.snapshots.at(-1)
1059 const newSnapshot = newState.snapshots.at(-1)
1060
1061 if (!newSnapshot) {
1062 return
1063 }
1064
1065 for (const trackingPath of newState.trackedFiles) {
1066 const filePath = maybeExpandFilePath(trackingPath)
1067 const oldBackup = oldSnapshot?.trackedFileBackups[trackingPath]
1068 const newBackup = newSnapshot.trackedFileBackups[trackingPath]
1069
1070 // Skip if both backups reference the same version (no change)
1071 if (
1072 oldBackup?.backupFileName === newBackup?.backupFileName &&
1073 oldBackup?.version === newBackup?.version
1074 ) {
1075 continue
1076 }
1077
1078 // Get old content from the previous backup
1079 let oldContent: string | null = null
1080 if (oldBackup?.backupFileName) {
1081 const backupPath = resolveBackupPath(oldBackup.backupFileName)
1082 oldContent = await readFileAsyncOrNull(backupPath)
1083 }
1084
1085 // Get new content from the new backup or current file
1086 let newContent: string | null = null
1087 if (newBackup?.backupFileName) {
1088 const backupPath = resolveBackupPath(newBackup.backupFileName)
1089 newContent = await readFileAsyncOrNull(backupPath)
1090 }
1091 // If newBackup?.backupFileName === null, the file was deleted; newContent stays null.
1092
1093 // Only notify if content actually changed
1094 if (oldContent !== newContent) {
1095 notifyVscodeFileUpdated(filePath, oldContent, newContent)
1096 }
1097 }
1098}
1099
1100/** Async read that swallows all errors and returns null (best-effort). */
1101async function readFileAsyncOrNull(path: string): Promise<string | null> {

Callers 1

fileHistoryMakeSnapshotFunction · 0.85

Calls 4

maybeExpandFilePathFunction · 0.85
resolveBackupPathFunction · 0.85
readFileAsyncOrNullFunction · 0.85
notifyVscodeFileUpdatedFunction · 0.85

Tested by

no test coverage detected