michaelgmcd / vscode-language-babel

VSCode syntax highlighting for today's JavaScript
https://marketplace.visualstudio.com/items?itemName=mgmcdermott.vscode-language-babel
MIT License
131 stars 17 forks source link

Injecting new grammar on top of vscode-language-babel issue #69

Open akalajzi opened 4 years ago

akalajzi commented 4 years ago

Describe the issue

I'm writing a theme built on top of vscode-language-babel, and want to inject some specific tokens (ie, react hooks etc). I've tested my extension and code against native reactjavascript/javascript language, and it works as expected; however with this extension active (which I'd like to have as its way better than native), I cannot seem to hook onto almost nothing apart from comments. Ie, I'd like inject into scope entity.name.function and it just doesnt register.

Is there a way to do this?

Sample Code to Reproduce

{
  "scopeName": "ak.injection",
  "injectionSelector": "L:entity.name.function",
  "patterns": [
    {
      "include": "#hooks"
    }
  ],
  "repository": {
    "hooks": {
      "name": "extra.hook",
      "match": "(?<!\\w)(use\\w+)"
    }
  }
}

package.json snippet:

"contributes": {
...
    "grammars": [
      {
        "path": "./syntaxes/hooks.json",
        "scopeName": "ak.injection",
        "injectTo": [
          "source.js",
          "source.js.jsx",
          "source.jsx"
        ]
      }
    ]
  }

Screenshot of Current Behavior

It doesn't pick up injection:

fn_hook

Screenshot of Expected Behavior

However it does pick it up in comment block if I inject into meta.function.arrow. This is how I'd expect it to behave if I could inject into entity.name.function scope.

comment_useData