atom / first-mate

TextMate helpers
http://atom.github.io/first-mate
MIT License
91 stars 57 forks source link

Injection grammars using the 'injections' property not working. #102

Closed gandm closed 6 years ago

gandm commented 6 years ago

Injection grammars work if using injectionSelector but not if using injections

It appears grammars are only added as injection grammars if they have the injectionSelector property (first example below) which makes no sense inside a nested set of injections as that property doesn't exist (second example below). Atom adds grammars as Injection grammars here and are only used as rules if they are marked as such here e.g. This works

{
  "scopeName": "working.injector",
  "injectionSelector": "L:source.js.embedded.html",
  "patterns": [
    { "include": "source.js.jsx" }
  ]
}

This doesn't

{
  "scopeName": "some.injector",
  "injections": {
    "L:source.js.embedded.html": {
      "patterns": [
        { "include": "source.js.jsx" }
      ]
    }
  }
}
50Wliu commented 6 years ago

@gandm I might need a bit more background. As far as I know, injection selectors are not meant to be actual grammars that you can select using the Grammar Selector. They're more for auxiliary highlighting (like language-todo). Injection grammars are meant to be selected and need to provide the scopes that they inject in themselves (language-php).

gandm commented 6 years ago

As far as I can see language-php doesn't work either. It has an injection here that should inject some patterns and eventually the PHP grammar into a scope L:source.js.embedded.html as a LEFT rule set. So an html file using language-html with a <?php inside a <script> and </script> which has a scope of source.js.embedded.html should highlight as PHP but it doesn't.

I've disabled language-javascript to stop it parsing any source.js code inside an html file as shown in the image below. PHP isn't highlighted at all which it should be if the above injection of rules was working. image

50Wliu commented 6 years ago

injections injects into itself, injectionSelector injects into other grammars. So PHP needs to be the active grammar in order for PHP highlighting to work, while TODO doesn't.

gandm commented 6 years ago

Still doesn't work?

image

50Wliu commented 6 years ago

What Atom version are you using?

gandm commented 6 years ago

Atom 1.21.1

gandm commented 6 years ago

Putting a space in front of the <?php works. Must be an issue with the inject regex patterns in language-php rather than the injection.

I'll close this as it appears to work as designed.