Skip to content

Commit 5fe066f

Browse files
authored
fix: don't bury lede in chat attachment aria label (microsoft#223538)
1 parent d5ff113 commit 5fe066f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,21 @@ export class ChatAttachmentsContentPart extends Disposable {
4747
const range = attachment.value && typeof attachment.value === 'object' && 'range' in attachment.value && Range.isIRange(attachment.value.range) ? attachment.value.range : undefined;
4848

4949
const correspondingContentReference = this.contentReferences.find((ref) => 'variableName' in ref.reference && ref.reference.variableName === attachment.name);
50+
const isAttachmentOmitted = correspondingContentReference?.options?.status?.kind === ChatResponseReferencePartStatusKind.Omitted;
51+
const isAttachmentPartialOrOmitted = isAttachmentOmitted || correspondingContentReference?.options?.status?.kind === ChatResponseReferencePartStatusKind.Partial;
5052

5153
if (file) {
5254
const fileBasename = basename(file.path);
5355
const fileDirname = dirname(file.path);
5456
const friendlyName = `${fileBasename} ${fileDirname}`;
55-
const ariaLabel = range ? localize('chat.fileAttachmentWithRange2', "Attached file, {0}, line {1} to line {2}.", friendlyName, range.startLineNumber, range.endLineNumber) : localize('chat.fileAttachment2', "Attached file, {0}.", friendlyName);
57+
let ariaLabel;
58+
if (isAttachmentOmitted) {
59+
ariaLabel = range ? localize('chat.omittedFileAttachmentWithRange', "Omitted: {0}, line {1} to line {2}.", friendlyName, range.startLineNumber, range.endLineNumber) : localize('chat.omittedFileAttachment', "Omitted: {0}.", friendlyName);
60+
} else if (isAttachmentPartialOrOmitted) {
61+
ariaLabel = range ? localize('chat.partialFileAttachmentWithRange', "Partially attached: {0}, line {1} to line {2}.", friendlyName, range.startLineNumber, range.endLineNumber) : localize('chat.partialFileAttachment', "Partially attached: {0}.", friendlyName);
62+
} else {
63+
ariaLabel = range ? localize('chat.fileAttachmentWithRange3', "Attached: {0}, line {1} to line {2}.", friendlyName, range.startLineNumber, range.endLineNumber) : localize('chat.fileAttachment3', "Attached: {0}.", friendlyName);
64+
}
5665

5766
label.setFile(file, {
5867
fileKind: FileKind.FILE,
@@ -81,11 +90,10 @@ export class ChatAttachmentsContentPart extends Disposable {
8190
const attachmentLabel = attachment.fullName ?? attachment.name;
8291
label.setLabel(attachmentLabel, correspondingContentReference?.options?.status?.description);
8392

84-
widget.ariaLabel = localize('chat.attachment2', "Attached context, {0}.", attachment.name);
93+
widget.ariaLabel = localize('chat.attachment3', "Attached context: {0}.", attachment.name);
8594
widget.tabIndex = 0;
8695
}
8796

88-
const isAttachmentPartialOrOmitted = correspondingContentReference?.options?.status?.kind === ChatResponseReferencePartStatusKind.Omitted || correspondingContentReference?.options?.status?.kind === ChatResponseReferencePartStatusKind.Partial;
8997
if (isAttachmentPartialOrOmitted) {
9098
widget.classList.add('warning');
9199
}

0 commit comments

Comments
 (0)