Sublime Forum

Scope selectors ranking matches - possible bug

#1

In this scope at id attribute in HTML tag:

entity.other.attribute-name.id.html meta-attribute-with-value.id.html meta.tag.block.any.html text.html.basic

scope selector (1): meta.tag entity
wins over scope selector (2): entity.other.attribute-name.id.html

I would argue that by this definition: manual.macromates.com/en/scope_selectors
scope selector (2) should win in step 2, first pass.

I can’t try this in TextMate, but this is how e does it.

1 Like

#2

Yes, I noticed this with theming.

It seems that here, as you described it, level (or depth) of two selectors is equal (second part of (1) and (2)), but first wins because it is descendant selector, although the second one has higher specificity. Descendant selectors resolution in step 3 should get in the picture only when there is a tie, but there is no tie here.

0 Likes

#3

To illustrate, in scope a.b c.d.e.f selector a.b c should lose against

c.d.e.f
c.d.e
c.d

but it should win over c, because of descendancy.

0 Likes

#4

Also, step 3 should be clever about cases like this one:

scope: a.b c.d e.f g.h

and selectors:
a.b c.d e g.h
a.b e.f g.h

0 Likes

#5

This is indeed a bug, I’ve put it on the list of things to fix.

Internally, since selectors form a regular language, sublime transforms them into regexes. To rank selectors vs. a scope, it simply takes the selector with the leftmost longest match. This is an approximation of the TextMate ranking scheme, but it doesn’t always rank in the same way - I’ll need to change the ranking to be done in a per-scope element iterative method.

0 Likes