Skip to content

Commit

Permalink
Collapse "used references" by default in edits view (#239981)
Browse files Browse the repository at this point in the history
* Collapse "used references" by default in edits view

* Fix build
  • Loading branch information
roblourens authored Feb 8, 2025
1 parent cbbe0be commit 8c54ad7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/chat/browser/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export interface IChatListItemRendererOptions {
readonly renderCodeBlockPills?: boolean;
readonly renderDetectedCommandsWithRequest?: boolean;
readonly renderTextEditsAsSummary?: (uri: URI) => boolean;
readonly referencesExpandedWhenEmptyResponse?: boolean;
}

export interface IChatWidgetViewOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export interface IChatReferenceListItem extends IChatContentReference {

export type IChatCollapsibleListItem = IChatReferenceListItem | IChatWarningMessage;

export interface IChatCollapsibleListOptions {
expandedWhenEmptyResponse?: boolean;
}

export class ChatCollapsibleListContentPart extends Disposable implements IChatContentPart {
public readonly domNode: HTMLElement;

Expand All @@ -70,6 +74,7 @@ export class ChatCollapsibleListContentPart extends Disposable implements IChatC
labelOverride: string | undefined,
context: IChatContentPartRenderContext,
contentReferencesListPool: CollapsibleListPool,
options: IChatCollapsibleListOptions,
@IOpenerService openerService: IOpenerService,
@IMenuService menuService: IMenuService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
Expand All @@ -83,7 +88,13 @@ export class ChatCollapsibleListContentPart extends Disposable implements IChatC
localize('usedReferencesPlural', "Used {0} references", data.length) :
localize('usedReferencesSingular', "Used {0} reference", 1));
const iconElement = $('.chat-used-context-icon');
const icon = (element: IChatResponseViewModel) => element.usedReferencesExpanded ? Codicon.chevronDown : Codicon.chevronRight;
const isExpanded = () =>
element.usedReferencesExpanded ?? (
options.expandedWhenEmptyResponse && element.response.value.length === 0
);
const icon = (element: IChatResponseViewModel) => {
return isExpanded() ? Codicon.chevronDown : Codicon.chevronRight;
};
iconElement.classList.add(...ThemeIcon.asClassNameArray(icon(element)));
const buttonElement = $('.chat-used-context-label', undefined);

Expand All @@ -100,15 +111,15 @@ export class ChatCollapsibleListContentPart extends Disposable implements IChatC
this.domNode = $('.chat-used-context', undefined, buttonElement);
collapseButton.label = referencesLabel;
collapseButton.element.prepend(iconElement);
this.updateAriaLabel(collapseButton.element, referencesLabel, element.usedReferencesExpanded);
this.domNode.classList.toggle('chat-used-context-collapsed', !element.usedReferencesExpanded);
this.updateAriaLabel(collapseButton.element, referencesLabel, isExpanded());
this.domNode.classList.toggle('chat-used-context-collapsed', !isExpanded());
this._register(collapseButton.onDidClick(() => {
iconElement.classList.remove(...ThemeIcon.asClassNameArray(icon(element)));
element.usedReferencesExpanded = !element.usedReferencesExpanded;
element.usedReferencesExpanded = !isExpanded();
iconElement.classList.add(...ThemeIcon.asClassNameArray(icon(element)));
this.domNode.classList.toggle('chat-used-context-collapsed', !element.usedReferencesExpanded);
this.domNode.classList.toggle('chat-used-context-collapsed', !isExpanded());
this._onDidChangeHeight.fire();
this.updateAriaLabel(collapseButton.element, referencesLabel, element.usedReferencesExpanded);
this.updateAriaLabel(collapseButton.element, referencesLabel, isExpanded());
}));

const ref = this._register(contentReferencesListPool.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ChatTaskContentPart extends Disposable implements IChatContentPart
super();

if (task.progress.length) {
const refsPart = this._register(instantiationService.createInstance(ChatCollapsibleListContentPart, task.progress, task.content.value, context, contentReferencesListPool));
const refsPart = this._register(instantiationService.createInstance(ChatCollapsibleListContentPart, task.progress, task.content.value, context, contentReferencesListPool, {}));
this.domNode = dom.$('.chat-progress-task');
this.domNode.appendChild(refsPart.domNode);
this.onDidChangeHeight = refsPart.onDidChangeHeight;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/chat/browser/chatListRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
}

private renderContentReferencesListData(references: IChatReferences, labelOverride: string | undefined, context: IChatContentPartRenderContext, templateData: IChatListItemTemplate): ChatCollapsibleListContentPart {
const referencesPart = this.instantiationService.createInstance(ChatCollapsibleListContentPart, references.references, labelOverride, context, this._contentReferencesListPool);
const referencesPart = this.instantiationService.createInstance(ChatCollapsibleListContentPart, references.references, labelOverride, context, this._contentReferencesListPool, { expandedWhenEmptyResponse: this.rendererOptions.referencesExpandedWhenEmptyResponse });
referencesPart.addDisposable(referencesPart.onDidChangeHeight(() => {
this.updateItemHeight(templateData);
}));
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/chat/browser/chatViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export class ChatViewPane extends ViewPane implements IViewWelcomeDelegate {
renderTextEditsAsSummary: (uri) => {
return this.chatOptions.location === ChatAgentLocation.EditingSession;
},
referencesExpandedWhenEmptyResponse: this.chatOptions.location !== ChatAgentLocation.EditingSession,
},
enableImplicitContext: this.chatOptions.location === ChatAgentLocation.Panel,
editorOverflowWidgetsDomNode: editorOverflowNode,
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/chat/common/chatViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ export class ChatResponseViewModel extends Disposable implements IChatResponseVi
return this._usedReferencesExpanded;
}

return this.response.value.length === 0 && !this.errorDetails;
return undefined;
}

set usedReferencesExpanded(v: boolean) {
Expand Down

0 comments on commit 8c54ad7

Please sign in to comment.