MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / showDiffInIDE

Function showDiffInIDE

source code/hooks/useDiffInIDE.ts:218–329  ·  view source on GitHub ↗

* Done if: * * 1. Tab is closed in IDE * 2. Tab is saved in IDE (we then close the tab) * 3. User selected an option in IDE * 4. User selected an option in terminal (or hit esc) * * Resolves with the new file content. * * TODO: Time out after 5 mins of inactivity? * TODO: Update auto-appro

(
  file_path: string,
  edits: FileEdit[],
  toolUseContext: ToolUseContext,
  tabName: string,
)

Source from the content-addressed store, hash-verified

216 * TODO: Close the IDE tab when the approval prompt is unmounted
217 */
218async function showDiffInIDE(
219 file_path: string,
220 edits: FileEdit[],
221 toolUseContext: ToolUseContext,
222 tabName: string,
223): Promise<{ oldContent: string; newContent: string }> {
224 let isCleanedUp = false
225
226 const oldFilePath = expandPath(file_path)
227 let oldContent = ''
228 try {
229 oldContent = readFileSync(oldFilePath)
230 } catch (e: unknown) {
231 if (!isENOENT(e)) {
232 throw e
233 }
234 }
235
236 async function cleanup() {
237 // Careful to avoid race conditions, since this
238 // function can be called from multiple places.
239 if (isCleanedUp) {
240 return
241 }
242 isCleanedUp = true
243
244 // Don't fail if this fails
245 try {
246 await closeTabInIDE(tabName, ideClient)
247 } catch (e) {
248 logError(e as Error)
249 }
250
251 process.off('beforeExit', cleanup)
252 toolUseContext.abortController.signal.removeEventListener('abort', cleanup)
253 }
254
255 // Cleanup if the user hits esc to cancel the tool call - or on exit
256 toolUseContext.abortController.signal.addEventListener('abort', cleanup)
257 process.on('beforeExit', cleanup)
258
259 // Open the diff in the IDE
260 const ideClient = getConnectedIdeClient(toolUseContext.options.mcpClients)
261 try {
262 const { updatedFile } = getPatchForEdits({
263 filePath: oldFilePath,
264 fileContents: oldContent,
265 edits,
266 })
267
268 if (!ideClient || ideClient.type !== 'connected') {
269 throw new Error('IDE client not available')
270 }
271 let ideOldPath = oldFilePath
272
273 // Only convert paths if we're in WSL and IDE is on Windows
274 const ideRunningInWindows =
275 (ideClient.config as McpSSEIDEServerConfig | McpWebSocketIDEServerConfig)

Callers 1

showDiffFunction · 0.85

Calls 13

toIDEPathMethod · 0.95
expandPathFunction · 0.85
isENOENTFunction · 0.85
getConnectedIdeClientFunction · 0.85
getPatchForEditsFunction · 0.85
getPlatformFunction · 0.85
callIdeRpcFunction · 0.85
isSaveMessageFunction · 0.85
isClosedMessageFunction · 0.85
isRejectedMessageFunction · 0.85
cleanupFunction · 0.70
readFileSyncFunction · 0.50

Tested by

no test coverage detected