atom / language-ruby

Ruby package for Atom
Other
101 stars 144 forks source link

Add scopes for a number of items. #267

Closed savetheclocktower closed 5 years ago

savetheclocktower commented 5 years ago

Description of the Change

There are a number of scopes missing from the tree-sitter grammar that are present in its TM-style sibling. Many of these aren't used by one-dark-syntax or other common syntax themes, which is probably why they've been overlooked. Here's what I've added:

  1. All strings, regardless of type, were scoped simply as string. I fleshed out these scope names to match the TM-style grammar: string.quoted.single, string.quoted.double.interpolated, et cetera.
  2. Global variables had no scope name. Now they're scoped as variable.other.readwrite.global.
  3. Operators weren't scoped at all. Now they're all given keyword.operator scope names equivalent to what they get in the TM-style grammar.
  4. Ordinary method parameters were scoped as variable.parameter, but method parameters with default values got no scope. Fixed this oversight.
  5. A number of punctuation scopes were added, including single- and double-quotes around strings, as well as the . and &. operators.

The atom-light-syntax theme is the first builtin theme I found that actually shows these differences. The existing grammar is on the left, and the updated grammar is on the right:

language-ruby-1 language-ruby-2

Alternate Designs

One thing worth mentioning: the distinguishing quotation marks via :nth-child selectors seems brittle. I'd love it if an :nth-last-child selector were available, but I've seen the code that implements :nth-child and I'm not sure I understand it well enough to try yet.

Benefits

Better syntax highlighting and richer contextual information for commands.

Possible Drawbacks

Hard to think of any. If this were a bold new direction for scope naming, perhaps there'd be some, but this is just about parity with the old grammar. The changes aren't even visible in most of the common syntax themes; the ones that are visible are obviously improved in consistency.

Applicable Issues

Can't find any among the open issues.

jasonrudolph commented 5 years ago

Thanks for this, @savetheclocktower! 💟