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

Function useDiffInIDE

source code/hooks/useDiffInIDE.ts:48–166  ·  view source on GitHub ↗
({
  onChange,
  toolUseContext,
  filePath,
  edits,
  editMode,
}: Props)

Source from the content-addressed store, hash-verified

46}
47
48export function useDiffInIDE({
49 onChange,
50 toolUseContext,
51 filePath,
52 edits,
53 editMode,
54}: Props): {
55 closeTabInIDE: () => void
56 showingDiffInIDE: boolean
57 ideName: string
58 hasError: boolean
59} {
60 const isUnmounted = useRef(false)
61 const [hasError, setHasError] = useState(false)
62
63 const sha = useMemo(() => randomUUID().slice(0, 6), [])
64 const tabName = useMemo(
65 () => `✻ [Claude Code] ${basename(filePath)} (${sha}) ⧉`,
66 [filePath, sha],
67 )
68
69 const shouldShowDiffInIDE =
70 hasAccessToIDEExtensionDiffFeature(toolUseContext.options.mcpClients) &&
71 getGlobalConfig().diffTool === 'auto' &&
72 // Diffs should only be for file edits.
73 // File writes may come through here but are not supported for diffs.
74 !filePath.endsWith('.ipynb')
75
76 const ideName =
77 getConnectedIdeName(toolUseContext.options.mcpClients) ?? 'IDE'
78
79 async function showDiff(): Promise<void> {
80 if (!shouldShowDiffInIDE) {
81 return
82 }
83
84 try {
85 logEvent('tengu_ext_will_show_diff', {})
86
87 const { oldContent, newContent } = await showDiffInIDE(
88 filePath,
89 edits,
90 toolUseContext,
91 tabName,
92 )
93 // Skip if component has been unmounted
94 if (isUnmounted.current) {
95 return
96 }
97
98 logEvent('tengu_ext_diff_accepted', {})
99
100 const newEdits = computeEditsFromContents(
101 filePath,
102 oldContent,
103 newContent,
104 editMode,
105 )

Callers 1

FilePermissionDialogFunction · 0.85

Calls 4

getGlobalConfigFunction · 0.85
getConnectedIdeNameFunction · 0.85
showDiffFunction · 0.85

Tested by

no test coverage detected