Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example for scoring scope selectors #132

Closed
wants to merge 3 commits into from

Conversation

keith-hall
Copy link
Collaborator

This PR adds an example for scoring scope selectors, to make it easier to debug color schemes etc. when multiple selectors match a scope stack, and we want to see which selector has a higher precedence/score.

@keith-hall
Copy link
Collaborator Author

Example use: cargo run --example score_selector "text.plain" "text"
Output:

Scoring selector "text" against scope stack [<text.plain>]...
MatchPower(1)

or cargo run --example score_selector -- "source.rust comment.line.documentation.rust" "-comment"

Scoring selector "-comment" against scope stack [<source.rust>, <comment.line.documentation.rust>]...
The selector does not match the scope stack.

@keith-hall
Copy link
Collaborator Author

this also addresses a bug whereby syntect wasn't scoring the best match when the scope stack contained multiple scopes whose prefixes would match a scope in the selector. As mentioned at https://manual.macromates.com/en/scope_selectors#ranking_matches, deeper scopes should give higher scores, but in syntect's previous implementation, it would work from left to right and so it would match a scope less deep and score that, rather than looking for the deepest matching scope. (Note that Sublime is also affected by this, see sublimehq/sublime_text#2152.)

@trishume
Copy link
Owner

Code looks good, and good idea, thanks!

However, this brings up the problem of whether I want to be bug-for-bug compatible with Sublime. So far I've tried to match Sublime's behaviour, and that's possibly even why that code is the way it is in syntect (although I may have just messed up in the same way). I've never had to rule on whether to replicate a bug before. I'd definitely also feel better if there was an official ruling on that issue that it really is a bug they intend to fix soon.

I also wonder if changing this would break compatibility with any themes. My head's not in the game enough right now to tell.

@brupelo
Copy link

brupelo commented Mar 11, 2019

@keith-hall From this thread and this one I also assume you're also interested on this subject... I've made some tests here in order to figure out how score_selector works internally but I haven't been able to figure out yet, do you know something about it?

@keith-hall
Copy link
Collaborator Author

Nope, sorry, can't help with that. For my purposes, as long as it returns the correct results, how it does so is just an implementation detail that could change any time without really affecting me. If you do find out, it would be of academic interest to me ofc, but I'm happy enough knowing how it works in syntect.

@Enselic
Copy link
Collaborator

Enselic commented Mar 14, 2022

I'm closing this PR for now as the open questions in #132 (comment) seems unaddressed, and since it is nice to keep the PR inbox clean, but of course feel very free to reopen this if I am closing it prematurely.

@Enselic Enselic closed this Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants