feat: split diffs

This commit is contained in:
tomasz-io 2024-11-26 14:20:35 -08:00
parent 39087c2207
commit 3c537f51c1
2 changed files with 16 additions and 6 deletions

2
core/index.d.ts vendored
View file

@ -503,7 +503,7 @@ export interface IdeSettings {
export interface IDE {
getIdeInfo(): Promise<IdeInfo>;
getIdeSettings(): Promise<IdeSettings>;
getDiff(includeUnstaged: boolean): Promise<string>;
getDiff(includeUnstaged: boolean): Promise<string[]>;
getClipboardContent(): Promise<{ text: string; copiedAt: string }>;
isTelemetryEnabled(): Promise<boolean>;
getUniqueId(): Promise<string>;

View file

@ -570,8 +570,20 @@ export class VsCodeIdeUtils {
return repo?.state?.HEAD?.name || "NONE";
}
async getDiff(includeUnstaged: boolean): Promise<string> {
let diffs: string[] = [];
private splitDiff(diffString: string): string[] {
const fileDiffHeaderRegex = /(?=diff --git a\/.* b\/.*)/;
const diffs = diffString.split(fileDiffHeaderRegex);
if (diffs[0].trim() === "") {
diffs.shift();
}
return diffs;
}
async getDiff(includeUnstaged: boolean): Promise<string[]> {
const diffs: string[] = [];
for (const dir of this.getWorkspaceDirectories()) {
const repo = await this.getRepo(vscode.Uri.file(dir));
@ -587,9 +599,7 @@ export class VsCodeIdeUtils {
}
}
const fullDiff = diffs.join("\n\n");
return fullDiff;
return diffs.flatMap((diff) => this.splitDiff(diff));
}
getHighlightedCode(): RangeInFile[] {