borela / naomi

Sublime Text enhanced syntax highlighting for JavaScript ES6/ES7/ES2015/ES2016/ES2017+, Babel, FlowType, React JSX, Styled Components, HTML5, SCSS3, PHP 7, phpDoc, PHPUnit, MQL4. Basic: Git config files.
Other
558 stars 18 forks source link

Cast object literal keys as strings or numbers for syntax highlighting #72

Closed neaumusic closed 6 years ago

neaumusic commented 6 years ago

Similar to Babel plugin, Object keys should be strings or numbers!!

Desired (Babel) syntax highlight: Desired (Babel) syntax highlight

Current (Naomi) syntax highlight: Current (Naomi) syntax highlight

borela commented 6 years ago

I agree with you that object keys are technically unquoted strings and I would love to change that, the sublime core devs even tried to that exactly that in the past but it broke many color schemes and so they had to revert the change: https://github.com/sublimehq/Packages/issues/141#issuecomment-182826789

I would be inclined to add this as a configurable option, soon I'll have to use a build system to simplify the syntaxes and that will allow me to make the syntaxes configurable.

For now, to make the keys looking like a string, a key need to be added to the color scheme, in your example:


<dict>
  <key>name</key>
  <string>Object literal key</string>
  <key>scope</key>
  <string>meta.object-literal.key, meta.object-literal.key variable.other.readwrite</string>
  <dict>
    <key>foreground</key>
    <string>#e6db74</string>
  </dict>
</dict>
neaumusic commented 6 years ago

I was getting a weird error "Expected element key" when trying to add that snippet to the Monokai.tmTheme file, but I ended up adding those scopes in the String entry and it works great

object literal string syntax highlighting

<dict>
  <key>name</key>
  <string>String</string>
  <key>scope</key>
  <string>string, meta.object-literal.key, meta.object-literal.key variable.other.readwrite</string>
  <key>settings</key>
  <dict>
    <key>foreground</key>
    <string>#E6DB74</string>
  </dict>
</dict>
borela commented 6 years ago

https://github.com/borela/naomi/releases/tag/v3.7.0 Reverted object keys to unquoted strings except for numbers. I let the relevant portion of code commented only so that when I implement the build system this feature could be disabled if users so desire.

In your case, you probably won't need to patch the color scheme anymore.

borela commented 6 years ago

The latest patch was published and now the syntax will adopt babel sublime's behavior highlighting object literal keys.

A-312 commented 4 years ago

If someone want to revert this change (I mean revert to the default property name color, I mean white or whathever) :

Sublime Text 3/Packages/User/Monokai.sublime-color-scheme:

{
    "rules": [
        {
            "scope": "source.js meta.declaration.variable.js.fjsx15 meta.object-literal.js.fjsx15 meta.block.js.fjsx15 meta.object-literal.key.js.fjsx15 string.unquoted.js.fjsx15",
            "foreground": "var(white)"
        },
    ]
}

(To get scope name, use developper tool "Show scope name")