Sublime Forum

Ruby instance variable highlighting/better Ruby syntax in general

#1

Ruby instance variables have never really been highlighted properly in Sublime. I’ve seen some attempts over the years to improve the Ruby.tmLanguage file (such as https://gist.github.com/edubkendo/6198986#file-rubynext-tmlanguage) but none of these improvements have made it into Sublime itself. How can we go about improving support for Ruby syntax?

1 Like

#2

All default syntaxes are maintained by the community at https://github.com/sublimehq/Packages

You are free to learn how the new syntax highlighting engine works and start contributing.

The engine is very powerful and allows context sensitive scoping of elements. It can do much more than the old *.tmLanguage format was ever able to. But it turned out to be a quite tricky job to create proper lexing rules with a static lexer which has do idea of the language itself. It requires a lot of guess work sometimes - with many possible edge cases.

Never the less high quality contribution is appreciated.

0 Likes

#3

Thanks for sharing, and looks like some people have already bug reported it over there.

0 Likes

#4

Hi, I’m trying to improve the highlighting in MonokaiFree. What color do you feel the instance variables should be? Currently your snippets look like this is MonokaiFree:

Please feel free to open issues about bugs and enhancements and I’ll do my best to.

0 Likes

#5

Maybe the red? Or magenta? Honestly, the color matters less versus it actually being a separate color :).

0 Likes

#6

Currently, Ruby instance variables are marked variable.other.readwrite.instance.ruby and the @ sigil is marked punctuation.definition.variable.ruby. These are probably the correct scopes; marking the variable as something like variable.language would be inappropriate.

The default Mariana color scheme does highlight the sigil (under punctuation.definition), although many color schemes do not. Most color schemes do not highlight variable.other.readwrite.instance, and I’m not sure how many languages make that distinction syntactically. However, if you use Ruby frequently and want instance variables to stand out, you can modify your favorite color scheme to highlight the variable.other.readwrite.instance scope.

@gerry: I’d recommend highlighting the punctuation.definition scope. This is what Mariana does.

1 Like

#7

Both the $ and the variable name can be highlighted. It’s really just a question of what colour and if both should be the same or just one or the other given a color. The impact the different choices of color have on the overall look and feel of the color scheme is surprising.

What I suggest is to try the different colors and spend a few days or a week with it and resolve to decision on what you think is best.

The relevant scheme definitions are:

<dict><key>scope</key><string>variable.other.readwrite.instance.ruby punctuation.definition.variable.ruby</string>
    <key>settings</key><dict><key>foreground</key><string>#fd971f</string></dict></dict>

<dict><key>scope</key><string>variable.other.readwrite.instance.ruby</string>
    <key>settings</key><dict><key>foreground</key><string>#fd971f</string></dict></dict>

Add those definitions to MonokaiFree and try it with colors from the palette:

    bg          | #272822
    bg_h        | #3e3d32
    fg          | #f8f8f2
    fg_h        | #75715e

    yellow      | #e6db74
    orange      | #fd971f
    red         | #f92672
    magenta     | #fd5ff0
    violet      | #ae81ff
    blue        | #66d9ef
    cyan        | #a1efe4
    green       | #a6e22e
0 Likes

#8

The scope naming documentation suggests that variable.other.member should be used for something like an instance variable. Creating a specialized scope under variable.other.readwrite is a little too deep, in my mind, for something that is pretty common.

1 Like