-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
TSX files are identified as TypeScript rather than JSX+TS #4359
Comments
This issue has been automatically marked as stale because it has not had activity in a long time. If this issue is still relevant and should remain open, please reply with a short explanation (e.g. "I have checked the code and this issue is still relevant because ___."). Thank you for your contributions. |
This issue is still relevant. The issue can still be seen here: https://github.com/rainboxx/tsx-jsx-repro/tree/master |
Ooops, I'm not sure how we missed this until now.
I don't think we want to be changing this. As I understand it, JSX can be used with a number of Javascript-like languages and |
Hi @lildude, There seems to be a "Team Sports Scheduling System XML Project File" with the suffix I think it's the same way "not a language" as |
Hmmm, now I'm confused. What problem are you pointing our or what are you requesting in this issue? From your OP I took it that you were asking for Typescript files with JSX within them be identified as "Typescript + JSX" instead of just "Typescript", and thus would warrant an equivalent for "Javascript + JSX" (perfectly valid AFAIK) and any other Javascript-like language which can or do use JSX. As it currently stands,
I'm pretty sure this already happens in some form or another as it stands. |
Sorry for being confusing 😉. I wanted to point out that the suffix is official because I interpreted your reply as "we shouldn't give Your resumé is straight to the point, except that I would clarify that "Typescript files" have the suffix
Maybe I'm getting you wrong (not a native english speaker), but the current rules are:
The TypeScript syntax is highlighted in I assume I'm just repeating what you already know 😉. Are you saying you don't want to implement a special sub-language |
This is going to be a problem with the syntax highlighting grammar and not Linguist, and is very similar to a long running issue we already have for JSX syntax highlighting - #3044
That is indeed confusing and it's not likely to stand for much longer. We're likely to roll
... from #3677 (comment) and then further acknowledged by @Alhadis at #3677 (comment):
The same arguments are likely arise if we split
Yes, but also because it shouldn't be needed if we stop treating JSX as its own language and start treating it as a sub-set of Javascript that it apparently is. |
I'm totally in favor of bringing However, could there still be some plans to still support JSX highlighting inside of TypeScript? JSX, according to https://facebook.github.io/jsx/, is an "XML-like syntax extension to ECMAScript" and therefore not exactly a sub-set of JavaScript. Because of this the "syntax extension" can also be used with TypeScript. This is a very valid use-case when using React in combination with TypeScript and I would really love to see this syntax change happen. Sorry, commented with the wrong user, comment should've been created by @rainboxx |
I don't see why not, however this would be up to the grammar maintainer to implement, not Linguist (we only do the language determination), or for another grammar to be sourced that has JSX support. |
Ok, so the whole ticket here is basically not relevant to linguist? And I should ask the grammar maintainer for TypeScript... Right? |
Yup, essentially, but you'll please to know I'm in the process of making a new release for Linguist and it includes an update to the TypeScript grammar which from my quick local testing takes your sample ... to ... Whilst not as pretty as the sample |
Thanks for letting me know about the change! I quickly checked the grammar repo and saw that this grammar is also in use within VS Code. That application detects JSX inside of (I fixed the sample code on GitHub as well but it still shows as before.) VS Code just highlights through TypeScript that Any idea how to investigate this further? |
@rainboxx you've really piqued my interest in getting to the bottom of this 😄 I've been experimenting with the TypeScript grammar in Lightshow and I think the issue here is the TypeScript repo actually provides four grammars with the two we're interested in being TypeScript and TypeScriptReact. These grammars do not source/include each other and as such are treated as different languages. GitHub is using the Typescript grammar to highlight your If I force the language to TypeScript I see the same highlighting as coming in the next release of Linguist: You can see this in action in Lightshow too:
Linguist, and thus GitHub, doesn't know about the "TypeScript React" language and thus doesn't use this grammar. I think there are only two solutions to this:
I'm reluctant to do the latter for my previously stated reservations but it might be the only option. |
I might be missing some context here, but why would option 1 not be acceptable?
As far as I remember (and understand), the issue with JSX is not so much with |
🤷♂️ just putting it out there. The two a currently separate, probably for maintainability, so the upstream team may not be too keen on merging the two. |
Would there be any drawback from using the TypeScriptReact grammar to highlight all TypeScript code? |
Any update on this? |
This issue has been automatically marked as stale because it has not had activity in a long time. If this issue is still relevant and should remain open, please reply with a short explanation (e.g. "I have checked the code and this issue is still relevant because ___."). Thank you for your contributions. |
I've not worked with TypeScript before (unless editing an Then, when my slack arse gets back to rewriting the JS grammar, I can consider integrating TypeScript syntax along with everything else, making it a single-grammar which we can use for JSX, TSX, plain TypeScript, plain JavaScript, and so forth. Will see what I can do. =) |
This issue has been automatically marked as stale because it has not had activity in a long time. If this issue is still relevant and should remain open, please reply with a short explanation (e.g. "I have checked the code and this issue is still relevant because ___."). Thank you for your contributions. |
Since @Stale marked this as |
@Alhadis sorry, I skipped this question, which I thought was directed to someone else but I could've answered this as well... Actually there could be an issue with the angle-bracket type assertion syntax, which is not allowed when using JSX. It looks like being an opening JSX tag and would most likely break syntax highlighting. I'm sure many people are switching to the |
Damn. I see what you mean... 😕 I suppose in the short-term, we can add TSX as a language, but it'll be grouped under TypeScript (and be classified as such in statistics bars). As long as Microsoft don't start phasing out the I describe this as a short-term solution because the long-term desideratum is to have a single grammar which can intelligently highlight both JSX and ordinary JavaScript. Doing so will involve some creative hacks, but I know from experience it's certainly possible. I just need to set aside some time first... |
@Alhadis sounds like a plan! If there's anything I can help, let me know. Thank you! |
Preliminary Steps
I confirm I have...
Problem Description
Files with the extension
.tsx
(and code blocks with language identifiertsx
) on GitHub are shown as TypeScript instead of TypeScript+JSX.URL of the affected repository:
https://github.com/rainboxx/tsx-jsx-repro/tree/master
Last modified on:
2018-12-21
Expected language:
JSX, although I'm not sure whether there needs a new language that combines TS+JSX
Detected language:
TypeScript
The text was updated successfully, but these errors were encountered: