Skip to content

Commit b77b01d

Browse files
authored
working set changed files improvements (microsoft#262183)
1 parent 6518fe6 commit b77b01d

File tree

4 files changed

+91
-6
lines changed

4 files changed

+91
-6
lines changed

src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedDocumentEntry.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ export class ChatEditingModifiedDocumentEntry extends AbstractChatEditingModifie
4747
return this._textModelChangeService.diffInfo.map(diff => diff.changes.length);
4848
}
4949

50+
get linesAdded() {
51+
return this._textModelChangeService.diffInfo.map(diff => {
52+
let added = 0;
53+
for (const c of diff.changes) {
54+
added += Math.max(0, c.modified.endLineNumberExclusive - c.modified.startLineNumber);
55+
}
56+
return added;
57+
});
58+
}
59+
get linesRemoved() {
60+
return this._textModelChangeService.diffInfo.map(diff => {
61+
let removed = 0;
62+
for (const c of diff.changes) {
63+
removed += Math.max(0, c.original.endLineNumberExclusive - c.original.startLineNumber);
64+
}
65+
return removed;
66+
});
67+
}
68+
5069
readonly originalURI: URI;
5170
private readonly _textModelChangeService: ChatEditingTextModelChangeService;
5271

src/vs/workbench/contrib/chat/browser/chatInputPart.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
325325

326326
readonly inputUri: URI;
327327

328+
private _workingSetLinesAddedSpan?: HTMLElement;
329+
private _workingSetLinesRemovedSpan?: HTMLElement;
330+
328331
private readonly _chatEditsActionsDisposables: DisposableStore;
329332
private readonly _chatEditsDisposables: DisposableStore;
330333
private _chatEditsContainer?: HTMLElement;
@@ -1611,18 +1614,58 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
16111614
secondary: true,
16121615
ariaLabel: localize('chatEditingSession.toggleWorkingSet', 'Toggle changed files.'),
16131616
}));
1614-
button.label = entries.length === 1 ? localize('chatEditingSession.oneFile.1', '1 file changed') : localize('chatEditingSession.manyFiles.1', '{0} files changed', entries.length);
1617+
1618+
let added = 0;
1619+
let removed = 0;
1620+
if (chatEditingSession) {
1621+
for (const entry of chatEditingSession.entries.get()) {
1622+
if (entry.linesAdded && entry.linesRemoved) {
1623+
added += entry.linesAdded.get();
1624+
removed += entry.linesRemoved.get();
1625+
}
1626+
}
1627+
}
1628+
1629+
const baseLabel = entries.length === 1 ? localize('chatEditingSession.oneFile.1', '1 file changed') : localize('chatEditingSession.manyFiles.1', '{0} files changed', entries.length);
1630+
button.label = baseLabel;
1631+
1632+
if (!this._workingSetLinesAddedSpan) {
1633+
this._workingSetLinesAddedSpan = dom.$('.working-set-lines-added');
1634+
}
1635+
if (!this._workingSetLinesRemovedSpan) {
1636+
this._workingSetLinesRemovedSpan = dom.$('.working-set-lines-removed');
1637+
}
1638+
1639+
const countsContainer = dom.$('.working-set-line-counts');
1640+
button.element.appendChild(countsContainer);
1641+
countsContainer.appendChild(this._workingSetLinesAddedSpan);
1642+
countsContainer.appendChild(this._workingSetLinesRemovedSpan);
1643+
1644+
this._workingSetLinesAddedSpan.textContent = `+${added}`;
1645+
this._workingSetLinesRemovedSpan.textContent = `-${removed}`;
1646+
button.element.setAttribute('aria-label', localize('chatEditingSession.ariaLabelWithCounts', '{0}, {1} lines added, {2} lines removed', baseLabel, added, removed));
16151647

16161648
const applyCollapseState = () => {
16171649
button.icon = this._workingSetCollapsed ? Codicon.chevronRight : Codicon.chevronDown;
16181650
workingSetContainer.classList.toggle('collapsed', this._workingSetCollapsed);
16191651
this._onDidChangeHeight.fire();
16201652
};
16211653

1622-
this._chatEditsActionsDisposables.add(button.onDidClick(() => {
1654+
const toggleWorkingSet = () => {
16231655
this._workingSetCollapsed = !this._workingSetCollapsed;
16241656
applyCollapseState();
1657+
};
16251658

1659+
this._chatEditsActionsDisposables.add(button.onDidClick(() => { toggleWorkingSet(); }));
1660+
this._chatEditsActionsDisposables.add(addDisposableListener(overviewRegion, 'click', e => {
1661+
if (e.defaultPrevented) {
1662+
return;
1663+
}
1664+
const target = e.target as HTMLElement;
1665+
if (target.closest('.monaco-button')) {
1666+
return;
1667+
}
1668+
toggleWorkingSet();
16261669
}));
16271670

16281671
applyCollapseState();

src/vs/workbench/contrib/chat/browser/media/chat.css

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ have to be updated for changes to the rules above, or to support more deeply nes
741741
justify-content: space-between;
742742
gap: 6px;
743743
padding-right: 4px;
744+
cursor: pointer;
744745
}
745746

746747
.interactive-session .chat-editing-session .chat-editing-session-container .chat-editing-session-overview > .working-set-title {
@@ -756,6 +757,22 @@ have to be updated for changes to the rules above, or to support more deeply nes
756757
color: var(--vscode-notificationsWarningIcon-foreground);
757758
}
758759

760+
/* Inline added/removed line count styling */
761+
.interactive-session .chat-editing-session .chat-editing-session-container .chat-editing-session-overview .working-set-line-counts {
762+
display: inline-flex;
763+
gap: 4px;
764+
margin-left: 6px;
765+
font-weight: 500;
766+
}
767+
768+
.interactive-session .chat-editing-session .chat-editing-session-container .chat-editing-session-overview .working-set-line-counts .working-set-lines-added {
769+
color: var(--vscode-chat-linesAddedForeground);
770+
}
771+
772+
.interactive-session .chat-editing-session .chat-editing-session-container .chat-editing-session-overview .working-set-line-counts .working-set-lines-removed {
773+
color: var(--vscode-chat-linesRemovedForeground);
774+
}
775+
759776
.interactive-session .chat-editing-session .working-set-title {
760777

761778
.monaco-button {
@@ -766,10 +783,6 @@ have to be updated for changes to the rules above, or to support more deeply nes
766783
color: var(--vscode-foreground)
767784
}
768785

769-
.monaco-button:hover {
770-
background-color: var(--vscode-toolbar-hoverBackground);
771-
}
772-
773786
.monaco-button:focus-visible {
774787
outline-offset: -1px !important;
775788
}

src/vs/workbench/contrib/chat/common/chatEditingService.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ export interface IModifiedFileEntry {
257257
*/
258258
readonly changesCount: IObservable<number>;
259259

260+
/**
261+
* Number of lines added in this entry.
262+
*/
263+
readonly linesAdded?: IObservable<number>;
264+
265+
/**
266+
* Number of lines removed in this entry
267+
*/
268+
readonly linesRemoved?: IObservable<number>;
269+
260270
getEditorIntegration(editor: IEditorPane): IModifiedFileEntryEditorIntegration;
261271
}
262272

0 commit comments

Comments
 (0)