Skip to content

Commit 0efd1c7

Browse files
authored
Fix diff count when converting to suggestions (#6519)
Fixes #6263
1 parent c368e80 commit 0efd1c7

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/view/reviewManager.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ export class ReviewManager extends Disposable {
780780
async createSuggestionsFromChanges(resources: vscode.Uri[]) {
781781
const resourceStrings = resources.map(resource => resource.toString());
782782
let hasError: boolean = false;
783-
let diff: DiffHunk[] = [];
783+
let diffCount: number = 0;
784784
const convertedFiles: vscode.Uri[] = [];
785785

786786
const convertOneSmallHunk = async (changeFile: Change, hunk: DiffHunk) => {
@@ -799,30 +799,35 @@ export class ReviewManager extends Disposable {
799799
return parsePatch(await this._folderRepoManager.repository.diffWithHEAD(changeFile.uri.fsPath)).map(hunk => splitIntoSmallerHunks(hunk)).flat();
800800
};
801801

802+
const convertAllChangesInFile = async (changeFile: Change, parallel: boolean) => {
803+
const diff = await getDiffFromChange(changeFile);
804+
if (diff) {
805+
diffCount += diff.length;
806+
if (parallel) {
807+
await Promise.allSettled(diff.map(async hunk => {
808+
return convertOneSmallHunk(changeFile, hunk);
809+
}));
810+
} else {
811+
for (const hunk of diff) {
812+
await convertOneSmallHunk(changeFile, hunk);
813+
}
814+
}
815+
}
816+
};
817+
802818
await vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: 'Converting changes to suggestions' }, async () => {
803819
// We need to create one suggestion first. This let's us ensure that only one review will be created.
804820
let i = 0;
805821
for (; (convertedFiles.length === 0) && (i < this._folderRepoManager.repository.state.workingTreeChanges.length); i++) {
806822
const changeFile = this._folderRepoManager.repository.state.workingTreeChanges[i];
807-
const diff = await getDiffFromChange(changeFile);
808-
if (diff) {
809-
for (const hunk of diff) {
810-
await convertOneSmallHunk(changeFile, hunk);
811-
}
812-
}
823+
await convertAllChangesInFile(changeFile, false);
813824
}
814825

815826
// If we have already created a suggestion, we can create the rest in parallel
816827
const promises: Promise<void>[] = [];
817828
for (; i < this._folderRepoManager.repository.state.workingTreeChanges.length; i++) {
818829
const changeFile = this._folderRepoManager.repository.state.workingTreeChanges[i];
819-
promises.push(getDiffFromChange(changeFile).then(async (diff) => {
820-
if (diff) {
821-
await Promise.allSettled(diff.map(async hunk => {
822-
return convertOneSmallHunk(changeFile, hunk);
823-
}));
824-
}
825-
}));
830+
promises.push(convertAllChangesInFile(changeFile, true));
826831
}
827832

828833
await Promise.all(promises);
@@ -835,7 +840,7 @@ export class ReviewManager extends Disposable {
835840
}
836841
});
837842
} else if (convertedFiles.length) {
838-
vscode.window.showWarningMessage(vscode.l10n.t('Not all changes could be converted to suggestions.'), { detail: vscode.l10n.t('{0} of {1} changes converted. Some of the changes may be outside of commenting ranges.\nYour changes are still available locally.', convertedFiles.length, diff.length), modal: true });
843+
vscode.window.showWarningMessage(vscode.l10n.t('Not all changes could be converted to suggestions.'), { detail: vscode.l10n.t('{0} of {1} changes converted. Some of the changes may be outside of commenting ranges.\nYour changes are still available locally.', convertedFiles.length, diffCount), modal: true });
839844
} else {
840845
vscode.window.showWarningMessage(vscode.l10n.t('No changes could be converted to suggestions.'), { detail: vscode.l10n.t('All of the changes are outside of commenting ranges.'), modal: true });
841846
}

0 commit comments

Comments
 (0)