Skip to content

Commit 5fbb91b

Browse files
authored
Merge pull request #282092 from microsoft/osortega/fix-multi-diff-stats-cloud
Fix for cloud multi diff stats
2 parents 2759242 + ff030c2 commit 5fbb91b

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

src/vs/workbench/api/browser/mainThreadChatSessions.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { URI, UriComponents } from '../../../base/common/uri.js';
1616
import { localize } from '../../../nls.js';
1717
import { IDialogService } from '../../../platform/dialogs/common/dialogs.js';
1818
import { ILogService } from '../../../platform/log/common/log.js';
19+
import { hasValidDiff, IAgentSession } from '../../contrib/chat/browser/agentSessions/agentSessionsModel.js';
1920
import { ChatViewPaneTarget, IChatWidgetService, isIChatViewViewContext } from '../../contrib/chat/browser/chat.js';
2021
import { IChatEditorOptions } from '../../contrib/chat/browser/chatEditor.js';
2122
import { ChatEditorInput } from '../../contrib/chat/browser/chatEditorInput.js';
@@ -470,12 +471,14 @@ export class MainThreadChatSessions extends Disposable implements MainThreadChat
470471
// We can still get stats if there is no model or if fetching from model failed
471472
if (!session.changes || !model) {
472473
const stats = (await this._chatService.getMetadataForSession(uri))?.stats;
473-
if (stats) {
474-
session.changes = {
475-
files: stats.fileCount,
476-
insertions: stats.added,
477-
deletions: stats.removed
478-
};
474+
// TODO: we shouldn't be converting this, the types should match
475+
const diffs: IAgentSession['changes'] = {
476+
files: stats?.fileCount || 0,
477+
insertions: stats?.added || 0,
478+
deletions: stats?.removed || 0
479+
};
480+
if (hasValidDiff(diffs)) {
481+
session.changes = diffs;
479482
}
480483
}
481484

src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsActions.ts

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

66
import './media/agentsessionsactions.css';
77
import { localize, localize2 } from '../../../../../nls.js';
8-
import { getAgentChangesSummary, IAgentSession } from './agentSessionsModel.js';
8+
import { IAgentSession, getAgentChangesSummary } from './agentSessionsModel.js';
99
import { Action, IAction } from '../../../../../base/common/actions.js';
1010
import { ActionViewItem, IActionViewItemOptions } from '../../../../../base/browser/ui/actionbar/actionViewItems.js';
1111
import { CommandsRegistry, ICommandService } from '../../../../../platform/commands/common/commands.js';

src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsModel.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ interface IAgentSessionData {
6464
};
6565
}
6666

67+
/**
68+
* Checks if the provided changes object represents valid diff information.
69+
*/
70+
export function hasValidDiff(changes: IAgentSession['changes']): boolean {
71+
if (!changes) {
72+
return false;
73+
}
74+
75+
if (changes instanceof Array) {
76+
return changes.length > 0;
77+
}
78+
79+
return changes.files > 0 || changes.insertions > 0 || changes.deletions > 0;
80+
}
81+
82+
/**
83+
* Gets a summary of agent session changes, converting from array format to object format if needed.
84+
*/
6785
export function getAgentChangesSummary(changes: IAgentSession['changes']) {
6886
if (!changes) {
6987
return;

src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsViewer.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ICompressedTreeNode } from '../../../../../base/browser/ui/tree/compres
1313
import { ICompressibleKeyboardNavigationLabelProvider, ICompressibleTreeRenderer } from '../../../../../base/browser/ui/tree/objectTree.js';
1414
import { ITreeNode, ITreeElementRenderDetails, IAsyncDataSource, ITreeSorter, ITreeDragAndDrop, ITreeDragOverReaction } from '../../../../../base/browser/ui/tree/tree.js';
1515
import { Disposable, DisposableStore, IDisposable } from '../../../../../base/common/lifecycle.js';
16-
import { IAgentSession, IAgentSessionsModel, isAgentSession, isAgentSessionsModel } from './agentSessionsModel.js';
16+
import { IAgentSession, IAgentSessionsModel, isAgentSession, isAgentSessionsModel, hasValidDiff } from './agentSessionsModel.js';
1717
import { IconLabel } from '../../../../../base/browser/ui/iconLabel/iconLabel.js';
1818
import { ThemeIcon } from '../../../../../base/common/themables.js';
1919
import { Codicon } from '../../../../../base/common/codicons.js';
@@ -162,11 +162,9 @@ export class AgentSessionRenderer implements ICompressibleTreeRenderer<IAgentSes
162162

163163
// Details Actions
164164
const { changes: diff } = session.element;
165-
if (session.element.status !== ChatSessionStatus.InProgress && diff && this.hasValidDiff(diff)) {
166-
if (diff instanceof Array ? diff.length > 0 : (diff.files > 0 || diff.insertions > 0 || diff.deletions > 0)) {
167-
const diffAction = template.elementDisposable.add(new AgentSessionShowDiffAction(session.element));
168-
template.detailsToolbar.push([diffAction], { icon: false, label: true });
169-
}
165+
if (session.element.status !== ChatSessionStatus.InProgress && diff && hasValidDiff(diff)) {
166+
const diffAction = template.elementDisposable.add(new AgentSessionShowDiffAction(session.element));
167+
template.detailsToolbar.push([diffAction], { icon: false, label: true });
170168
}
171169

172170
// Description otherwise
@@ -181,17 +179,7 @@ export class AgentSessionRenderer implements ICompressibleTreeRenderer<IAgentSes
181179
this.renderHover(session, template);
182180
}
183181

184-
private hasValidDiff(diff: IAgentSession['changes']): boolean {
185-
if (!diff) {
186-
return false;
187-
}
188182

189-
if (diff instanceof Array) {
190-
return diff.length > 0;
191-
}
192-
193-
return diff.files > 0 || diff.insertions > 0 || diff.deletions > 0;
194-
}
195183

196184
private getIcon(session: IAgentSession): ThemeIcon {
197185
if (session.status === ChatSessionStatus.InProgress) {

0 commit comments

Comments
 (0)