refactor config constants of reusable prompts

This commit is contained in:
Oleg Solomko
2025-03-21 16:49:30 -07:00
parent fb6d926e64
commit f8458a26ca
5 changed files with 28 additions and 24 deletions

View File

@@ -4,7 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import { ContextKeyExpr } from '../../contextkey/common/contextkey.js';
import { IConfigurationService } from '../../configuration/common/configuration.js';
import type { IConfigurationService } from '../../configuration/common/configuration.js';
import { CONFIG_KEY, DEFAULT_SOURCE_FOLDER, LOCATIONS_CONFIG_KEY } from './constants.js';
/**
* Configuration helper for the `reusable prompts` feature.
@@ -27,21 +28,8 @@ import { IConfigurationService } from '../../configuration/common/configuration.
* - current root folder (if a single folder is open)
*/
export namespace PromptsConfig {
/**
* Configuration key for the `reusable prompts` feature
* (also known as `prompt files`, `prompt instructions`, etc.).
*/
export const CONFIG_KEY: string = 'chat.promptFiles';
/**
* Configuration key for the locations of reusable prompt files.
*/
export const LOCATIONS_CONFIG_KEY: string = 'chat.promptFilesLocations';
/**
* Default reusable prompt files source folder.
*/
export const DEFAULT_SOURCE_FOLDER = '.github/prompts';
export const KEY = CONFIG_KEY;
export const LOCATIONS_KEY = LOCATIONS_CONFIG_KEY;
/**
* Checks if the feature is enabled.

View File

@@ -17,6 +17,22 @@ export const PROMPT_FILE_EXTENSION = '.prompt.md';
*/
export const COPILOT_CUSTOM_INSTRUCTIONS_FILENAME = 'copilot-instructions.md';
/**
* Configuration key for the `reusable prompts` feature
* (also known as `prompt files`, `prompt instructions`, etc.).
*/
export const CONFIG_KEY: string = 'chat.promptFiles';
/**
* Configuration key for the locations of reusable prompt files.
*/
export const LOCATIONS_CONFIG_KEY: string = 'chat.promptFilesLocations';
/**
* Default reusable prompt files source folder.
*/
export const DEFAULT_SOURCE_FOLDER = '.github/prompts';
/**
* Check if provided path is a reusable prompt file.
*/

View File

@@ -22,7 +22,7 @@ const createMock = <T>(value: T): IConfigurationService => {
);
assert(
[PromptsConfig.CONFIG_KEY, PromptsConfig.LOCATIONS_CONFIG_KEY].includes(key),
[PromptsConfig.KEY, PromptsConfig.LOCATIONS_KEY].includes(key),
`Unsupported configuration key '${key}'.`,
);

View File

@@ -21,7 +21,7 @@ import { IInstantiationService } from '../../../../platform/instantiation/common
import product from '../../../../platform/product/common/product.js';
import { IProductService } from '../../../../platform/product/common/productService.js';
import { PromptsConfig } from '../../../../platform/prompts/common/config.js';
import { PROMPT_FILE_EXTENSION } from '../../../../platform/prompts/common/constants.js';
import { DEFAULT_SOURCE_FOLDER as PROMPT_FILES_DEFAULT_SOURCE_FOLDER, PROMPT_FILE_EXTENSION } from '../../../../platform/prompts/common/constants.js';
import { Registry } from '../../../../platform/registry/common/platform.js';
import { EditorPaneDescriptor, IEditorPaneRegistry } from '../../../browser/editor.js';
import { Extensions, IConfigurationMigrationRegistry } from '../../../common/configuration.js';
@@ -247,7 +247,7 @@ configurationRegistry.registerConfiguration({
default: false,
markdownDescription: nls.localize('mpc.discovery.enabled', "Configures discovery of Model Context Protocol servers on the machine. It may be set to `true` or `false` to disable or enable all sources, and an array of sources you wish to enable."),
},
[PromptsConfig.CONFIG_KEY]: {
[PromptsConfig.KEY]: {
type: 'boolean',
title: nls.localize(
'chat.reusablePrompts.config.enabled.title',
@@ -264,7 +264,7 @@ configurationRegistry.registerConfiguration({
disallowConfigurationDefault: true,
tags: ['experimental', 'prompts', 'reusable prompts', 'prompt snippets', 'instructions'],
},
[PromptsConfig.LOCATIONS_CONFIG_KEY]: {
[PromptsConfig.LOCATIONS_KEY]: {
type: 'object',
title: nls.localize(
'chat.reusablePrompts.config.locations.title',
@@ -277,7 +277,7 @@ configurationRegistry.registerConfiguration({
DOCUMENTATION_URL,
),
default: {
[PromptsConfig.DEFAULT_SOURCE_FOLDER]: true,
[PROMPT_FILES_DEFAULT_SOURCE_FOLDER]: true,
},
additionalProperties: { type: 'boolean' },
unevaluatedProperties: { type: 'boolean' },
@@ -285,10 +285,10 @@ configurationRegistry.registerConfiguration({
tags: ['experimental', 'prompts', 'reusable prompts', 'prompt snippets', 'instructions'],
examples: [
{
[PromptsConfig.DEFAULT_SOURCE_FOLDER]: true,
[PROMPT_FILES_DEFAULT_SOURCE_FOLDER]: true,
},
{
[PromptsConfig.DEFAULT_SOURCE_FOLDER]: true,
[PROMPT_FILES_DEFAULT_SOURCE_FOLDER]: true,
'/Users/vscode/repos/prompts': true,
},
],

View File

@@ -33,7 +33,7 @@ const mockConfigService = <T>(value: T): IConfigurationService => {
);
assert(
[PromptsConfig.CONFIG_KEY, PromptsConfig.LOCATIONS_CONFIG_KEY].includes(key),
[PromptsConfig.KEY, PromptsConfig.LOCATIONS_KEY].includes(key),
`Unsupported configuration key '${key}'.`,
);