fix(vscode): open each apply patch file
This commit is contained in:
@@ -3,6 +3,7 @@ import { parsePatchFiles } from '@pierre/diffs';
|
||||
export type DiffPatchEntry = {
|
||||
id: string;
|
||||
title: string;
|
||||
filePath?: string;
|
||||
patch: string;
|
||||
renderMode: 'diff' | 'text';
|
||||
};
|
||||
@@ -140,6 +141,20 @@ export const getPatchText = (value: unknown): string | undefined => {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const getApplyPatchFilePath = (file: unknown): string | null => {
|
||||
if (!isRecord(file)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return typeof file.movePath === 'string'
|
||||
? file.movePath
|
||||
: typeof file.filePath === 'string'
|
||||
? file.filePath
|
||||
: typeof file.relativePath === 'string'
|
||||
? file.relativePath
|
||||
: null;
|
||||
};
|
||||
|
||||
export const getPrimaryToolPath = (
|
||||
toolName: string,
|
||||
input: Record<string, unknown> | undefined,
|
||||
@@ -147,17 +162,15 @@ export const getPrimaryToolPath = (
|
||||
): string | null => {
|
||||
if (toolName === 'apply_patch') {
|
||||
const files = Array.isArray(metadata?.files) ? metadata.files : [];
|
||||
const first = files.find((entry) => isRecord(entry) && entry.type !== 'delete');
|
||||
if (!isRecord(first)) {
|
||||
return null;
|
||||
for (const file of files) {
|
||||
if (isRecord(file) && file.type !== 'delete') {
|
||||
const filePath = getApplyPatchFilePath(file);
|
||||
if (filePath) {
|
||||
return filePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
return typeof first.movePath === 'string'
|
||||
? first.movePath
|
||||
: typeof first.filePath === 'string'
|
||||
? first.filePath
|
||||
: typeof first.relativePath === 'string'
|
||||
? first.relativePath
|
||||
: null;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (toolName === 'edit' || toolName === 'multiedit') {
|
||||
@@ -334,7 +347,7 @@ const getPatchEntriesFromText = (
|
||||
}];
|
||||
};
|
||||
|
||||
const getFilePatch = (file: unknown): { patch: string; title: string } | null => {
|
||||
const getFilePatch = (file: unknown): { filePath?: string; patch: string; title: string } | null => {
|
||||
if (!isRecord(file)) {
|
||||
return null;
|
||||
}
|
||||
@@ -351,6 +364,7 @@ const getFilePatch = (file: unknown): { patch: string; title: string } | null =>
|
||||
: '';
|
||||
|
||||
return {
|
||||
filePath: getApplyPatchFilePath(file) ?? undefined,
|
||||
patch,
|
||||
title: rawPath,
|
||||
};
|
||||
@@ -372,7 +386,7 @@ export const getDiffPatchEntries = (
|
||||
filePatch.title || `File ${index + 1}`,
|
||||
`file-${index}`,
|
||||
resolveTitle,
|
||||
);
|
||||
).map((entry) => ({ ...entry, filePath: filePatch.filePath }));
|
||||
});
|
||||
|
||||
if (fileEntries.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user