Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injections not applied in grammar that was itself injected #152

Closed
wlach opened this issue Jul 16, 2021 · 4 comments
Closed

Injections not applied in grammar that was itself injected #152

wlach opened this issue Jul 16, 2021 · 4 comments
Assignees

Comments

@wlach
Copy link

wlach commented Jul 16, 2021

(Redirecting from sveltejs/language-tools#1094)

The svelte vscode plugin uses injections to create a set of matching rules to syntax highlight embedded javascript blocks, like the following:

This is a markdown document.

```svelte
<script>
  var x = 1;
</script>
Foo
```

https://github.com/sveltejs/language-tools/blob/89d6c87f410f4465a1ef7c88f28fa0e8c6603bb9/packages/svelte-vscode/syntaxes/svelte.tmLanguage.src.yaml#L18

However, in the case of a svelte component embedded in a markdown file, these injection rules do not seem to be applied (only the rules defined later in the textmate definition) and thus syntax highlighting is not applied correctly. A small patch to the script matching logic to manually add the rule that we were relying on confirms this (by fixing the problem for bare script tags like the one cited above):

diff --git a/packages/svelte-vscode/syntaxes/svelte.tmLanguage.src.yaml b/packages/svelte-vscode/syntaxes/svelte.tmLanguage.src.yaml
index 5a7ebc4..197b69d 100644
--- a/packages/svelte-vscode/syntaxes/svelte.tmLanguage.src.yaml
+++ b/packages/svelte-vscode/syntaxes/svelte.tmLanguage.src.yaml
@@ -502,6 +502,7 @@ repository:
       patterns: [ include: '#tags-lang-start-attributes' ]
     # Fallback to default language.
     - include: '#tags-lang-start-attributes'
+    - patterns: [{begin: '(?<=>)(?!</)', end: '(?=</)', name: meta.embedded.block.svelte, patterns: [{ include: source.js }]}]
 
   # Void element tags. They must be treated separately due to their lack of end nodes.
   # A void element cannot be differentiated from other tags, unless you look at their name.

Is it expected that injections will not be applied inside embedded contexts like these? This seems vaguely similar to #122 which was marked as fixed, though it seems like it might be slightly different. It's also not clear to me if this is an issue with vscode-textmate or vscode's use of it, so feel free to redirect as needed.

It's probably possible to workaround this (to some degree) in the svelte plugin using the pattern above, though I think the code would be longer and less elegant than the injection-based approach (there's also one language extension injection that I'm not sure how to reimplement offhand: https://github.com/sveltejs/language-tools/blob/89d6c87f410f4465a1ef7c88f28fa0e8c6603bb9/packages/svelte-vscode/syntaxes/svelte.tmLanguage.src.yaml#L91).

@alexdima
Copy link
Member

alexdima commented Aug 17, 2021

Writing down the steps I'm taking to troubleshoot this:

  • create test.md
```svelte
<script>
  const x = 3;
</script>
  • create test.svelte
<script>
  const x = 3;
</script>
  • kill code
  • launch code using VSCODE_TEXTMATE_DEBUG=1 code
  • open developer tools
  • open the two files

Output for test.svelte

@@scanNext 0: |<script>\n|
 matched rule id: 20326 from 0 to 7
   pushing t#20326 @ svelte.tmLanguage.json:911 - <(script|style|template)
 
 @@scanNext 0: |<script|
 matched rule id: 20328 from 0 to 7
   scanning for injections
    - 20420: (?<=>)(?!</)
   matched t#20328 @ svelte.tmLanguage.json:873 - (<)([^/\s>/]*)
 
 @@scanNext 1: |script|
 matched rule id: 20339 from 1 to 7
   scanning for injections
    - 20420: (?<=>)(?!</)
   matched t#20339 @ svelte.tmLanguage.json:842 - [a-z][\w0-9:-]*
 
 @@scanNext 7: ||
   scanning for injections
    - 20420: (?<=>)(?!</)
   no more matches.
 
 @@scanNext 7: ||
   scanning for injections
    - 20420: (?<=>)(?!</)
   no more matches.
 
 @@scanNext 7: |>\n|
 matched rule id: 20351 from 7 to 7
   scanning for injections
    - 20420: (?<=>)(?!</)
   pushing t#20351 @ svelte.tmLanguage.json:858 - \G
 
 @@scanNext 7: |>\n|
 matched rule id: -1 from 7 to 8
   scanning for injections
    - 20420: (?<=>)(?!</)
   popping t#20351 @ svelte.tmLanguage.json:858 - (?=/>)|>
 
 @@scanNext 8: |\n|
   scanning for injections
    - 20420: (?<=>)(?!</)
   pushing t#20420 @ svelte.tmLanguage.json:56 - (?<=>)(?!</)
 
 @@scanNext 8: |\n|
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   no more matches.
 
 @@scanNext 0: |  const x = 3;\n|
 matched rule id: 636 from 2 to 2
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   pushing t#636 @ JavaScript.tmLanguage.json:362 - (?=(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))
 
 @@scanNext 2: |const x = 3;\n|
 matched rule id: 640 from 2 to 8
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   pushing t#640 @ JavaScript.tmLanguage.json:378 - (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))\s*
 
 @@scanNext 8: |x = 3;\n|
 matched rule id: -1 from 8 to 8
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   popping t#640 @ JavaScript.tmLanguage.json:378 - (?=\S)
 
 @@scanNext 8: |x = 3;\n|
 matched rule id: 664 from 8 to 9
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   pushing t#664 @ JavaScript.tmLanguage.json:513 - ([_$[:alpha:]][_$[:alnum:]]*)
 
 @@scanNext 9: | = 3;\n|
 matched rule id: -1 from 10 to 10
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   popping t#664 @ JavaScript.tmLanguage.json:513 - (?=$|^|[;,=}]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))
 
 @@scanNext 10: |= 3;\n|
 matched rule id: 531 from 10 to 11
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   pushing t#531 @ JavaScript.tmLanguage.json:1153 - (?<!=|!)(=)(?!=)(?=\s*\S)(?!\s*.*=>\s*$)
 
 @@scanNext 11: | 3;\n|
 matched rule id: 228 from 12 to 13
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   matched t#228 @ JavaScript.tmLanguage.json:3461 - (?x)
(?<!\$)(?:
  (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
  (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
  (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
  (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
  (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
  (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
  (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
  (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
)(?!\$)
 
 @@scanNext 13: |;\n|
 matched rule id: -1 from 13 to 13
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   popping t#531 @ JavaScript.tmLanguage.json:1153 - (?=$|^|[,);}\]]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))
 
 @@scanNext 13: |;\n|
 matched rule id: -1 from 13 to 13
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   popping t#636 @ JavaScript.tmLanguage.json:362 - (?!(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))((?=;|}|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+)|;|^\s*$|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))|((?<!^const|[^\._$[:alnum:]]const)(?=\s*$)))
 
 @@scanNext 13: |;\n|
 matched rule id: 813 from 13 to 14
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   matched t#813 @ JavaScript.tmLanguage.json:4548 - ;
 
 @@scanNext 14: |\n|
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   no more matches.
 
 @@scanNext 0: |</script>\n|
 matched rule id: -1 from 0 to 0
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   popping t#20420 @ svelte.tmLanguage.json:56 - (?=</)
 
 @@scanNext 0: |</script>\n|
 matched rule id: -1 from 0 to 9
   scanning for injections
    - 20420: (?<=>)(?!</)
   popping t#20326 @ svelte.tmLanguage.json:911 - </\1\s*>|/>
 
 @@scanNext 0: |</script>|
 matched rule id: 20343 from 0 to 9
   scanning for injections
    - 20420: (?<=>)(?!</)
   matched t#20343 @ svelte.tmLanguage.json:889 - (</)(.*?)\s*(>)|(/>)
 
 @@scanNext 2: |script|
 matched rule id: 20339 from 2 to 8
   scanning for injections
    - 20420: (?<=>)(?!</)
   matched t#20339 @ svelte.tmLanguage.json:842 - [a-z][\w0-9:-]*
 
 @@scanNext 8: ||
   scanning for injections
    - 20420: (?<=>)(?!</)
   no more matches.
 
 @@scanNext 9: ||
   scanning for injections
    - 20420: (?<=>)(?!</)
   pushing t#20420 @ svelte.tmLanguage.json:56 - (?<=>)(?!</)
 
 @@scanNext 9: ||
   scanning for injections
    - 20482: (?<![_$[:alnum:]])\$(?=[_[:alpha:]][_$[:alnum:]]*)
   - 20483: (?<![_$[:alnum:]])(\$\$)(?=props|restProps|slots)
   no more matches.
 
 @@scanNext 9: |\n|
 matched rule id: 20411 from 9 to 9
   pushing t#20411 @ svelte.tmLanguage.json:235 - (?<=>|})
 
 @@scanNext 9: |\n|
   no more matches.
 
 @@scanNext 0: |\n|
   no more matches.

Output for test.md
 
 @@scanNext 0: |```svelte\n|
 matched rule id: 20708 from 0 to 3
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   pushing t#20748 @ markdown-svelte.json:11 - (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
 
 @@scanNext 10: ||
 matched rule id: 20753 from 10 to 10
   scanning for injections
    - 20748: (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   pushing t#20753 @ markdown-svelte.json:32
 
 @@scanNext 10: ||
   scanning for injections
    - 20748: (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   no more matches.
   scanning for while rule
    - -2: (^|\G)(?!\s*([`~]{3,})\s*$)
 
 @@scanNext 0: |<script>\n|
 matched rule id: 20817 from 0 to 7
   scanning for injections
    - 20748: (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   pushing t#20817 @ svelte.tmLanguage.json:911 - <(script|style|template)
 
 @@scanNext 0: |<script|
 matched rule id: 20819 from 0 to 7
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   matched t#20819 @ svelte.tmLanguage.json:873 - (<)([^/\s>/]*)
 
 @@scanNext 1: |script|
 matched rule id: 20830 from 1 to 7
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   matched t#20830 @ svelte.tmLanguage.json:842 - [a-z][\w0-9:-]*
 
 @@scanNext 7: ||
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   no more matches.
 
 @@scanNext 7: ||
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   no more matches.
 
 @@scanNext 7: |>\n|
 matched rule id: 20842 from 7 to 7
   scanning for injections
    - 20748: (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   pushing t#20842 @ svelte.tmLanguage.json:858 - \G
 
 @@scanNext 7: |>\n|
 matched rule id: -1 from 7 to 8
   scanning for injections
    - 20748: (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   popping t#20842 @ svelte.tmLanguage.json:858 - (?=/>)|>
 
 @@scanNext 8: |\n|
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   no more matches.
   scanning for while rule
    - -2: (^|\�)(?!\s*([`~]{3,})\s*$)
 
 @@scanNext 0: |  const x = 3;\n|
 matched rule id: 20842 from 0 to 0
   scanning for injections
    - 20748: (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   pushing t#20842 @ svelte.tmLanguage.json:858 - \G
 
 @@scanNext 0: |  const x = 3;\n|
 matched rule id: 20883 from 2 to 7
   scanning for injections
    - 20748: (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   pushing t#20883 @ svelte.tmLanguage.json:624 - ([_$[:alpha:]][_\-$[:alnum:]]*)
 
 @@scanNext 7: | x = 3;\n|
 matched rule id: -1 from 7 to 7
   scanning for injections
    - 20748: (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   popping t#20883 @ svelte.tmLanguage.json:624 - (?=\s*+[^=\s])
 
 @@scanNext 7: | x = 3;\n|
 matched rule id: 20883 from 8 to 9
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   pushing t#20883 @ svelte.tmLanguage.json:624 - ([_$[:alpha:]][_\-$[:alnum:]]*)
 
 @@scanNext 9: | = 3;\n|
 matched rule id: 20871 from 10 to 11
   scanning for injections
    - 20748: (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   pushing t#20871 @ svelte.tmLanguage.json:639 - =
 
 @@scanNext 11: | 3;\n|
 matched rule id: 20879 from 12 to 14
   scanning for injections
    - 20748: (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   matched t#20879 @ svelte.tmLanguage.json:660 - ([^\s"'=<>`/]|/(?!>))+
 
 @@scanNext 14: |\n|
 matched rule id: -1 from 14 to 14
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   popping t#20871 @ svelte.tmLanguage.json:639 - (?<=[^\s=])(?!\s*=)|(?=/?>)
 
 @@scanNext 14: |\n|
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   no more matches.
   scanning for while rule
    - -2: (^|\�)(?!\s*([`~]{3,})\s*$)
 
 @@scanNext 0: |</script>\n|
 matched rule id: -1 from 0 to 0
   scanning for injections
    - 20748: (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   popping t#20883 @ svelte.tmLanguage.json:624 - (?=\s*+[^=\s])
 
 @@scanNext 0: |</script>\n|
 matched rule id: 20883 from 2 to 8
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   pushing t#20883 @ svelte.tmLanguage.json:624 - ([_$[:alpha:]][_\-$[:alnum:]]*)
 
 @@scanNext 8: |>\n|
 matched rule id: -1 from 8 to 8
   scanning for injections
    - 20748: (^|\G)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   popping t#20883 @ svelte.tmLanguage.json:624 - (?=\s*+[^=\s])
 
 @@scanNext 8: |>\n|
 matched rule id: -1 from 8 to 9
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   popping t#20842 @ svelte.tmLanguage.json:858 - (?=/>)|>
 
 @@scanNext 9: |\n|
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   no more matches.
   scanning for while rule
    - -2: (^|\�)(?!\s*([`~]{3,})\s*$)
   popping t#20753 @ markdown-svelte.json:32 - (^|\G)(?!\s*([`~]{3,})\s*$)
 
 @@scanNext 0: |```\n|
 matched rule id: -1 from 0 to 4
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   popping t#20748 @ markdown-svelte.json:11 - (^|\G)(\2|\s{0,3})(\3)\s*$
 
 @@scanNext 4: ||
   scanning for injections
    - 20748: (^|\�)(\s*)(\`{3,}|~{3,})\s*(?i:(svelte|sv)(\s+[^`~]*)?$)
   no more matches.

The first real diff appears at the end of <script>, where for .svelte (left side) an injection is matching:

image

Actually, the logging is incomplete, each produced token should be printed to console.log. Investigating...

@alexdima
Copy link
Member

alexdima commented Aug 18, 2021

After more logging, it looks like source.svelte ends up with different injections than text.html.markdown:

Grammar source.svelte contains the following injections:
   - L:meta.script.svelte meta.lang.javascript - (meta source)
   - L:meta.script.svelte (meta.lang.ts | meta.lang.typescript) - (meta source)
   - L:meta.script.svelte meta.lang.coffee - (meta source)
   - L:meta.script.svelte - meta.lang - (meta source)
   - L:meta.style.svelte meta.lang.stylus - (meta source)
   - L:meta.style.svelte meta.lang.sass - (meta source)
   - L:meta.style.svelte meta.lang.css - (meta source)
   - L:meta.style.svelte meta.lang.scss - (meta source)
   - L:meta.style.svelte meta.lang.less - (meta source)
   - L:meta.style.svelte meta.lang.postcss - (meta source)
   - L:meta.style.svelte - meta.lang - (meta source)
   - L:meta.template.svelte meta.lang.pug - (meta source)
   - L:meta.template.svelte - meta.lang - (meta source)
   - L:(source.ts, source.js, source.coffee)
   - L:text.pug -meta.embedded.ts -meta.tag.other -text.block.pug, L:inline.pug -meta.embedded.ts -meta.tag.other
   - L:text.pug -meta.embedded.ts -meta.tag.other -text.block.pug, L:inline.pug -meta.embedded.ts -meta.tag.other
   - L:text.pug meta.tag.other -meta.embedded.ts
   - L:text.block.pug -meta.embedded.ts

Grammar text.html.markdown contains the following injections:
​   - L:text.pug -meta.embedded.ts -meta.tag.other -text.block.pug, L:inline.pug -meta.embedded.ts -meta.tag.other
​   - L:text.pug -meta.embedded.ts -meta.tag.other -text.block.pug, L:inline.pug -meta.embedded.ts -meta.tag.other
​   - L:text.pug meta.tag.other -meta.embedded.ts
​   - L:text.block.pug -meta.embedded.ts
​   - L:text.html.markdown

@alexdima
Copy link
Member

I think I have now a better understanding of what is going on. The source.svelte grammar has injections here. These injections are taken into account when creating the source.svelte grammar for .svelte files, but they are ignored when creating the text.html.markdown grammar for .md files. That is because injections are not recursively collected.

I have tried changing vscode-textmate to recursively collect all injections from all included grammars. This change effectively makes all existing grammar injections become global.

But that is dangerous because there might be many injections which are not prepared to become active in all the places where their grammar is included. This change even ends up breaking an integration test in vscode. For example, a colorization test fails for Razor because this injection is now included in the Razor grammar.

I think that any change in behavior here should be opt-in.

@alexdima alexdima self-assigned this Aug 18, 2021
@alexdima alexdima added this to the August 2021 milestone Aug 18, 2021
@alexdima
Copy link
Member

After further analysis, we have found that TextMate also does not honor injections from included grammars. Given we don't want to deviate from TextMate, we will not add support for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants