textmate / ruby.tmbundle

TextMate support for Ruby
178 stars 90 forks source link

Removed redundant scope #122

Closed Epigene closed 6 years ago

Epigene commented 6 years ago

Hi, this is a re-post from https://github.com/Microsoft/vscode/pull/56745#event-1796897759

infininight commented 6 years ago

So some history here: Originally the entire #{} construct would have been scoped as source.ruby to indicate and embedded bit of code. This however had the issue as you point out of being incorrect so the meta.embedded scope was introduced. This example is a bit different as it's basically ruby code embedded in ruby code. A easier to describe example is probably PHP.

In PHP you have the tags <?php ?>, this isn't exactly the PHP code but really just the construct that enables the PHP code contained therein. So we use a combination of meta.embedded and punctuation scopes to denote this, and then an interior source.php scope.

A big reason for all this is the scope of the caret. In TextMate at least the default scope used for running command and such is the scope to the right of the caret. With the previous solution you were in a PHP scope when the caret was right before <? which caused problems. Moving to meta.embedded solves this but causes a new issue, now when you are inside a tag and right before ?> you don't have a PHP scope. The same is true with an empty tag.

So to solve this issue we always give the closing character of an embedded context the scope of the interior. While technically wrong it provides a better caret scope. For PHP we only scope the ? of ?> as source.php, in this case there is only one character so } gets the source.ruby scope.

Seems one of your reasons was for theming purposes, you may find targeting the meta.embedded scope to be a better fit for this as it will target the entire context and even empty contexts. Many themes use a different background color for this but there are lots of ways to do it.