Skip to content

Commit 83a0539

Browse files
authored
fix: set content reference description on historical chat attachments (microsoft#249112)
1 parent 2bcc698 commit 83a0539

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { getFlatContextMenuActions } from '../../../../platform/actions/browser/
5050
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';
5151
import { ResourceContextKey } from '../../../common/contextkeys.js';
5252
import { Location, SymbolKind } from '../../../../editor/common/languages.js';
53+
import { IChatContentReference } from '../common/chatService.js';
5354

5455
abstract class AbstractChatAttachmentWidget extends Disposable {
5556
public readonly element: HTMLElement;
@@ -162,6 +163,7 @@ export class FileAttachmentWidget extends AbstractChatAttachmentWidget {
162163
resource: URI,
163164
range: IRange | undefined,
164165
attachment: IChatRequestVariableEntry,
166+
correspondingContentReference: IChatContentReference | undefined,
165167
currentLanguageModel: ILanguageModelChatMetadataAndIdentifier | undefined,
166168
options: { shouldFocusClearButton: boolean; supportsDeletion: boolean },
167169
container: HTMLElement,
@@ -185,7 +187,7 @@ export class FileAttachmentWidget extends AbstractChatAttachmentWidget {
185187
ariaLabel = localize('chat.omittedFileAttachment', "Omitted this file: {0}", attachment.name);
186188
this.renderOmittedWarning(friendlyName, ariaLabel, hoverDelegate);
187189
} else {
188-
const fileOptions: IFileLabelOptions = { hidePath: true };
190+
const fileOptions: IFileLabelOptions = { hidePath: true, title: correspondingContentReference?.options?.status?.description };
189191
this.label.setFile(resource, attachment.kind === 'file' ? {
190192
...fileOptions,
191193
fileKind: FileKind.FILE,
@@ -418,6 +420,7 @@ export class DefaultChatAttachmentWidget extends AbstractChatAttachmentWidget {
418420
resource: URI | undefined,
419421
range: IRange | undefined,
420422
attachment: IChatRequestVariableEntry,
423+
correspondingContentReference: IChatContentReference | undefined,
421424
currentLanguageModel: ILanguageModelChatMetadataAndIdentifier | undefined,
422425
options: { shouldFocusClearButton: boolean; supportsDeletion: boolean },
423426
container: HTMLElement,
@@ -432,7 +435,7 @@ export class DefaultChatAttachmentWidget extends AbstractChatAttachmentWidget {
432435

433436
const attachmentLabel = attachment.fullName ?? attachment.name;
434437
const withIcon = attachment.icon?.id ? `$(${attachment.icon.id})\u00A0${attachmentLabel}` : attachmentLabel;
435-
this.label.setLabel(withIcon, undefined);
438+
this.label.setLabel(withIcon, correspondingContentReference?.options?.status?.description);
436439
this.element.ariaLabel = localize('chat.attachment', "Attached context, {0}", attachment.name);
437440

438441
if (attachment.kind === 'diagnostic') {

src/vs/workbench/contrib/chat/browser/chatContentParts/chatAttachmentsContentPart.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,28 @@ export class ChatAttachmentsContentPart extends Disposable {
4747
this.attachedContextDisposables.clear();
4848
const hoverDelegate = this.attachedContextDisposables.add(createInstantHoverDelegate());
4949

50-
this.variables.forEach(async (attachment) => {
50+
for (const attachment of this.variables) {
5151
const resource = URI.isUri(attachment.value) ? attachment.value : attachment.value && typeof attachment.value === 'object' && 'uri' in attachment.value && URI.isUri(attachment.value.uri) ? attachment.value.uri : undefined;
5252
const range = attachment.value && typeof attachment.value === 'object' && 'range' in attachment.value && Range.isIRange(attachment.value.range) ? attachment.value.range : undefined;
53+
const correspondingContentReference = this.contentReferences.find((ref) => (typeof ref.reference === 'object' && 'variableName' in ref.reference && ref.reference.variableName === attachment.name) || (URI.isUri(ref.reference) && basename(ref.reference.path) === attachment.name));
5354

5455
let widget;
5556
if (isElementVariableEntry(attachment)) {
5657
widget = this.instantiationService.createInstance(ElementChatAttachmentWidget, attachment, undefined, { shouldFocusClearButton: false, supportsDeletion: false }, container, this._contextResourceLabels, hoverDelegate);
5758
} else if (isImageVariableEntry(attachment)) {
5859
widget = this.instantiationService.createInstance(ImageAttachmentWidget, resource, attachment, undefined, { shouldFocusClearButton: false, supportsDeletion: false }, container, this._contextResourceLabels, hoverDelegate);
5960
} else if (resource && (attachment.kind === 'file' || attachment.kind === 'directory')) {
60-
widget = this.instantiationService.createInstance(FileAttachmentWidget, resource, range, attachment, undefined, { shouldFocusClearButton: false, supportsDeletion: false }, container, this._contextResourceLabels, hoverDelegate);
61+
widget = this.instantiationService.createInstance(FileAttachmentWidget, resource, range, attachment, correspondingContentReference, undefined, { shouldFocusClearButton: false, supportsDeletion: false }, container, this._contextResourceLabels, hoverDelegate);
6162
} else if (isPasteVariableEntry(attachment)) {
6263
widget = this.instantiationService.createInstance(PasteAttachmentWidget, attachment, undefined, { shouldFocusClearButton: false, supportsDeletion: false }, container, this._contextResourceLabels, hoverDelegate);
6364
} else if (resource && isNotebookOutputVariableEntry(attachment)) {
6465
widget = this.instantiationService.createInstance(NotebookCellOutputChatAttachmentWidget, resource, attachment, undefined, { shouldFocusClearButton: false, supportsDeletion: false }, container, this._contextResourceLabels, hoverDelegate);
6566
} else if (isSCMHistoryItemVariableEntry(attachment)) {
6667
widget = this.instantiationService.createInstance(SCMHistoryItemAttachmentWidget, attachment, undefined, { shouldFocusClearButton: false, supportsDeletion: false }, container, this._contextResourceLabels, hoverDelegate);
6768
} else {
68-
widget = this.instantiationService.createInstance(DefaultChatAttachmentWidget, resource, range, attachment, undefined, { shouldFocusClearButton: false, supportsDeletion: false }, container, this._contextResourceLabels, hoverDelegate);
69+
widget = this.instantiationService.createInstance(DefaultChatAttachmentWidget, resource, range, attachment, correspondingContentReference, undefined, { shouldFocusClearButton: false, supportsDeletion: false }, container, this._contextResourceLabels, hoverDelegate);
6970
}
7071

71-
const correspondingContentReference = this.contentReferences.find((ref) => (typeof ref.reference === 'object' && 'variableName' in ref.reference && ref.reference.variableName === attachment.name) || (URI.isUri(ref.reference) && basename(ref.reference.path) === attachment.name));
7272
const isAttachmentOmitted = correspondingContentReference?.options?.status?.kind === ChatResponseReferencePartStatusKind.Omitted;
7373
const isAttachmentPartialOrOmitted = isAttachmentOmitted || correspondingContentReference?.options?.status?.kind === ChatResponseReferencePartStatusKind.Partial;
7474

@@ -89,6 +89,7 @@ export class ChatAttachmentsContentPart extends Disposable {
8989
}
9090

9191
if (this.attachedContextDisposables.isDisposed) {
92+
widget.dispose();
9293
return;
9394
}
9495

@@ -97,6 +98,6 @@ export class ChatAttachmentsContentPart extends Disposable {
9798
}
9899

99100
this.attachedContextDisposables.add(widget);
100-
});
101+
}
101102
}
102103
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
12331233
if (resource && isNotebookOutputVariableEntry(attachment)) {
12341234
attachmentWidget = this.instantiationService.createInstance(NotebookCellOutputChatAttachmentWidget, resource, attachment, this._currentLanguageModel, options, container, this._contextResourceLabels, hoverDelegate);
12351235
} else if (resource && (attachment.kind === 'file' || attachment.kind === 'directory')) {
1236-
attachmentWidget = this.instantiationService.createInstance(FileAttachmentWidget, resource, range, attachment, this._currentLanguageModel, options, container, this._contextResourceLabels, hoverDelegate);
1236+
attachmentWidget = this.instantiationService.createInstance(FileAttachmentWidget, resource, range, attachment, undefined, this._currentLanguageModel, options, container, this._contextResourceLabels, hoverDelegate);
12371237
} else if (isImageVariableEntry(attachment)) {
12381238
attachmentWidget = this.instantiationService.createInstance(ImageAttachmentWidget, resource, attachment, this._currentLanguageModel, options, container, this._contextResourceLabels, hoverDelegate);
12391239
} else if (isElementVariableEntry(attachment)) {
@@ -1243,7 +1243,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
12431243
} else if (isSCMHistoryItemVariableEntry(attachment)) {
12441244
attachmentWidget = this.instantiationService.createInstance(SCMHistoryItemAttachmentWidget, attachment, this._currentLanguageModel, options, container, this._contextResourceLabels, hoverDelegate);
12451245
} else {
1246-
attachmentWidget = this.instantiationService.createInstance(DefaultChatAttachmentWidget, resource, range, attachment, this._currentLanguageModel, options, container, this._contextResourceLabels, hoverDelegate);
1246+
attachmentWidget = this.instantiationService.createInstance(DefaultChatAttachmentWidget, resource, range, attachment, undefined, this._currentLanguageModel, options, container, this._contextResourceLabels, hoverDelegate);
12471247
}
12481248
store.add(attachmentWidget);
12491249
store.add(attachmentWidget.onDidDelete(e => {

0 commit comments

Comments
 (0)