Skip to content

Commit 2e124f3

Browse files
committed
Add warning for TextMate injection bug
1 parent 05549ab commit 2e124f3

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

documentation/injections.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The injection syntax is parsed into the following tokens
3434

3535
* `L:` - `left` side priority selector `-1` to following the scopeName
3636
* `R:` - `right` side priority selector `1` to following the scopeName
37+
* `B:` - Both `left` and `right` side priority selectors (Github and [TextMate](https://github.com/textmate/textmate/blob/master/Frameworks/scope/src/types.h#L74) only. VSCode doesn't support it)
3738
* __*__`:` - any char followed by `:` colon. Defaults to priority `0` to following the scopeName
3839
* `(` - Open bracket group
3940
* `)` - Close bracket group
@@ -91,3 +92,50 @@ You will need put the injections inside the parent grammar.
9192

9293
TextMate will inject the rules into the entire document.
9394
Including recursively into the injected rules.
95+
96+
### Warning
97+
TextMate 2.0 and Github have a bug where a injected `include` won't be applied if the `include` is already present in the same instance.
98+
Causing `L:` to effectively be ignored.
99+
100+
For example in this grammar:
101+
```json textmate
102+
{
103+
"scopeName": "source.languageId",
104+
"injections": {
105+
"L:source.languageId": {
106+
"patterns": [ { "include": "#any" } ]
107+
}
108+
},
109+
"patterns": [
110+
{ "include": "#abc" },
111+
{ "include": "#any" }
112+
],
113+
"repository": {
114+
"abc": {
115+
"match": "abc",
116+
"name": "string.abc"
117+
},
118+
"any": {
119+
"match": ".",
120+
"name": "comment.any"
121+
},
122+
"any2": {
123+
"match": ".",
124+
"name": "comment.any"
125+
}
126+
}
127+
}
128+
```
129+
It would be expected that this grammar matches the text `abc` with `comment.any`.
130+
But instead it is matched with `string.abc`.
131+
Even tho the injection has high priority `L:`.
132+
TextMate and Github see that `#any` was already included from within the root level `patterns`.
133+
Then proceeding to simply ignore it.
134+
Forgetting that the order/priority of the `include` needs to be changed.
135+
136+
As you will see changing one of the `#any` to `#any2` fixes it.
137+
Also removing `#any` from the root level `patterns` fixes it.
138+
139+
VSCode handles this correctly by not ignoring the duplicate injection `include`.
140+
https://github.com/github-linguist/linguist/discussions/6756
141+
https://github.com/lifeart/vsc-ember-syntax/pull/77

0 commit comments

Comments
 (0)