({
onChange,
toolUseContext,
filePath,
edits,
editMode,
}: Props)
| 46 | } |
| 47 | |
| 48 | export 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 | ) |
no test coverage detected