Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
neaumusic opened this issue Feb 21, 2018 · 5 comments
Closed

Comments

@neaumusic
Copy link

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
Copy link
Owner

borela commented Feb 22, 2018

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: sublimehq/Packages#141 (comment)

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
Copy link
Author

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
Copy link
Owner

borela commented Feb 28, 2018

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
Copy link
Owner

borela commented Mar 5, 2018

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

@borela borela closed this as completed Mar 5, 2018
@A-312
Copy link

A-312 commented May 13, 2020

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants