Files
openchamber/packages/ui/src/components/chat/message/parts/applyPatchEditorAction.ts
T
Nabeel Siddiqui d45b8065b0 Merge remote-tracking branch 'upstream/main' into fix/2566-apply-patch-vscode-diff
# Conflicts:
#	packages/ui/src/components/chat/message/parts/ToolPart.tsx
2026-08-01 16:15:42 -04:00

34 lines
1.0 KiB
TypeScript

import type { EditorAPI } from '@/lib/api/types';
import { toAbsoluteFilePath } from '@/lib/path-utils';
import { extractFirstChangedLineFromDiff, getApplyPatchFilePath, getPatchText } from './toolDiffUtils';
export const openApplyPatchFileInEditor = ({
currentDirectory,
diffLabel,
editor,
file,
isVSCode,
}: {
currentDirectory: string;
diffLabel: string;
editor: EditorAPI;
file: Record<string, unknown>;
isVSCode: boolean;
}): boolean => {
const filePath = getApplyPatchFilePath(file);
if (!filePath || file.type === 'delete') {
return false;
}
const patch = getPatchText(file.patch) ?? getPatchText(file.diff);
const line = patch ? extractFirstChangedLineFromDiff(patch) : undefined;
const absolutePath = toAbsoluteFilePath(currentDirectory, filePath);
if (isVSCode && patch) {
void editor.openDiff('', absolutePath, diffLabel, { line, patch });
} else {
void editor.openFile(absolutePath, line);
}
return true;
};