Skip to content

Commit 28ef807

Browse files
authored
allow instruction files from contributions (#1185)
1 parent 1778275 commit 28ef807

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/platform/customInstructions/common/customInstructionsService.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import type * as vscode from 'vscode';
77
import { createServiceIdentifier } from '../../../util/common/services';
88
import { match } from '../../../util/vs/base/common/glob';
9+
import { Disposable } from '../../../util/vs/base/common/lifecycle';
10+
import { ResourceSet } from '../../../util/vs/base/common/map';
911
import { Schemas } from '../../../util/vs/base/common/network';
1012
import { dirname, isAbsolute } from '../../../util/vs/base/common/path';
1113
import { joinPath } from '../../../util/vs/base/common/resources';
@@ -14,6 +16,7 @@ import { URI } from '../../../util/vs/base/common/uri';
1416
import { FileType, Uri } from '../../../vscodeTypes';
1517
import { CodeGenerationImportInstruction, CodeGenerationTextInstruction, Config, ConfigKey, IConfigurationService } from '../../configuration/common/configurationService';
1618
import { IEnvService } from '../../env/common/envService';
19+
import { IExtensionsService } from '../../extensions/common/extensionsService';
1720
import { IFileSystemService } from '../../filesystem/common/fileSystemService';
1821
import { ILogService } from '../../log/common/logService';
1922
import { IPromptPathRepresentationService } from '../../prompts/common/promptPathRepresentationService';
@@ -74,18 +77,25 @@ const INSTRUCTIONS_LOCATION_KEY = 'chat.instructionsFilesLocations';
7477
const COPILOT_INSTRUCTIONS_PATH = '.github/copilot-instructions.md';
7578

7679

77-
export class CustomInstructionsService implements ICustomInstructionsService {
80+
export class CustomInstructionsService extends Disposable implements ICustomInstructionsService {
7881

7982
readonly _serviceBrand: undefined;
8083

84+
private _contributedInstructions: ResourceSet | undefined;
85+
8186
constructor(
8287
@IConfigurationService private readonly configurationService: IConfigurationService,
8388
@IEnvService private readonly envService: IEnvService,
8489
@IWorkspaceService private readonly workspaceService: IWorkspaceService,
8590
@IFileSystemService private readonly fileSystemService: IFileSystemService,
8691
@IPromptPathRepresentationService private readonly promptPathRepresentationService: IPromptPathRepresentationService,
8792
@ILogService private readonly logService: ILogService,
93+
@IExtensionsService private readonly extensionService: IExtensionsService,
8894
) {
95+
super();
96+
this._register(this.extensionService.onDidChange(() => {
97+
this._contributedInstructions = undefined;
98+
}));
8999
}
90100

91101
public async fetchInstructionsFromFile(fileUri: Uri): Promise<ICustomInstructions | undefined> {
@@ -188,6 +198,10 @@ export class CustomInstructionsService implements ICustomInstructionsService {
188198
if (uri.scheme === Schemas.vscodeUserData) {
189199
return true;
190200
}
201+
if (this.getInstructionURLFromExtensionPoint().has(uri)) {
202+
return true;
203+
}
204+
191205
if (uri.scheme !== Schemas.file) {
192206
return false;
193207
}
@@ -209,4 +223,24 @@ export class CustomInstructionsService implements ICustomInstructionsService {
209223
}
210224
return true;
211225
}
226+
227+
private getInstructionURLFromExtensionPoint(): ResourceSet {
228+
if (!this._contributedInstructions) {
229+
const result = new ResourceSet();
230+
for (const extension of this.extensionService.all) {
231+
232+
const chatInstructions = extension.packageJSON['contributes']?.['chatInstructions'];
233+
if (Array.isArray(chatInstructions)) {
234+
for (const contribution of chatInstructions) {
235+
if (contribution.path) {
236+
const fileUri = joinPath(extension.extensionUri, contribution.path);
237+
result.add(fileUri);
238+
}
239+
}
240+
}
241+
}
242+
this._contributedInstructions = result;
243+
}
244+
return this._contributedInstructions;
245+
}
212246
}

0 commit comments

Comments
 (0)