Skip to content

Commit c000fcb

Browse files
committed
Prompt file name cannot contain digits
1 parent 98cdb63 commit c000fcb

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/vs/workbench/contrib/chat/common/chatRequestParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { IPromptsService } from './promptSyntax/service/promptsService.js';
1616

1717
const agentReg = /^@([\w_\-\.]+)(?=(\s|$|\b))/i; // An @-agent
1818
const variableReg = /^#([\w_\-]+)(:\d+)?(?=(\s|$|\b))/i; // A #-variable with an optional numeric : arg (@response:2)
19-
const slashReg = /^\/([\p{L}_\-\.:]+)(?=(\s|$|\b))/iu; // A / command
19+
const slashReg = /^\/([\p{L}\d_\-\.:]+)(?=(\s|$|\b))/iu; // A / command
2020

2121
export interface IChatParserContext {
2222
/** Used only as a disambiguator, when the query references an agent that has a duplicate with the same name. */
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
parts: [
3+
{
4+
range: {
5+
start: 0,
6+
endExclusive: 11
7+
},
8+
editorRange: {
9+
startLineNumber: 1,
10+
startColumn: 1,
11+
endLineNumber: 1,
12+
endColumn: 12
13+
},
14+
slashPromptCommand: { command: "001-sample" },
15+
kind: "prompt"
16+
},
17+
{
18+
range: {
19+
start: 11,
20+
endExclusive: 26
21+
},
22+
editorRange: {
23+
startLineNumber: 1,
24+
startColumn: 12,
25+
endLineNumber: 1,
26+
endColumn: 27
27+
},
28+
text: " this is a test",
29+
kind: "text"
30+
}
31+
],
32+
text: "/001-sample this is a test"
33+
}

src/vs/workbench/contrib/chat/test/common/chatRequestParser.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,25 @@ suite('ChatRequestParser', () => {
184184
await assertSnapshot(result);
185185
});
186186

187+
test('prompt slash command with numbers', async () => {
188+
const slashCommandService = mockObject<IChatSlashCommandService>()({});
189+
slashCommandService.getCommands.returns([{ command: 'fix' }]);
190+
instantiationService.stub(IChatSlashCommandService, slashCommandService as any);
191+
192+
const promptSlashCommandService = mockObject<IPromptsService>()({});
193+
promptSlashCommandService.asPromptSlashCommand.callsFake((command: string) => {
194+
if (command.match(/^[\w_\-\.]+$/)) {
195+
return { command };
196+
}
197+
return undefined;
198+
});
199+
instantiationService.stub(IPromptsService, promptSlashCommandService as any);
200+
201+
parser = instantiationService.createInstance(ChatRequestParser);
202+
const text = '/001-sample this is a test';
203+
const result = parser.parseChatRequest('1', text);
204+
await assertSnapshot(result);
205+
});
187206

188207
// test('variables', async () => {
189208
// varService.hasVariable.returns(true);

0 commit comments

Comments
 (0)