Skip to content

Commit 59ecc74

Browse files
authored
1 parent 9750e6f commit 59ecc74

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

src/@types/vscode.proposed.chatParticipantAdditions.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ declare module 'vscode' {
125125
* Optional URI to navigate to when clicking on the file.
126126
*/
127127
goToFileUri?: Uri;
128+
129+
/**
130+
* Added data (e.g. line numbers) to show in the UI
131+
*/
132+
added?: number;
133+
134+
/**
135+
* Removed data (e.g. line numbers) to show in the UI
136+
*/
137+
removed?: number;
128138
}
129139

130140
/**

src/github/copilotRemoteAgent.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,10 +1327,13 @@ export class CopilotRemoteAgentManager extends Disposable {
13271327

13281328
const diffEntries: vscode.ChatResponseDiffEntry[] = [];
13291329
for (const changeModel of changeModels) {
1330+
const { added, removed } = await changeModel.calculateChangedLinesCount();
13301331
diffEntries.push({
13311332
originalUri: changeModel.parentFilePath,
13321333
modifiedUri: changeModel.filePath,
13331334
goToFileUri: changeModel.filePath,
1335+
added,
1336+
removed,
13341337
});
13351338
}
13361339

src/github/copilotRemoteAgent/chatSessionContentBuilder.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,13 @@ export class ChatSessionContentBuilder {
440440

441441
const diffEntries: vscode.ChatResponseDiffEntry[] = [];
442442
for (const changeModel of changeModels) {
443+
const { added, removed } = await changeModel.calculateChangedLinesCount();
443444
diffEntries.push({
444445
originalUri: changeModel.parentFilePath,
445446
modifiedUri: changeModel.filePath,
446-
goToFileUri: changeModel.filePath
447+
goToFileUri: changeModel.filePath,
448+
added,
449+
removed,
447450
});
448451
}
449452

src/view/fileChangeModel.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode';
77
import { ViewedState } from '../common/comment';
8-
import { DiffHunk, parsePatch } from '../common/diffHunk';
8+
import { DiffChangeType, DiffHunk, parsePatch } from '../common/diffHunk';
99
import { GitChangeType, InMemFileChange, SimpleFileChange, SlimFileChange } from '../common/file';
1010
import Logger from '../common/logger';
1111
import { resolvePath, toPRUri, toReviewUri } from '../common/uri';
@@ -66,6 +66,28 @@ export abstract class FileChangeModel {
6666
return diffHunks;
6767
}
6868

69+
public async calculateChangedLinesCount(): Promise<{ added: number; removed: number }> {
70+
try {
71+
const diffHunks = await this.diffHunks();
72+
let added = 0;
73+
let removed = 0;
74+
75+
for (const hunk of diffHunks) {
76+
for (const line of hunk.diffLines) {
77+
if (line.type === DiffChangeType.Add) {
78+
++added;
79+
} else if (line.type === DiffChangeType.Delete) {
80+
++removed;
81+
}
82+
}
83+
}
84+
return { added, removed };
85+
} catch (error) {
86+
Logger.warn(`Failed to calculate added/removed lines for ${this.fileName}: ${error}`, FileChangeModel.ID);
87+
return { added: 0, removed: 0 };
88+
}
89+
}
90+
6991
constructor(public readonly pullRequest: PullRequestModel,
7092
protected readonly folderRepoManager: FolderRepositoryManager,
7193
public readonly change: SimpleFileChange,

0 commit comments

Comments
 (0)