Skip to content

Commit 943fafb

Browse files
authored
add missing prompt enablement setting checks, add logging (microsoft#251633)
add missing promptEnebled setting checks, add logging
1 parent 24c0ff1 commit 943fafb

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

src/vs/workbench/contrib/chat/browser/promptSyntax/attachInstructionsAction.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ class ManageInstructionsFilesAction extends Action2 {
148148
category: CHAT_CATEGORY,
149149
menu: {
150150
id: MenuId.ViewTitle,
151-
152-
when: ContextKeyExpr.equals('view', ChatViewId),
151+
when: ContextKeyExpr.and(PromptsConfig.enabledCtx, ChatContextKeys.enabled, ContextKeyExpr.equals('view', ChatViewId)),
153152
order: 11,
154153
group: '2_manage'
155154
},

src/vs/workbench/contrib/chat/browser/promptSyntax/chatModeActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ManageModeAction extends Action2 {
3838
when: ChatContextKeys.Modes.hasCustomChatModes
3939
}, {
4040
id: MenuId.ViewTitle,
41-
when: ContextKeyExpr.equals('view', ChatViewId),
41+
when: ContextKeyExpr.and(PromptsConfig.enabledCtx, ChatContextKeys.enabled, ContextKeyExpr.equals('view', ChatViewId)),
4242
order: 12,
4343
group: '2_manage'
4444
}

src/vs/workbench/contrib/chat/browser/promptSyntax/runPromptAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class ManagePromptFilesAction extends Action2 {
251251
category: CHAT_CATEGORY,
252252
menu: {
253253
id: MenuId.ViewTitle,
254-
when: ContextKeyExpr.equals('view', ChatViewId),
254+
when: ContextKeyExpr.and(PromptsConfig.enabledCtx, ChatContextKeys.enabled, ContextKeyExpr.equals('view', ChatViewId)),
255255
order: 10,
256256
group: '2_manage'
257257
},

src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsServiceImpl.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { localize } from '../../../../../../nls.js';
7-
import { getPromptsTypeForLanguageId, isValidPromptType, PROMPT_LANGUAGE_ID, PromptsType } from '../promptTypes.js';
7+
import { getPromptsTypeForLanguageId, PROMPT_LANGUAGE_ID, PromptsType } from '../promptTypes.js';
88
import { PromptParser } from '../parsers/promptParser.js';
99
import { match, splitGlobAware } from '../../../../../../base/common/glob.js';
1010
import { type URI } from '../../../../../../base/common/uri.js';
@@ -27,6 +27,8 @@ import { IUserDataProfileService } from '../../../../../services/userDataProfile
2727
import type { IChatPromptSlashCommand, ICustomChatMode, IMetadata, IPromptParserResult, IPromptPath, IPromptsService, TPromptsStorage } from './promptsService.js';
2828
import { getCleanPromptName, PROMPT_FILE_EXTENSION } from '../config/promptFileLocations.js';
2929
import { ILanguageService } from '../../../../../../editor/common/languages/language.js';
30+
import { PromptsConfig } from '../config/config.js';
31+
import { IConfigurationService } from '../../../../../../platform/configuration/common/configuration.js';
3032

3133
/**
3234
* Provides prompt services.
@@ -57,6 +59,7 @@ export class PromptsService extends Disposable implements IPromptsService {
5759
@IInstantiationService private readonly instantiationService: IInstantiationService,
5860
@IUserDataProfileService private readonly userDataService: IUserDataProfileService,
5961
@ILanguageService private readonly languageService: ILanguageService,
62+
@IConfigurationService private readonly configurationService: IConfigurationService,
6063
) {
6164
super();
6265

@@ -126,6 +129,10 @@ export class PromptsService extends Disposable implements IPromptsService {
126129
}
127130

128131
public async listPromptFiles(type: PromptsType, token: CancellationToken): Promise<readonly IPromptPath[]> {
132+
if (!PromptsConfig.enabled(this.configurationService)) {
133+
return [];
134+
}
135+
129136
const prompts = await Promise.all([
130137
this.fileLocator.listFiles(type, 'user', token)
131138
.then(withType('user', type)),
@@ -137,9 +144,9 @@ export class PromptsService extends Disposable implements IPromptsService {
137144
}
138145

139146
public getSourceFolders(type: PromptsType): readonly IPromptPath[] {
140-
// sanity check to make sure we don't miss a new
141-
// prompt type that could be added in the future
142-
assert(isValidPromptType(type), `Unknown prompt type '${type}'.`);
147+
if (!PromptsConfig.enabled(this.configurationService)) {
148+
return [];
149+
}
143150

144151
const result: IPromptPath[] = [];
145152

@@ -258,20 +265,25 @@ export class PromptsService extends Disposable implements IPromptsService {
258265
public async findInstructionFilesFor(files: readonly URI[], ignoreInstructions?: ResourceSet): Promise<readonly { uri: URI; reason: string }[]> {
259266
const instructionFiles = await this.listPromptFiles(PromptsType.instructions, CancellationToken.None);
260267
if (instructionFiles.length === 0) {
268+
this.logger.trace('[PromptsService#findInstructionFilesFor] No instruction files available.');
261269
return [];
262270
}
271+
this.logger.trace(`[PromptsService#findInstructionFilesFor] ${files.length} input files provided. ${files.map(file => file.toString()).join(', ')}`);
272+
this.logger.trace(`[PromptsService#findInstructionFilesFor] ${instructionFiles.length} instruction files available.`);
263273

264274
const result: { uri: URI; reason: string }[] = [];
265275
const foundFiles = new ResourceSet();
266276
for (const instructionFile of instructionFiles) {
267277
const { metadata, uri } = await this.parse(instructionFile.uri, CancellationToken.None);
268278

269279
if (metadata?.promptType !== PromptsType.instructions) {
280+
this.logger.trace(`[PromptsService#findInstructionFilesFor] Not an instruction file: ${uri}`);
270281
continue;
271282
}
272283

273284
if (ignoreInstructions?.has(uri) || foundFiles.has(uri)) {
274285
// the instruction file is already part of the input or has already been processed
286+
this.logger.trace(`[PromptsService#findInstructionFilesFor] Skipping already processed instruction file: ${uri}`);
275287
continue;
276288
}
277289

@@ -310,6 +322,7 @@ export class PromptsService extends Disposable implements IPromptsService {
310322
};
311323

312324

325+
let matches = false;
313326
for (const pattern of patterns) {
314327
const matchResult = patterMatches(pattern);
315328
if (matchResult !== false) {
@@ -319,11 +332,14 @@ export class PromptsService extends Disposable implements IPromptsService {
319332

320333
result.push({ uri, reason });
321334
foundFiles.add(uri);
335+
this.logger.trace(`[PromptsService#findInstructionFilesFor] ${uri} selected: ${reason}`);
336+
matches = true;
322337
break;
323338
}
324339
}
325-
326-
340+
if (!matches) {
341+
this.logger.trace(`[PromptsService#findInstructionFilesFor] ${uri} no match: pattern: ${applyTo}`);
342+
}
327343
}
328344
return result;
329345
}

0 commit comments

Comments
 (0)