()
| 188 | } |
| 189 | |
| 190 | private async saveNow() { |
| 191 | if (!this.cachePath) return; |
| 192 | |
| 193 | try { |
| 194 | // Create snapshot to avoid race condition with concurrent modifications |
| 195 | // Deep clone ensures mutations during async write don't corrupt saved data |
| 196 | const snapshot: CacheFile = { |
| 197 | version: CACHE_VERSION, |
| 198 | files: JSON.parse(JSON.stringify(this.files)), |
| 199 | crossFileEdges: JSON.parse(JSON.stringify(this.crossFileEdges)), |
| 200 | workflows: JSON.parse(JSON.stringify(this.workflows)) |
| 201 | }; |
| 202 | const cacheContent = JSON.stringify(snapshot, null, 2); |
| 203 | await vscode.workspace.fs.writeFile(this.cachePath, Buffer.from(cacheContent, 'utf8')); |
| 204 | this.lastSaveTime = Date.now(); |
| 205 | } catch (error) { |
| 206 | console.error('Failed to save cache:', error); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Write the merged graph to a standalone JSON file for external consumers (e.g., MCP server). |
no test coverage detected