Skip to content

Commit 8951f2c

Browse files
authored
Merge pull request microsoft#261704 from j3iiifn/fix/prompt-filename-with-digits
Prompt file name cannot contain digits
2 parents 7173613 + 2f77b57 commit 8951f2c

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
@@ -183,6 +183,25 @@ suite('ChatRequestParser', () => {
183183
await assertSnapshot(result);
184184
});
185185

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

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

0 commit comments

Comments
 (0)