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

fix(themes): Highlight .token.null #1727

Closed

Conversation

ExE-Boss
Copy link
Contributor

The JSON syntax highlighting uses .token.null to style null:

'null': /\bnull\b/

This updates the Prism stylesheet to style it using the style for .token.boolean and .token.number.

@mAAdhaTTah
Copy link
Member

It seems curious that JSON is the only language that has .token.null for null. I think we highlight it as a keyword in other languages. Might make more sense to change how we highlight in JSON.

@RunDevelopment Thoughts?

@ExE-Boss
Copy link
Contributor Author

Well, PHP used .token.null at one point too:

Prism.languages.insertBefore('php', 'class-name', {
'null': {
pattern: /\b(?:null)\b/i,
alias: 'constant predefined-constant'
}
});

And there might be other languages that do the same.

@RunDevelopment
Copy link
Member

At this point in time, the only languages which have a null token without aliases are JSON and SCSS.

I think we highlight it as a keyword in other languages.

Depends on the language. Most use keyword, some use boolean, few use others.

Might make more sense to change how we highlight in JSON.

I also think it's better for JSON to have null as a keyword instead of changing the themes to include null for a few reasons:

  1. You only have to change one file. keyword is supported by all themes.
  2. JS uses keyword for null and JSON is supposed to be a subset of JS (it's not, but almost).
  3. We can always use the Highlight Keywords plugin to change the style of null.

@ExE-Boss
Copy link
Contributor Author

  1. JS uses keyword for null and JSON is supposed to be a subset of JS (it's not, but almost).

It is a subset of ES2019+, as ES2019 now allows unescaped \u2028 and \u2029 in strings:

let str = "a
b"; // This string contains an unescaped Line Separator

That said, I’d still like to fix highlighting of .token.null.

@RunDevelopment
Copy link
Member

That said, I’d still like to fix highlighting of .token.null.

.token.null is pretty much a non-standard token name, so I think it's ok to ignore it.
Plus, changing JSON and SCSS is simply easier.

@mAAdhaTTah
Copy link
Member

Agreed. I'd prefer to use a token we reuse across a lot of languages than handling a token used once or twice in a theme. I find it a little curious some of them are using boolean for null; keyword seems to make the most sense, so maybe we just decide now to consistently use keyword for it?

Appreciate you raising this to our attention!

@RunDevelopment
Copy link
Member

keyword seems to make the most sense, so maybe we just decide now to consistently use keyword for it?

Well, it's not that easy...
Most languages in which null (so similar) is a language construct highlight it as keyword. But we can't just make null a keyword in all languages.
I.e. in C/C++ NULL is a macro, in PHP it's a constant.

But I think that null (or conceptually similar) should not be boolean as in Python (None), SQL, and Twig.

@mAAdhaTTah
Copy link
Member

Fair enough; choosing something that makes sense for each language is fine. I'm admittedly less familiar with those languages, but I think a null token for JSON & SCSSS only doesn't really make sense. So we should update the JSON + SCSS languages to give null different tokens. Agree?

@ExE-Boss
Copy link
Contributor Author

ExE-Boss commented Feb 13, 2019

I dunno, the null token makes a lot of sense for JSON, maybe we could add keyword as an alias?

@RunDevelopment
Copy link
Member

So we should update the JSON + SCSS languages to give null different tokens. Agree?

Maybe the alias idea from @ExE-Boss is even better. I mean, we used these token names for quite some time now, so there might be some folks out there how incorporated null into their themes. With an alias, it's unlikely (but still possible) that we break them.

@mAAdhaTTah
Copy link
Member

I'm on board with that.

@RunDevelopment
Copy link
Member

Just for clarification: We are not going to change the themes now, are we? @ExE-Boss @mAAdhaTTah

@ExE-Boss
Copy link
Contributor Author

I’d like to fix the themes.

@RunDevelopment
Copy link
Member

@ExE-Boss With or without the aliases? Because after the aliases, there's nothing to fix.

@ExE-Boss
Copy link
Contributor Author

Well, even with the aliases, .token.null should still take precedence over .token.keyword.

@RunDevelopment
Copy link
Member

So you want to change the look of null to be highlighted the different from keyword, I suppose.
I think is better if JSON's nulls are highlighted like JS's nulls. Consistency.

@RunDevelopment
Copy link
Member

I feel like this question should have been asked a lot sooner, but why do you want null to look like boolean?
Null and true/false are not conceptually close (IMO) and most editors highlight both like keywords, so why boolean?

@ExE-Boss
Copy link
Contributor Author

After a day of thinking it over, I think it might be better to just highlight it using keyword as an alias.

@mAAdhaTTah
Copy link
Member

I'm personally opposed to changing the theme here, as I think handling a token in all the themes that only appears in two languages is unnecessary and the correct fix is the keyword change, as suggested.

@RunDevelopment
Copy link
Member

I'm personally opposed to changing the theme here

Agreed. After #1735 there's nothing left to fix.

I'm closing this now. Feel free to reopen this if further discussion is necessary.

mAAdhaTTah pushed a commit that referenced this pull request Feb 14, 2019
Add the `keyword` alias to the `null` pattern for SCSS.

This was the last `null` pattern without any aliases (#1727).
@ExE-Boss ExE-Boss mentioned this pull request Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants