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

Function notifyVscodeSnapshotFilesUpdated

src/utils/fileHistory.ts:1056–1100  ·  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

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