Sublime Forum

Ruby syntax highlighting - Change color of %i and %I symbol array literal elements according to symbol color

#1

Hi,
maybe there is a way to get this without changing the Ruby.sublime-syntax for all (I’d be glad for any instructions) but I don’t understand the .sublime-syntax format yet, nor do I know how to override the file locally (if possible).

So, what do wish?

:foo
%i[foo bar]
# => [:foo, :bar] 

Here, the :foo symbol is colored purple. Elements of the %i(foo) are yellow as if they’d be strings. I’d love to have those elements to be purple to show, what they actually are.

While of course Elements of

%w[foobar]
# => ["foobar"] 

shall keep yellow as they are strings.

Thanks for any idea!

0 Likes

#2

This will likely require a fix in the Ruby.sublime-syntax for all users. If you post the issue at https://github.com/sublimehq/Packages/issues someone will probably make an attempt at fixing it.

If you want to try and work on it yourself, generally the best place for help would be the #default-packages channel on the Discord server since a lot of the core contributors to the default packages hang out there.

From a cursory look, the changes will need to be made at https://github.com/sublimehq/Packages/blob/master/Ruby/Ruby.sublime-syntax#L997-L1049. I presume the i version creates a symbol array? If so, you may need to split it out and then have it match \w+ segments as the scope for symbols.

0 Likes

#3

Thank you for your response @wbond!
The line you pointed at looks like a good candidate, although I had a few others which looked (more or less) similar promising in this file. Still, I personally do not understand how/what I should change it. Thus:
I opened an issue as you suggested: https://github.com/sublimehq/Packages/issues/1879

0 Likes

#4

Initial PR is here: https://github.com/sublimehq/Packages/pull/2148

I’d be glad if someone could give me feedback or suggestions on this, thanks :slight_smile:

0 Likes