Repository works only when it defined at top level of grammar file
In textmate you can define repositroy within a specific rule and it works fine.
I created this grammar file for test
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>qwe</string>
</array>
<key>name</key>
<string>Qwe</string>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>begin</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.begin.qwe</string>
</dict>
</dict>
<key>end</key>
<string>end</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.end.qwe</string>
</dict>
</dict>
<key>name</key>
<string>meta.begin-end.qwe</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#foo</string>
</dict>
</array>
<key>repository</key>
<dict>
<key>foo</key>
<dict>
<key>match</key>
<string>foo</string>
<key>name</key>
<string>keyword.control.foo.qwe</string>
</dict>
</dict>
</dict>
</array>
<key>scopeName</key>
<string>source.qwe</string>
<key>uuid</key>
<string>06AD8311-7342-4086-843E-BFB83EBC2377</string>
</dict>
</plist>
result in textmate:
result in vscode:

In vscode whole rule stopped working without any error
I have used sub repository several times. My current experience says that it needs to reside in the root element, or directly in other repositories, in order to work, not within any patterns element. It is possible that TextMate allows repository to appear anywhere, but it is not documented.
+1! This was a tough one to debug! 😬
I believe I am running into the same issue. As a reduced test case I defined this simple grammar:
patterns:
- include: "#aaaaaa"
repository:
aaaaaa:
name: meta.definition.operator.swift
begin: abc
end: $
beginCaptures:
0: { name: storage.modifier.swift }
patterns:
- include: "#xxx"
repository:
xxx:
match: def
captures:
0: { name: entity.name.function.operator.swift }
In TextMate this renders as expected:
In VS Code, somehow even the name and beginCaptures are not applied. It's like the whole pattern is being thrown away.
If I change it to:
patterns:
- include: "#aaaaaa"
repository:
aaaaaa:
...
xxx:
...
then it seems to work.
Would you agree this looks like the same issue, or do you think it's a different one?
I would disagree somewhat with the original issue title. Like @msftrncs said, I've had nested repository work in many cases. Yet in some cases, it stops working. I have not determined when it works and when it doesn't. I will probably just abandon nested repositories to avoid a recurrence of this issue.
@jtbandes looks like the very same issue. Rule stops working when you define repository in this rule and include it
@jtbandes also keep in mind another bug
if all includes inside the patterns array cannot be found
then the entire repository item aaaaaa will fail and be skipped
an empty patterns array or having atleast one working include inside it will not cause an error, and allow it to work as expected
Thanks for the info. I've also noticed another bug which is causing some grief: a 2nd match of a group (e.g. via \g<1>) will cancel/override an earlier match:
- match: (AAA)\g<1>
captures:
1: { name: keyword.control }
produces:
This seems related to https://github.com/microsoft/vscode-textmate/issues/164 but I'm not sure it's the same issue.
Also, patterns executed inside a capture group seem to cancel/override scopes from parent groups:
- match: (A(BCD+EF)G)
captures:
1:
name: keyword.control
2:
patterns:
- match: CDE
name: storage.modifier
produces:
@jtbandes
This seems related to #164 but I'm not sure it's the same issue.
it is also the same as https://github.com/microsoft/vscode-textmate/issues/208https://github.com/microsoft/vscode-textmate/issues/208
Also, patterns executed inside a capture group seem to cancel/override scopes from parent groups:
I think there was a work around
you can place name at same level as patterns ~~? or smth~~
~~or only at the same level as the first match~~
~~or maybe just for begin/end rules~~
I found the problem to be; if theres a match or begin at the same level as the nested repository
then VSCode will just ignore the repository
workaround is to nest everything except the repository inside a patterns array
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>qwe</string>
</array>
<key>name</key>
<string>Qwe</string>
<key>patterns</key>
<array>
<dict>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>begin</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.begin.qwe</string>
</dict>
</dict>
<key>end</key>
<string>end</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.end.qwe</string>
</dict>
</dict>
<key>name</key>
<string>meta.begin-end.qwe</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#foo</string>
</dict>
</array>
</dict>
</array>
<key>repository</key>
<dict>
<key>foo</key>
<dict>
<key>match</key>
<string>foo</string>
<key>name</key>
<string>keyword.control.foo.qwe</string>
</dict>
</dict>
</dict>
</array>
<key>scopeName</key>
<string>source.qwe</string>
<key>uuid</key>
<string>06AD8311-7342-4086-843E-BFB83EBC2377</string>
</dict>
</plist>