Skip to content

child operator for scope selectors #6741

@deathaxe

Description

@deathaxe

Problem description

Currently available scope selector operators are not sufficient to target tokens of a certain nesting level.

Considder an expression of nested python tuples (meta.sequence.tuple) and sets meta.set with commas being scoped punctuation.separator.sequence:

(a,b,{(c,d),(e,{(f,g),(h,i)})})

A color scheme or plugin wants to ONLY match commas in tuples, but NOT those from sets.

All current operators take all following scopes into account regardless how many other scopes are in between. Hence without detailed information or knowledge about possibly involved meta scopes, it is barely possible to write selectors which target tokens of certain nesting level. In cases it is possible quite sophisticated selectors are required.

A prominent recent example may be mapping key color schemes (see: #6670).

With an child operator at hand required selector to match keys correctly would be as simple as

    {
        "name": "String Key",
        "scope": "meta.mapping.key > string",
        "foreground": "var(blue5)",
    },

forwarded from: https://forum.sublimetext.com/t/add-implement-child-operator-for-sublime-selectors/76725

Preferred solution

Implement a child selector operator which works like CSS/Child_combinator.

A selector meta.sequence.tuple > punctuation.separator.sequence would only match tokens scoped punctuation.separator.sequence if they are a direct child of a meta.sequence.tuple:

(a,b,{(c,d),(e,{(f,g),(h,i)})})
# ^ ^   ^     ^   ^     ^ matching commas

And meta.set > punctuation.separator.sequence matches:

(a,b,{(c,d),(e,{(f,g),(h,i)})})
#          ^         ^   matching commas

Alternatives

Keep DX at current level.

Additional Information

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions