Skip to content

Commit b2b3389

Browse files
authored
Instruction files - comma separated list of glob patterns not working in applyTo property (microsoft#250754)
* Instruction files - comma separated list of glob patterns not working in applyTo property * use path, not fsPath * fix test
1 parent a089903 commit b2b3389

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

src/vs/workbench/contrib/chat/common/promptSyntax/parsers/promptHeader/metadata/applyTo.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { PromptStringMetadata } from './base/string.js';
77
import { localize } from '../../../../../../../../nls.js';
88
import { INSTRUCTIONS_LANGUAGE_ID } from '../../../constants.js';
9-
import { isEmptyPattern, parse } from '../../../../../../../../base/common/glob.js';
9+
import { isEmptyPattern, parse, splitGlobAware } from '../../../../../../../../base/common/glob.js';
1010
import { PromptMetadataDiagnostic, PromptMetadataError, PromptMetadataWarning } from '../diagnostics.js';
1111
import { FrontMatterRecord, FrontMatterToken } from '../../../../../../../../editor/common/codecs/frontMatterCodec/tokens/index.js';
1212

@@ -85,11 +85,17 @@ export class PromptApplyToMetadata extends PromptStringMetadata {
8585
pattern: string,
8686
): boolean {
8787
try {
88-
const globPattern = parse(pattern);
89-
if (isEmptyPattern(globPattern)) {
88+
const patterns = splitGlobAware(pattern, ',');
89+
if (patterns.length === 0) {
9090
return false;
9191
}
92+
for (const pattern of patterns) {
9293

94+
const globPattern = parse(pattern);
95+
if (isEmptyPattern(globPattern)) {
96+
return false;
97+
}
98+
}
9399
return true;
94100
} catch (_error) {
95101
return false;

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

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { flatten } from '../utils/treeUtils.js';
77
import { localize } from '../../../../../../nls.js';
88
import { PROMPT_LANGUAGE_ID } from '../constants.js';
99
import { PromptParser } from '../parsers/promptParser.js';
10-
import { match } from '../../../../../../base/common/glob.js';
10+
import { match, splitGlobAware } from '../../../../../../base/common/glob.js';
1111
import { pick } from '../../../../../../base/common/arrays.js';
1212
import { type URI } from '../../../../../../base/common/uri.js';
1313
import { type IPromptFileReference } from '../parsers/types.js';
@@ -268,23 +268,38 @@ export class PromptsService extends Disposable implements IPromptsService {
268268
continue;
269269
}
270270

271-
// if glob pattern is one of the special wildcard values,
272-
// add the instructions file event if no files are attached
273-
if ((applyTo === '**') || (applyTo === '**/*')) {
274-
foundFiles.add(uri);
275-
276-
continue;
277-
}
271+
const patterns = splitGlobAware(applyTo, ',');
272+
const patterMatches = (pattern: string) => {
273+
pattern = pattern.trim();
274+
if (pattern.length === 0) {
275+
// if glob pattern is empty, skip it
276+
return false;
277+
}
278+
if (pattern === '**' || pattern === '**/*' || pattern === '*') {
279+
// if glob pattern is one of the special wildcard values,
280+
// add the instructions file event if no files are attached
281+
return true;
282+
}
283+
if (!pattern.startsWith('/') && !pattern.startsWith('**/')) {
284+
// support relative glob patterns, e.g. `src/**/*.js`
285+
pattern = '**/' + pattern;
286+
}
278287

279-
// match each attached file with each glob pattern and
280-
// add the instructions file if its rule matches the file
281-
for (const file of files) {
282-
if (match(applyTo, file.fsPath)) {
283-
foundFiles.add(uri);
288+
// match each attached file with each glob pattern and
289+
// add the instructions file if its rule matches the file
290+
for (const file of files) {
291+
// if the file is not a valid URI, skip it
292+
if (match(pattern, file.path)) {
293+
return true;
294+
}
284295
}
296+
return false;
297+
};
298+
299+
if (patterns.some(patterMatches)) {
300+
foundFiles.add(uri);
285301
}
286302
}
287-
288303
return [...foundFiles];
289304
}
290305

0 commit comments

Comments
 (0)