MCPcopy Index your code
hub / github.com/codeaashu/claude-code / useDiffInIDE

Function useDiffInIDE

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

Source from the content-addressed store, hash-verified

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

Callers 1

FilePermissionDialogFunction · 0.85

Calls 4

getGlobalConfigFunction · 0.85
getConnectedIdeNameFunction · 0.85
showDiffFunction · 0.85

Tested by

no test coverage detected