Skip to content

Commit 7e84e80

Browse files
authored
fix chat rendering issue - renderAttachments back to sync (microsoft#242238)
fix rendering issue, back to sync
1 parent b1f8442 commit 7e84e80

File tree

2 files changed

+7
-46
lines changed

2 files changed

+7
-46
lines changed

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

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { StandardMouseEvent } from '../../../../../base/browser/mouseEvent.js';
88
import { IManagedHoverTooltipMarkdownString } from '../../../../../base/browser/ui/hover/hover.js';
99
import { IHoverDelegate } from '../../../../../base/browser/ui/hover/hoverDelegate.js';
1010
import { createInstantHoverDelegate } from '../../../../../base/browser/ui/hover/hoverDelegateFactory.js';
11-
import { Promises } from '../../../../../base/common/async.js';
1211
import { Codicon } from '../../../../../base/common/codicons.js';
1312
import { Emitter } from '../../../../../base/common/event.js';
1413
import { Disposable, DisposableStore, IDisposable } from '../../../../../base/common/lifecycle.js';
@@ -62,7 +61,6 @@ export class ChatAttachmentsContentPart extends Disposable {
6261
@IInstantiationService private readonly instantiationService: IInstantiationService,
6362
@IOpenerService private readonly openerService: IOpenerService,
6463
@IHoverService private readonly hoverService: IHoverService,
65-
@IFileService private readonly fileService: IFileService,
6664
@ICommandService private readonly commandService: ICommandService,
6765
@IThemeService private readonly themeService: IThemeService,
6866
@ILabelService private readonly labelService: ILabelService,
@@ -80,7 +78,6 @@ export class ChatAttachmentsContentPart extends Disposable {
8078
this.attachedContextDisposables.clear();
8179
const hoverDelegate = this.attachedContextDisposables.add(createInstantHoverDelegate());
8280

83-
const attachmentInitPromises: Promise<void>[] = [];
8481
this.variables.forEach(async (attachment) => {
8582
let 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;
8683
let range = attachment.value && typeof attachment.value === 'object' && 'range' in attachment.value && Range.isIRange(attachment.value.range) ? attachment.value.range : undefined;
@@ -148,25 +145,9 @@ export class ChatAttachmentsContentPart extends Disposable {
148145
}
149146

150147
if (!isAttachmentPartialOrOmitted) {
151-
attachmentInitPromises.push(Promises.withAsyncBody(async (resolve) => {
152-
let buffer: Uint8Array;
153-
try {
154-
if (attachment.value instanceof URI) {
155-
const readFile = await this.fileService.readFile(attachment.value);
156-
if (this.attachedContextDisposables.isDisposed) {
157-
return;
158-
}
159-
buffer = readFile.value.buffer;
160-
} else {
161-
buffer = attachment.value as Uint8Array;
162-
}
163-
this.createImageElements(buffer, widget, hoverElement);
164-
} catch (error) {
165-
console.error('Error processing attachment:', error);
166-
}
167-
this.attachedContextDisposables.add(this.hoverService.setupManagedHover(hoverDelegate, widget, hoverElement, { trapFocus: false }));
168-
resolve();
169-
}));
148+
const buffer = attachment.value as Uint8Array;
149+
this.createImageElements(buffer, widget, hoverElement);
150+
this.attachedContextDisposables.add(this.hoverService.setupManagedHover(hoverDelegate, widget, hoverElement, { trapFocus: false }));
170151
}
171152
widget.style.position = 'relative';
172153
} else if (isPasteVariableEntry(attachment)) {
@@ -231,7 +212,6 @@ export class ChatAttachmentsContentPart extends Disposable {
231212
}
232213
}
233214

234-
await Promise.all(attachmentInitPromises);
235215
if (this.attachedContextDisposables.isDisposed) {
236216
return;
237217
}

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

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { IHoverDelegate } from '../../../../base/browser/ui/hover/hoverDelegate.
1717
import { createInstantHoverDelegate, getDefaultHoverDelegate } from '../../../../base/browser/ui/hover/hoverDelegateFactory.js';
1818
import { renderLabelWithIcons } from '../../../../base/browser/ui/iconLabel/iconLabels.js';
1919
import { IAction, Separator, toAction } from '../../../../base/common/actions.js';
20-
import { Promises } from '../../../../base/common/async.js';
2120
import { Codicon } from '../../../../base/common/codicons.js';
2221
import { Emitter, Event } from '../../../../base/common/event.js';
2322
import { HistoryNavigator2 } from '../../../../base/common/history.js';
@@ -983,7 +982,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
983982
}
984983
}
985984

986-
private async renderAttachedContext() {
985+
private renderAttachedContext() {
987986
const container = this.attachedContextContainer;
988987
const oldHeight = container.offsetHeight;
989988
const store = new DisposableStore();
@@ -1006,7 +1005,6 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
10061005
this.promptInstructionsAttached.set(!this.instructionAttachmentsPart.empty);
10071006
this.instructionAttachmentsPart.render(container);
10081007

1009-
const attachmentInitPromises: Promise<void>[] = [];
10101008
for (const [index, attachment] of attachments) {
10111009
const widget = dom.append(container, $('.chat-attached-context-attachment.show-file-icons'));
10121010
const label = this._contextResourceLabels.create(widget, { supportIcons: true, hoverDelegate, hoverTargetOverride: widget });
@@ -1059,25 +1057,9 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
10591057
}
10601058

10611059
if (supportsVision) {
1062-
attachmentInitPromises.push(Promises.withAsyncBody(async (resolve) => {
1063-
let buffer: Uint8Array;
1064-
try {
1065-
if (attachment.value instanceof URI) {
1066-
const readFile = await this.fileService.readFile(attachment.value);
1067-
if (store.isDisposed) {
1068-
return;
1069-
}
1070-
buffer = readFile.value.buffer;
1071-
} else {
1072-
buffer = attachment.value as Uint8Array;
1073-
}
1074-
this.createImageElements(buffer, widget, hoverElement);
1075-
} catch (error) {
1076-
console.error('Error processing attachment:', error);
1077-
}
1078-
store.add(this.hoverService.setupManagedHover(hoverDelegate, widget, hoverElement, { trapFocus: false }));
1079-
resolve();
1080-
}));
1060+
const buffer = attachment.value as Uint8Array;
1061+
this.createImageElements(buffer, widget, hoverElement);
1062+
store.add(this.hoverService.setupManagedHover(hoverDelegate, widget, hoverElement, { trapFocus: false }));
10811063
}
10821064

10831065
this.attachButtonAndDisposables(widget, index, attachment, hoverDelegate);
@@ -1142,7 +1124,6 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
11421124
store.add(this.instantiationService.invokeFunction(accessor => hookUpSymbolAttachmentDragAndContextMenu(accessor, widget, scopedContextKeyService, { ...attachment, kind: attachment.symbolKind }, MenuId.ChatInputSymbolAttachmentContext)));
11431125
}
11441126

1145-
await Promise.all(attachmentInitPromises);
11461127
if (store.isDisposed) {
11471128
return;
11481129
}

0 commit comments

Comments
 (0)