Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/vs/workbench/contrib/chat/browser/chatDragAndDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { URI } from '../../../../base/common/uri.js';
import { IRange } from '../../../../editor/common/core/range.js';
import { SymbolKinds } from '../../../../editor/common/languages.js';
import { localize } from '../../../../nls.js';
import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js';
import { CodeDataTransfers, containsDragType, DocumentSymbolTransferData, extractEditorsDropData, extractSymbolDropData, IDraggedResourceEditorInput } from '../../../../platform/dnd/browser/dnd.js';
import { FileType, IFileService, IFileSystemProvider } from '../../../../platform/files/common/files.js';
import { IThemeService, Themable } from '../../../../platform/theme/common/themeService.js';
Expand Down Expand Up @@ -49,6 +50,7 @@ export class ChatDragAndDrop extends Themable {
@IExtensionService private readonly extensionService: IExtensionService,
@IFileService protected readonly fileService: IFileService,
@IEditorService protected readonly editorService: IEditorService,
@IDialogService protected readonly dialogService: IDialogService
) {
super(themeService);

Expand Down Expand Up @@ -233,7 +235,7 @@ export class ChatDragAndDrop extends Themable {

private async resolveAttachContext(editorInput: IDraggedResourceEditorInput): Promise<IChatRequestVariableEntry | undefined> {
// Image
const imageContext = await getImageAttachContext(editorInput, this.fileService);
const imageContext = await getImageAttachContext(editorInput, this.fileService, this.dialogService);
if (imageContext) {
return this.extensionService.extensions.some(ext => isProposedApiEnabled(ext, 'chatReferenceBinaryData')) ? imageContext : undefined;
}
Expand Down Expand Up @@ -350,8 +352,9 @@ export class EditsDragAndDrop extends ChatDragAndDrop {
@IExtensionService extensionService: IExtensionService,
@IFileService fileService: IFileService,
@IEditorService editorService: IEditorService,
@IDialogService dialogService: IDialogService
) {
super(attachmentModel, styles, themeService, extensionService, fileService, editorService);
super(attachmentModel, styles, themeService, extensionService, fileService, editorService, dialogService);
}

protected override handleDrop(context: IChatRequestVariableEntry[]): void {
Expand Down Expand Up @@ -424,14 +427,18 @@ function getResourceAttachContext(resource: URI, isDirectory: boolean): IChatReq
};
}

async function getImageAttachContext(editor: EditorInput | IDraggedResourceEditorInput, fileService: IFileService): Promise<IChatRequestVariableEntry | undefined> {
async function getImageAttachContext(editor: EditorInput | IDraggedResourceEditorInput, fileService: IFileService, dialogService: IDialogService): Promise<IChatRequestVariableEntry | undefined> {
if (!editor.resource) {
return undefined;
}

if (/\.(png|jpg|jpeg|gif|webp)$/i.test(editor.resource.path)) {
const fileName = basename(editor.resource);
const readFile = await fileService.readFile(editor.resource);
if (readFile.size > 30 * 1024 * 1024) { // 30 MB
dialogService.error(localize('imageTooLarge', 'Image is too large'), localize('imageTooLargeMessage', 'The image {0} is too large to be attached.', fileName));
throw new Error('Image is too large');
}
const resizedImage = await resizeImage(readFile.value.buffer);
return {
id: editor.resource.toString(),
Expand Down
Loading