Jeaper
Jeaper

Reputation: 111

Multi scope selection for textMateRules

Trying to make the move from webstorm to vscode.

Im trying to figure out how to target textMateRules more accurately. Specifically demanding more than one scope match.

I read somewhere that you did it like this, but it gets overwritten by the default entity.name.function.

"scope": [
          "entity.name.function meta.method.declaration"
        ],

Any help appriciated.

Upvotes: 3

Views: 1835

Answers (3)

Tom F.
Tom F.

Reputation: 153

It looks like you have to use the textmate scopes from the inspector in the opposite order (from bottom to top).

For example, I tried to apply my rule to array keyword followed by a round bracket (PHP). The scope inspector showed the scopes in this order:

    support.function.construct.php
    meta.array.php
    meta.function-call.php
    source.php
    meta.embedded.block.php
    text.html.php

Like this:

Scope inspector with selected array keyword followed by a round bracket

I took the first two and reversed the order in my settings.json file like this. In the screenshot above you can see that the rule is already applied.

{
    "scope": "meta.array.php support.function.construct.php"
    "settings": {
        "foreground": "#000ba3",
        "fontStyle": "bold"
    }
}

Upvotes: 1

Mykola
Mykola

Reputation: 121

In my VS Code (1.63.2) for multiple scopes I use this code:

"scope": [
    "entity.name.function",
    "meta.method.declaration"
],

Upvotes: 1

Jeaper
Jeaper

Reputation: 111

I had not realized ordering was important.

"scope": [
          "meta.method.declaration entity.name.function"
        ],

Did the trick.

Upvotes: 8

Related Questions