6
6
import type * as vscode from 'vscode' ;
7
7
import { createServiceIdentifier } from '../../../util/common/services' ;
8
8
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' ;
9
11
import { Schemas } from '../../../util/vs/base/common/network' ;
10
12
import { dirname , isAbsolute } from '../../../util/vs/base/common/path' ;
11
13
import { joinPath } from '../../../util/vs/base/common/resources' ;
@@ -14,6 +16,7 @@ import { URI } from '../../../util/vs/base/common/uri';
14
16
import { FileType , Uri } from '../../../vscodeTypes' ;
15
17
import { CodeGenerationImportInstruction , CodeGenerationTextInstruction , Config , ConfigKey , IConfigurationService } from '../../configuration/common/configurationService' ;
16
18
import { IEnvService } from '../../env/common/envService' ;
19
+ import { IExtensionsService } from '../../extensions/common/extensionsService' ;
17
20
import { IFileSystemService } from '../../filesystem/common/fileSystemService' ;
18
21
import { ILogService } from '../../log/common/logService' ;
19
22
import { IPromptPathRepresentationService } from '../../prompts/common/promptPathRepresentationService' ;
@@ -74,18 +77,25 @@ const INSTRUCTIONS_LOCATION_KEY = 'chat.instructionsFilesLocations';
74
77
const COPILOT_INSTRUCTIONS_PATH = '.github/copilot-instructions.md' ;
75
78
76
79
77
- export class CustomInstructionsService implements ICustomInstructionsService {
80
+ export class CustomInstructionsService extends Disposable implements ICustomInstructionsService {
78
81
79
82
readonly _serviceBrand : undefined ;
80
83
84
+ private _contributedInstructions : ResourceSet | undefined ;
85
+
81
86
constructor (
82
87
@IConfigurationService private readonly configurationService : IConfigurationService ,
83
88
@IEnvService private readonly envService : IEnvService ,
84
89
@IWorkspaceService private readonly workspaceService : IWorkspaceService ,
85
90
@IFileSystemService private readonly fileSystemService : IFileSystemService ,
86
91
@IPromptPathRepresentationService private readonly promptPathRepresentationService : IPromptPathRepresentationService ,
87
92
@ILogService private readonly logService : ILogService ,
93
+ @IExtensionsService private readonly extensionService : IExtensionsService ,
88
94
) {
95
+ super ( ) ;
96
+ this . _register ( this . extensionService . onDidChange ( ( ) => {
97
+ this . _contributedInstructions = undefined ;
98
+ } ) ) ;
89
99
}
90
100
91
101
public async fetchInstructionsFromFile ( fileUri : Uri ) : Promise < ICustomInstructions | undefined > {
@@ -188,6 +198,10 @@ export class CustomInstructionsService implements ICustomInstructionsService {
188
198
if ( uri . scheme === Schemas . vscodeUserData ) {
189
199
return true ;
190
200
}
201
+ if ( this . getInstructionURLFromExtensionPoint ( ) . has ( uri ) ) {
202
+ return true ;
203
+ }
204
+
191
205
if ( uri . scheme !== Schemas . file ) {
192
206
return false ;
193
207
}
@@ -209,4 +223,24 @@ export class CustomInstructionsService implements ICustomInstructionsService {
209
223
}
210
224
return true ;
211
225
}
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
+ }
212
246
}
0 commit comments