Skip to content

Commit a426831

Browse files
authored
Merge pull request microsoft#256738 from microsoft/tyriar/boost_active
Boost active file in chat completions
2 parents 02eb425 + 9a3f987 commit a426831

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -868,15 +868,16 @@ class BuiltinDynamicCompletions extends Disposable {
868868

869869
private async addFileAndFolderEntries(widget: IChatWidget, result: CompletionList, info: { insert: Range; replace: Range; varWord: IWordAtPosition | null }, token: CancellationToken) {
870870

871-
const makeCompletionItem = (resource: URI, kind: FileKind, description?: string): CompletionItem => {
872-
871+
const makeCompletionItem = (resource: URI, kind: FileKind, description?: string, boostPriority?: boolean): CompletionItem => {
872+
console.log('makeCompletionItem', resource);
873873
const basename = this.labelService.getUriBasenameLabel(resource);
874874
const text = `${chatVariableLeader}file:${basename}`;
875875
const uriLabel = this.labelService.getUriLabel(resource, { relative: true });
876876
const labelDescription = description
877877
? localize('fileEntryDescription', '{0} ({1})', uriLabel, description)
878878
: uriLabel;
879-
const sortText = ' '; // keep files always at the top
879+
// keep files above other completions
880+
const sortText = boostPriority ? ' ' : '!';
880881

881882
return {
882883
label: { label: basename, description: labelDescription },
@@ -905,22 +906,9 @@ class BuiltinDynamicCompletions extends Disposable {
905906
const seen = new ResourceSet();
906907
const len = result.suggestions.length;
907908

908-
// RELATED FILES
909-
if (widget.input.currentModeKind !== ChatModeKind.Ask && widget.viewModel && widget.viewModel.model.editingSession) {
910-
const relatedFiles = (await raceTimeout(this._chatEditingService.getRelatedFiles(widget.viewModel.sessionId, widget.getInput(), widget.attachmentModel.fileAttachments, token), 200)) ?? [];
911-
for (const relatedFileGroup of relatedFiles) {
912-
for (const relatedFile of relatedFileGroup.files) {
913-
if (!seen.has(relatedFile.uri)) {
914-
seen.add(relatedFile.uri);
915-
result.suggestions.push(makeCompletionItem(relatedFile.uri, FileKind.FILE, relatedFile.description));
916-
}
917-
}
918-
}
919-
}
920-
921909
// HISTORY
922910
// always take the last N items
923-
for (const item of this.historyService.getHistory()) {
911+
for (const [i, item] of this.historyService.getHistory().entries()) {
924912
if (!item.resource || seen.has(item.resource)) {
925913
// ignore editors without a resource
926914
continue;
@@ -935,12 +923,25 @@ class BuiltinDynamicCompletions extends Disposable {
935923
}
936924

937925
seen.add(item.resource);
938-
const newLen = result.suggestions.push(makeCompletionItem(item.resource, FileKind.FILE));
926+
const newLen = result.suggestions.push(makeCompletionItem(item.resource, FileKind.FILE, i === 0 ? localize('activeFile', 'Active file') : undefined, i === 0));
939927
if (newLen - len >= 5) {
940928
break;
941929
}
942930
}
943931

932+
// RELATED FILES
933+
if (widget.input.currentModeKind !== ChatModeKind.Ask && widget.viewModel && widget.viewModel.model.editingSession) {
934+
const relatedFiles = (await raceTimeout(this._chatEditingService.getRelatedFiles(widget.viewModel.sessionId, widget.getInput(), widget.attachmentModel.fileAttachments, token), 200)) ?? [];
935+
for (const relatedFileGroup of relatedFiles) {
936+
for (const relatedFile of relatedFileGroup.files) {
937+
if (!seen.has(relatedFile.uri)) {
938+
seen.add(relatedFile.uri);
939+
result.suggestions.push(makeCompletionItem(relatedFile.uri, FileKind.FILE, relatedFile.description));
940+
}
941+
}
942+
}
943+
}
944+
944945
// SEARCH
945946
// use file search when having a pattern
946947
if (pattern) {

0 commit comments

Comments
 (0)