Skip to content

Commit 5a95072

Browse files
authored
copilot-instructions.md not added when chat.promptFiles is disabled (microsoft#256438)
1 parent 5b071d5 commit 5a95072

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,11 @@ export class ChatWidget extends Disposable implements IChatWidget {
15651565
}
15661566

15671567
private async _applyPromptFileIfSet(requestInput: IChatRequestInputOptions): Promise<IPromptParserResult | undefined> {
1568+
if (!PromptsConfig.enabled(this.configurationService)) {
1569+
// if prompts are not enabled, we don't need to do anything
1570+
return undefined;
1571+
}
1572+
15681573

15691574
let parseResult: IPromptParserResult | undefined;
15701575

@@ -1635,12 +1640,9 @@ export class ChatWidget extends Disposable implements IChatWidget {
16351640

16361641
const isUserQuery = !query;
16371642

1638-
const instructionsEnabled = PromptsConfig.enabled(this.configurationService);
1639-
if (instructionsEnabled) {
1640-
// process the prompt command
1641-
await this._applyPromptFileIfSet(requestInputs);
1642-
await this._autoAttachInstructions(requestInputs);
1643-
}
1643+
// process the prompt command and instruction files
1644+
await this._applyPromptFileIfSet(requestInputs);
1645+
await this._autoAttachInstructions(requestInputs);
16441646

16451647
if (this.viewOptions.enableWorkingSet !== undefined && this.input.currentModeKind === ChatModeKind.Edit && !this.chatService.edits2Enabled) {
16461648
const uniqueWorkingSetEntries = new ResourceSet(); // NOTE: this is used for bookkeeping so the UI can avoid rendering references in the UI that are already shown in the working set
@@ -1980,13 +1982,21 @@ export class ChatWidget extends Disposable implements IChatWidget {
19801982
* - instructions referenced in an already included instruction file
19811983
*/
19821984
private async _autoAttachInstructions({ attachedContext }: IChatRequestInputOptions): Promise<void> {
1983-
let readFileTool = this.toolsService.getToolByName('readFile');
1984-
if (readFileTool && this.getUserSelectedTools()?.[readFileTool.id] === false) {
1985-
readFileTool = undefined;
1986-
}
1985+
const promptsConfigEnabled = PromptsConfig.enabled(this.configurationService);
1986+
this.logService.debug(`ChatWidget#_autoAttachInstructions: ${PromptsConfig.KEY}: ${promptsConfigEnabled}`);
19871987

1988-
const computer = this.instantiationService.createInstance(ComputeAutomaticInstructions, readFileTool);
1989-
await computer.collect(attachedContext, CancellationToken.None);
1988+
if (promptsConfigEnabled) {
1989+
let readFileTool = this.toolsService.getToolByName('readFile');
1990+
if (readFileTool && this.getUserSelectedTools()?.[readFileTool.id] === false) {
1991+
readFileTool = undefined;
1992+
}
1993+
1994+
const computer = this.instantiationService.createInstance(ComputeAutomaticInstructions, readFileTool);
1995+
await computer.collect(attachedContext, CancellationToken.None);
1996+
} else {
1997+
const computer = this.instantiationService.createInstance(ComputeAutomaticInstructions, undefined);
1998+
await computer.collectCopilotInstructionsOnly(attachedContext, CancellationToken.None);
1999+
}
19902000

19912001
// add to attached list to make the instructions sticky
19922002
//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)