Skip to content

Commit af1d248

Browse files
authored
instructions.md files duplicated in prompts (microsoft#250742)
1 parent 9b409a0 commit af1d248

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatPromptAttachmentsCollection.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { URI } from '../../../../../base/common/uri.js';
77
import { Emitter } from '../../../../../base/common/event.js';
8-
import { basename } from '../../../../../base/common/resources.js';
8+
import { basename, isEqual } from '../../../../../base/common/resources.js';
99
import { ChatPromptAttachmentModel } from './chatPromptAttachmentModel.js';
1010
import { PromptsConfig } from '../../../../../platform/prompts/common/config.js';
1111
import { IPromptFileReference } from '../../common/promptSyntax/parsers/types.js';
@@ -97,6 +97,15 @@ export function isPromptFileChatVariable(
9797
&& variable.id.startsWith(PROMPT_VARIABLE_ID_PREFIX);
9898
}
9999

100+
/**
101+
* Adds the provided `newReference` to the list of chat variables if it is not already present.
102+
*/
103+
export function addPromptFileChatVariable(variables: IChatRequestVariableEntry[], newReference: URI): void {
104+
if (!variables.some(variable => isPromptFileChatVariable(variable) && isEqual(IChatRequestVariableEntry.toUri(variable), newReference))) {
105+
variables.push(toChatVariable({ uri: newReference, isPromptFile: true }, true));
106+
}
107+
}
108+
100109
/**
101110
* Model for a collection of prompt instruction attachments.
102111
* See {@linkcode ChatPromptAttachmentModel} for individual attachment.

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import { handleModeSwitch } from './actions/chatActions.js';
5959
import { ChatTreeItem, IChatAcceptInputOptions, IChatAccessibilityService, IChatCodeBlockInfo, IChatFileTreeInfo, IChatListItemRendererOptions, IChatWidget, IChatWidgetService, IChatWidgetViewContext, IChatWidgetViewOptions } from './chat.js';
6060
import { ChatAccessibilityProvider } from './chatAccessibilityProvider.js';
6161
import { ChatAttachmentModel } from './chatAttachmentModel.js';
62-
import { isPromptFileChatVariable, toChatVariable } from './chatAttachmentModel/chatPromptAttachmentsCollection.js';
62+
import { addPromptFileChatVariable, isPromptFileChatVariable } from './chatAttachmentModel/chatPromptAttachmentsCollection.js';
6363
import { ChatInputPart, IChatInputStyles } from './chatInputPart.js';
6464
import { ChatListDelegate, ChatListItemRenderer, IChatRendererDelegate } from './chatListRenderer.js';
6565
import { ChatEditorOptions } from './chatOptions.js';
@@ -1219,12 +1219,8 @@ export class ChatWidget extends Disposable implements IChatWidget {
12191219
if (agentSlashPromptPart) {
12201220
metadata = await this.promptsService.resolvePromptSlashCommand(agentSlashPromptPart.slashPromptCommand);
12211221
if (metadata) {
1222-
const uri = metadata.uri;
1223-
if (!requestInput.attachedContext.some(variable => isPromptFileChatVariable(variable) && isEqual(IChatRequestVariableEntry.toUri(variable), uri))) {
1224-
// not yet attached, so attach it
1225-
const variable = toChatVariable({ uri: metadata.uri, isPromptFile: true }, true);
1226-
requestInput.attachedContext.push(variable);
1227-
}
1222+
// add the prompt file to the context, but not sticky
1223+
addPromptFileChatVariable(requestInput.attachedContext, metadata.uri);
12281224
// remove the slash command from the input
12291225
requestInput.input = this.parsedInput.parts.filter(part => !(part instanceof ChatRequestSlashPromptPart)).map(part => part.text).join('').trim();
12301226
}
@@ -1631,11 +1627,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
16311627
.findInstructionFilesFor(variableUris);
16321628

16331629
// add instructions to the final context list
1634-
attachedContext.push(
1635-
...automaticInstructions.map((uri) => {
1636-
return toChatVariable({ uri, isPromptFile: true }, true);
1637-
}),
1638-
);
1630+
automaticInstructions.forEach(instruction => addPromptFileChatVariable(attachedContext, instruction));
16391631

16401632
// add to attached list to make the instructions sticky
16411633
this.inputPart

0 commit comments

Comments
 (0)