Why does Copilot Instructions applyTo 'src/**/*.ts' also match 'app/src/testB.component.ts'?
VS Code 1.104.3 with Copilot Chat extension 0.31.5 on Windows 11: I created an instruction file with applyTo: "src//*.ts", but it is also referenced when the opened file is app\src\testB.component.ts. I expected only the file with applyTo: "/*.ts" to match. Why does the pattern match a path that does not start with src, and can I match relative to the workspace root?
Originally asked on GitHub: https://github.com/microsoft/vscode/issues/270160
2 answers
Still open: VS Code confirmed the behavior and the request was moved to the VS Code backlog after receiving enough community upvotes.
A VS Code contributor explained that the applyTo glob is matched as if "/" were prepended to it. So applyTo: "src//.ts" behaves like "/src//.ts" and matches both src/testA.component.ts and app/src/testB.component.ts. In the reported reproduction (Copilot Chat 0.31.5, VS Code 1.104.3, Windows 11), opening app\src\testB.component.ts and running the prompt in Edit mode caused both angular.instructions.md (applyTo "src//*.ts") and typescript.instructions.md (applyTo "/*.ts") to appear in the referenced files. The matching logic is in computeAutomaticInstructions.ts under src/vs/workbench/contrib/chat/common/promptSyntax/.
VS Code currently has no way to specify a full-match pattern relative to the workspace root; the maintainers marked that as a future feature. The thread itself does not contain a workaround. As general advice, after each chat prompt check the referenced-files list to see which instruction files were actually attached, and keep applyTo patterns broad enough that the implicit leading "**/" cannot pick up unintended paths.
Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Reporter created angular.instructions.md with applyTo "src//*.ts" and typescript.instructions.md with applyTo "/.ts", opened app\src\testB.component.ts, and ran the Edit-mode prompt "Does this file follows project's guidelines?" on VS Code 1.104.3 with Copilot Chat 0.31.5 on Windows 11. Both instruction files were listed as referenced files instead of only the "**/.ts" one.
Source: https://github.com/microsoft/vscode/issues/270160 (opens external site)
Did this work for you?