Skip to content

Commit def9aff

Browse files
authored
Edits and Chat drag and drop should align again (microsoft#242171)
fixes microsoft/vscode-copilot#13496
1 parent a03cb7c commit def9aff

File tree

2 files changed

+11
-94
lines changed

2 files changed

+11
-94
lines changed

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

Lines changed: 9 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import { coalesce } from '../../../../base/common/arrays.js';
1010
import { Codicon } from '../../../../base/common/codicons.js';
1111
import { IDisposable } from '../../../../base/common/lifecycle.js';
1212
import { Mimes } from '../../../../base/common/mime.js';
13-
import { basename, joinPath } from '../../../../base/common/resources.js';
13+
import { basename } from '../../../../base/common/resources.js';
1414
import { URI } from '../../../../base/common/uri.js';
1515
import { IRange } from '../../../../editor/common/core/range.js';
1616
import { SymbolKinds } from '../../../../editor/common/languages.js';
1717
import { ITextModelService } from '../../../../editor/common/services/resolverService.js';
1818
import { localize } from '../../../../nls.js';
1919
import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js';
2020
import { CodeDataTransfers, containsDragType, DocumentSymbolTransferData, extractEditorsDropData, extractMarkerDropData, extractSymbolDropData, IDraggedResourceEditorInput, MarkerTransferData } from '../../../../platform/dnd/browser/dnd.js';
21-
import { FileType, IFileService, IFileSystemProvider } from '../../../../platform/files/common/files.js';
21+
import { IFileService } from '../../../../platform/files/common/files.js';
2222
import { MarkerSeverity } from '../../../../platform/markers/common/markers.js';
2323
import { IThemeService, Themable } from '../../../../platform/theme/common/themeService.js';
2424
import { isUntitledResourceEditorInput } from '../../../common/editor.js';
@@ -48,14 +48,14 @@ export class ChatDragAndDrop extends Themable {
4848
private overlayTextBackground: string = '';
4949

5050
constructor(
51-
protected readonly attachmentModel: ChatAttachmentModel,
51+
private readonly attachmentModel: ChatAttachmentModel,
5252
private readonly styles: IChatInputStyles,
5353
@IThemeService themeService: IThemeService,
5454
@IExtensionService private readonly extensionService: IExtensionService,
55-
@IFileService protected readonly fileService: IFileService,
56-
@IEditorService protected readonly editorService: IEditorService,
57-
@IDialogService protected readonly dialogService: IDialogService,
58-
@ITextModelService protected readonly textModelService: ITextModelService
55+
@IFileService private readonly fileService: IFileService,
56+
@IEditorService private readonly editorService: IEditorService,
57+
@IDialogService private readonly dialogService: IDialogService,
58+
@ITextModelService private readonly textModelService: ITextModelService
5959
) {
6060
super(themeService);
6161

@@ -150,10 +150,6 @@ export class ChatDragAndDrop extends Themable {
150150
return;
151151
}
152152

153-
this.handleDrop(contexts);
154-
}
155-
156-
protected handleDrop(contexts: IChatRequestVariableEntry[]): void {
157153
this.attachmentModel.addContext(...contexts);
158154
}
159155

@@ -193,7 +189,7 @@ export class ChatDragAndDrop extends Themable {
193189
return dropType !== undefined;
194190
}
195191

196-
protected getDropTypeName(type: ChatDragAndDropType): string {
192+
private getDropTypeName(type: ChatDragAndDropType): string {
197193
switch (type) {
198194
case ChatDragAndDropType.FILE_INTERNAL: return localize('file', 'File');
199195
case ChatDragAndDropType.FILE_EXTERNAL: return localize('file', 'File');
@@ -412,7 +408,7 @@ export class ChatDragAndDrop extends Themable {
412408
overlay.classList.toggle('visible', type !== undefined);
413409
}
414410

415-
protected getOverlayText(type: ChatDragAndDropType): string {
411+
private getOverlayText(type: ChatDragAndDropType): string {
416412
const typeName = this.getDropTypeName(type);
417413
return localize('attacAsContext', 'Attach {0} as Context', typeName);
418414
}
@@ -428,81 +424,6 @@ export class ChatDragAndDrop extends Themable {
428424
}
429425
}
430426

431-
export class EditsDragAndDrop extends ChatDragAndDrop {
432-
433-
constructor(
434-
attachmentModel: ChatAttachmentModel,
435-
styles: IChatInputStyles,
436-
@IThemeService themeService: IThemeService,
437-
@IExtensionService extensionService: IExtensionService,
438-
@IFileService fileService: IFileService,
439-
@IEditorService editorService: IEditorService,
440-
@IDialogService dialogService: IDialogService,
441-
@ITextModelService textModelService: ITextModelService
442-
) {
443-
super(attachmentModel, styles, themeService, extensionService, fileService, editorService, dialogService, textModelService);
444-
}
445-
446-
protected override handleDrop(context: IChatRequestVariableEntry[]): void {
447-
this.handleDropAsync(context);
448-
}
449-
450-
protected async handleDropAsync(context: IChatRequestVariableEntry[]): Promise<void> {
451-
const nonDirectoryContext = context.filter(context => !context.isDirectory);
452-
const directories = context
453-
.filter(context => context.isDirectory)
454-
.map(context => context.value)
455-
.filter(value => !!value && URI.isUri(value));
456-
457-
// If there are directories, we need to resolve the files and add them to the working set
458-
for (const directory of directories) {
459-
const fileSystemProvider = this.fileService.getProvider(directory.scheme);
460-
if (!fileSystemProvider) {
461-
continue;
462-
}
463-
464-
const resolvedFiles = await resolveFilesInDirectory(directory, fileSystemProvider, true);
465-
const resolvedFileContext = await Promise.all(resolvedFiles.map(file => getResourceAttachContext(file, false, this.textModelService)));
466-
nonDirectoryContext.push(...resolvedFileContext.filter(context => !!context));
467-
}
468-
469-
super.handleDrop(nonDirectoryContext);
470-
}
471-
472-
protected override getOverlayText(type: ChatDragAndDropType): string {
473-
const typeName = this.getDropTypeName(type);
474-
switch (type) {
475-
case ChatDragAndDropType.FILE_INTERNAL:
476-
case ChatDragAndDropType.FILE_EXTERNAL:
477-
return localize('addToWorkingSet', 'Add {0} to Working Set', typeName);
478-
case ChatDragAndDropType.FOLDER:
479-
return localize('addToWorkingSet', 'Add {0} to Working Set', localize('files', 'Files'));
480-
default:
481-
return super.getOverlayText(type);
482-
}
483-
}
484-
}
485-
486-
async function resolveFilesInDirectory(resource: URI, fileSystemProvider: IFileSystemProvider, shouldRecurse: boolean): Promise<URI[]> {
487-
const entries = await fileSystemProvider.readdir(resource);
488-
489-
const files: URI[] = [];
490-
const folders: URI[] = [];
491-
492-
for (const [name, type] of entries) {
493-
const entryResource = joinPath(resource, name);
494-
if (type === FileType.File) {
495-
files.push(entryResource);
496-
} else if (type === FileType.Directory && shouldRecurse) {
497-
folders.push(entryResource);
498-
}
499-
}
500-
501-
const subFiles = await Promise.all(folders.map(folder => resolveFilesInDirectory(folder, fileSystemProvider, shouldRecurse)));
502-
503-
return [...files, ...subFiles.flat()];
504-
}
505-
506427
async function getResourceAttachContext(resource: URI, isDirectory: boolean, textModelService: ITextModelService): Promise<IChatRequestVariableEntry | undefined> {
507428
let isOmitted = false;
508429

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import { toChatVariable } from './chatAttachmentModel/chatPromptAttachmentsColle
9595
import { hookUpResourceAttachmentDragAndContextMenu, hookUpSymbolAttachmentDragAndContextMenu } from './chatContentParts/chatAttachmentsContentPart.js';
9696
import { IDisposableReference } from './chatContentParts/chatCollections.js';
9797
import { CollapsibleListPool, IChatCollapsibleListItem } from './chatContentParts/chatReferencesContentPart.js';
98-
import { ChatDragAndDrop, EditsDragAndDrop } from './chatDragAndDrop.js';
98+
import { ChatDragAndDrop } from './chatDragAndDrop.js';
9999
import { ChatEditingRemoveAllFilesAction, ChatEditingShowChangesAction } from './chatEditing/chatEditingActions.js';
100100
import { ChatFollowups } from './chatFollowups.js';
101101
import { IChatViewState } from './chatWidget.js';
@@ -361,11 +361,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
361361
super();
362362

363363
this._attachmentModel = this._register(this.instantiationService.createInstance(ChatAttachmentModel));
364-
if (this.location === ChatAgentLocation.EditingSession) {
365-
this.dnd = this._register(this.instantiationService.createInstance(EditsDragAndDrop, this.attachmentModel, styles));
366-
} else {
367-
this.dnd = this._register(this.instantiationService.createInstance(ChatDragAndDrop, this.attachmentModel, styles));
368-
}
364+
this.dnd = this._register(this.instantiationService.createInstance(ChatDragAndDrop, this._attachmentModel, styles));
369365

370366
this.getInputState = (): IChatInputState => {
371367
return {

0 commit comments

Comments
 (0)