Skip to content

Commit 95f1d43

Browse files
authored
copilot-instructions.md not added when chat.promptFiles is disabled (#256573)
1 parent 25d003b commit 95f1d43

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,11 @@ export class ChatWidget extends Disposable implements IChatWidget {
15861586
}
15871587

15881588
private async _applyPromptFileIfSet(requestInput: IChatRequestInputOptions): Promise<IPromptParserResult | undefined> {
1589+
if (!PromptsConfig.enabled(this.configurationService)) {
1590+
// if prompts are not enabled, we don't need to do anything
1591+
return undefined;
1592+
}
1593+
15891594

15901595
let parseResult: IPromptParserResult | undefined;
15911596

@@ -1656,8 +1661,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
16561661

16571662
const isUserQuery = !query;
16581663

1659-
const instructionsEnabled = PromptsConfig.enabled(this.configurationService);
1660-
if (instructionsEnabled && !this.viewModel.editing) {
1664+
if (!this.viewModel.editing) {
16611665
// process the prompt command
16621666
await this._applyPromptFileIfSet(requestInputs);
16631667
await this._autoAttachInstructions(requestInputs);
@@ -1999,14 +2003,22 @@ export class ChatWidget extends Disposable implements IChatWidget {
19992003
* - instructions referenced in an already included instruction file
20002004
*/
20012005
private async _autoAttachInstructions({ attachedContext }: IChatRequestInputOptions): Promise<void> {
2002-
let readFileTool = this.toolsService.getToolByName('readFile');
2003-
const enablementMap = this.input.selectedToolsModel.enablementMap.get();
2004-
if (readFileTool && Iterable.some(enablementMap, ([tool, enabled]) => tool.id === readFileTool!.id && enabled === false)) {
2005-
readFileTool = undefined;
2006-
}
2006+
const promptsConfigEnabled = PromptsConfig.enabled(this.configurationService);
2007+
this.logService.debug(`ChatWidget#_autoAttachInstructions: ${PromptsConfig.KEY}: ${promptsConfigEnabled}`);
2008+
2009+
if (promptsConfigEnabled) {
2010+
let readFileTool = this.toolsService.getToolByName('readFile');
2011+
const enablementMap = this.input.selectedToolsModel.enablementMap.get();
2012+
if (readFileTool && Iterable.some(enablementMap, ([tool, enabled]) => tool.id === readFileTool!.id && enabled === false)) {
2013+
readFileTool = undefined;
2014+
}
20072015

2008-
const computer = this.instantiationService.createInstance(ComputeAutomaticInstructions, readFileTool);
2009-
await computer.collect(attachedContext, CancellationToken.None);
2016+
const computer = this.instantiationService.createInstance(ComputeAutomaticInstructions, readFileTool);
2017+
await computer.collect(attachedContext, CancellationToken.None);
2018+
} else {
2019+
const computer = this.instantiationService.createInstance(ComputeAutomaticInstructions, undefined);
2020+
await computer.collectCopilotInstructionsOnly(attachedContext, CancellationToken.None);
2021+
}
20102022

20112023
// add to attached list to make the instructions sticky
20122024
//this.inputPart.attachmentModel.addContext(...computer.autoAddedInstructions);

src/vs/workbench/contrib/chat/common/promptSyntax/computeAutomaticInstructions.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ export class ComputeAutomaticInstructions {
8181

8282
}
8383

84+
public async collectCopilotInstructionsOnly(variables: ChatRequestVariableSet, token: CancellationToken): Promise<void> {
85+
const copilotInstructions = await this._getCopilotInstructions();
86+
for (const entry of copilotInstructions) {
87+
variables.add(entry);
88+
}
89+
this._logService.trace(`[InstructionsContextComputer] ${copilotInstructions.length} Copilot instructions files added.`);
90+
// add all instructions for all instruction files that are in the context
91+
await this._addReferencedInstructions(variables, token);
92+
return;
93+
}
94+
8495
/** public for testing */
8596
public async findInstructionFilesFor(instructionFiles: readonly IPromptPath[], context: { files: ResourceSet; instructions: ResourceSet }, token: CancellationToken): Promise<IPromptFileVariableEntry[]> {
8697

0 commit comments

Comments
 (0)