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

Replace JSX grammar #4223

Merged
merged 2 commits into from
Oct 5, 2018
Merged

Conversation

pchaigno
Copy link
Contributor

@pchaigno pchaigno commented Aug 5, 2018

This pull request changes the JSX grammar to use https://github.com/babel/babel-sublime as discussed in #3779.

Description

Our current JSX grammar is locked to an old version because of a bug in the upstream grammar. With 632 commits behind the upstream to date, we're sure to miss important fixes and updates. Keeping the fork up-to-date is difficult because we have to watch out for PCRE incompatibilities in regular expressions.

This pull request changes the JSX grammar to use babel/babel-sublime. As discussed in #3779, the only issue is we have to change the scope to avoid a conflict with JavaScript.

@lildude I'm guessing Lightshow is still blocked by the security review... Any chance you could check on your side if the grammar applies correctly and if it fixes #3775?

Fixes #3775 (cf. example 1, example 2, example 3, and example 4).

@Alhadis Alhadis changed the title Replace jsx grammar Replace JSX grammar Aug 7, 2018
@lildude
Copy link
Member

lildude commented Aug 12, 2018

I've taken a quick look at the difference in grammars and the babel/babel-sublime grammar produces quite different syntax highlighting for the simple example mentioned in #3775 (comment):

screen shot 2018-08-12 at 12 03 38

Interestingly, the current grammar doesn't show the problem either, but does render it quite differently:

screen shot 2018-08-12 at 12 04 17

The first example of those I reference in #3775 (comment) fails quite horribly with the babel/babel-sublime:

screen shot 2018-08-12 at 12 08 24

... vs our current grammar:

screen shot 2018-08-12 at 12 09 53

@pchaigno
Copy link
Contributor Author

@lildude - @kivikakk mentioned the same highlighting issue in #4168, and it looks like it's coming from Lightshow. I'll wait for her go to update the original post with links to Lightshow.

@kivikakk
Copy link
Contributor

@lildude @pchaigno As of now, this issue should be fixed. Here's the simple case rendering properly.

image

@pchaigno
Copy link
Contributor Author

Thanks @kivikakk!

@lildude I've updated the original post with the appropriate links to Lightshow. Ready for review!

@lildude
Copy link
Member

lildude commented Aug 14, 2018

@pchaigno it certainly looks better, but still noticeably different:

compare

Not sure if this is a grammar or Lightshow difference though and if it's significantly different that peeps will notice.

@Alhadis
Copy link
Collaborator

Alhadis commented Aug 14, 2018

It's a grammar difference. If this grammar is anything like the language-babel grammar, then many of the scopes will differ to language-javascript. Most of the discrepancies are minor, but function calls in particular are being scoped strangely:

obj.methodName( arg ); /*
    ^^^^^^^^^^ - entity.name.function.js (Current)
               - variable.function.js (Babel grammar)
*/

Offending lines: #2375, #2408

Barring visual and aesthetic differences, the current scope-name (entity.name.function) is more correct according to the semantics of TextMate grammar naming conventions.

@pchaigno
Copy link
Contributor Author

Yep, I've seen the missing colors for HTML tags but I thought it was worth it since it fixes the previous bugs? Maybe we can report the discrepancies upstream if they're not already.

@Alhadis
Copy link
Collaborator

Alhadis commented Aug 14, 2018

I doubt upstream will be interested in accepting changes, since that's imposing the same unexpected (and apparently arbitrary) colour changes on users of the babel-sublime package. Part of why so many grammars continue to have incorrect scope-choices is because there's little incentive to justify the changes (beyond grammar-specific semantics few end-users care about).

Remember, these scopes dictate what users have to put in their stylesheets and preference files to tweak the colour choices...

@Alhadis
Copy link
Collaborator

Alhadis commented Aug 14, 2018

@pchaigno It should be safe to perform a simple search-and-replace for the following patterns:

Search for: Replace with:
<string>variable.function.js</string> <string>entity.name.function.js</string>
<string>meta.tag.jsx entity.name.tag.jsx</string> <string>entity.name.tag.html.jsx</string>

I believe including .html as a scope for JSX tags will adjust the highlighting to better match what we have currently, as that's the scope being used by our language-babel fork.

@pchaigno
Copy link
Contributor Author

I doubt upstream will be interested in accepting changes, since that's imposing the same unexpected (and apparently arbitrary) colour changes on users of the babel-sublime package. Part of why so many grammars continue to have incorrect scope-choices is because there's little incentive to justify the changes (beyond grammar-specific semantics few end-users care about).

I was referring to the lack of HTML highlighting rather than scope names 😜

It should be safe to perform a simple search-and-replace for the following patterns:

Hm, is that something we could upstream?

@Alhadis
Copy link
Collaborator

Alhadis commented Aug 14, 2018

Hold on, I just noticed there are spaces inside some of the scope names. Specifically, the ones affecting the HTML highlighting. Is that legal in XML TextMate grammars?

Because it's been known to screw with selector matching in Atom, so I wonder if it might be having an adverse effect on Lightshow too... :\

Hm, is that something we could upstream?

Nope. We're performing a mass change of dozens of scope names, which goes back to my previous point. 😉

@pchaigno
Copy link
Contributor Author

Hold on, I just noticed there are spaces inside some of the scope names. Specifically, the ones affecting the HTML highlighting. Is that legal in XML TextMate grammars?

Looks like they're trying to define two scope names (separated by a white space) for the matched tokens... I'm surprised that even works with Sublime Text.

Nope. We're performing a mass change of dozens of scope names, which goes back to my previous point.

Right, my bad; I read a bit quickly.

@budmc29
Copy link

budmc29 commented Sep 28, 2018

Any updates on this? I'm happy to help getting this merged.

@pchaigno
Copy link
Contributor Author

pchaigno commented Oct 2, 2018

I've updated the modified version of the babel-sublime grammar hosted at github-linguist/babel-sublime to change scope names as per @Alhadis' suggestions and to fix the double scope names. Here is the result:
sans titre
Old is the previous grammar; New is the new grammar before the scope name changes; newer is the last version.

It's not perfect because we'll have to update the scope names if the grammar is updated, but at least it fixes #3775.

@pchaigno pchaigno force-pushed the replace-jsx-grammar branch from 70ff9dd to 0e66c53 Compare October 2, 2018 14:22
@pchaigno pchaigno requested review from Alhadis and lildude October 4, 2018 16:48
Copy link
Collaborator

@Alhadis Alhadis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

Copy link
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. Thanks. 🙇‍♂️

@pchaigno pchaigno merged commit b70a976 into github-linguist:master Oct 5, 2018
@pchaigno pchaigno deleted the replace-jsx-grammar branch October 5, 2018 07:49
@peterbe
Copy link

peterbe commented Nov 1, 2018

Disclaimer; I haven't studied the details of this PR but I see that it was merged about a month ago and I'm still seeing busted display of JSX .js files. E.g. https://github.com/peterbe/whatsdeployed/pull/41/files

@Alhadis

This comment has been minimized.

@kivikakk

This comment has been minimized.

@Alhadis

This comment has been minimized.

@kivikakk

This comment has been minimized.

@Alhadis

This comment has been minimized.

@kivikakk

This comment has been minimized.

@Alhadis

This comment has been minimized.

@Alhadis

This comment has been minimized.

@lildude
Copy link
Member

lildude commented Nov 1, 2018

Disclaimer; I haven't studied the details of this PR but I see that it was merged about a month ago and I'm still seeing busted display of JSX .js files. E.g. https://github.com/peterbe/whatsdeployed/pull/41/files

That's probably because there hasn't been a Linguist release made since this PR was merged so you're still looking at the old behaviour. I aim to make a new release approximately monthly and today would make it exactly a month since the last release 😁

I'll try find time in the next week.

@mythmon
Copy link

mythmon commented Mar 29, 2019

As a follow up to the last comment, we're still seeing the same syntax highlighting problems on whatsdeployed PRs. This PR is extremely hard to review since most of the lines are covered in red backgrounds.

We've seen this problem pretty continuously over the last few months. I think it is a regression based on this change, and that nothing has happened in the last few months.

@lildude
Copy link
Member

lildude commented Mar 29, 2019

@mythmon This is happening because of the apostrophe right at the beginning of the JSX content and is essentially a continuation of #3044. We're attempting to get this fixed in the upstream grammar in #3044

@github-linguist github-linguist locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Javascript/JSX single-quote/apostrophe breaks syntax highlighting
7 participants