-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
JSX language support - more than colors #140
Comments
Seems that changing language only affect highlighting? |
@leafduo So it does, and I must change file extension into .jsx to get rid of these warnings. |
@OshotOkill It's annoying. And jsx and js files have different highlighting. That's annoying too. |
http://stackoverflow.com/questions/32832264/change-language-to-jsx-on-visual-studio-code Found this but it is not working for the latest VS Code build |
@leafduo That's OK for me, especially colors and highlightings are the same as .tsx files in this version (kinda like C#). |
@daiheitan It's a hack lol and could lead to some side effects... BTW #81 also mentioned these problems. |
Same problem here, none of the hacky "fixes" I've found around the internet seem to help either. Is renaming our files to use the IDE properly really our only option at the moment? |
@anibali AFAIK It is... Once upon a time I replied them on twitter for asking jsx support, and they said they were working on getting it better just a start. |
@OshitOkill |
I think one of the issues seems to be that jsx is seen as different to normal js (which seems to work pretty well with autocompletion/intellisense etc). JSX and other variants of JS should still be able to support all the same functionality as the basic JS syntax if those features are available and there should be the ability for VS Code dialects to act as extenders as oppose to completely separate languages if that makes any sense... |
Appart form syntax highlights there is no real support for JSX yet, but it is on its way. Stay tuned. |
What is the motivation for JSX syntax in .js files? I don't understand what using the .js file extension buys you other than possible tooling compatabilty. I don't doubt that there are valid reasons but they should be presented when making feature requests. |
@jpierson It's like having JS code in an HTML page. Also, from a developer point of view, JSX is Javascript with a different syntax. |
@jpierson Using a new IDE should not force you to rename a bunch of files IMO. |
There is a workaround by using ESLint. Have a look at "JavaScript Linters (ESLint, JSHint)" heading on this page: Very efficient! |
Ok so what I can gather from @anibali and @gpbl is that jsx syntax inside .js files is useful for designers and there must be other editors that have set this precident and thus would make VSCode difficult to switch to for projects that have been taking advantage of this feature. Does that sound right? Personally I would be more in favor of a feature that allows a global setting that makes all .js files be able to default to reactjs JSX syntax. This should be similar to the jsconfig files that are already used on a directory level to specify between es5 and es6. Any arguments against using that as a solution? My concerns about supporting any super set of JavaScript in .js files is that it could potentially make the code for standard JS parsing more complex, slow, and hard to maintain. Are these concerns valid? |
See #334 for more details on another option for treating JavaScript as JSX. |
@jpierson I don't expect any superset of JS to be automatically supported. Either of your proposed solutions would work fine for me. |
FWIW the ESLint workaround proposed by @alexisbg is good for my needs. |
@jpierson My opinion is similar that they should make an optional choice in user settings to config all .js files support JSX syntax or, to say the least, provide this option in jsconfig.json. |
@alexisbg lOl I totally forget we could initiate ESlint in editor other than the default and extensions now make it more convenient to switch between. Thanks. But I am also looking forward to another way of setting this in global rather than download ESlint from NPM every time. |
Does the eslint workaround work when the file is named |
If I use the eslint workaround, can I still get intellisense to work? |
@fhelwanger Intellisense seems to work but it is not always relevant. |
eslint is a decent workaround at the moment but it would still make a lot of sense to fully support JSX syntax in |
We plan to improve this by integrating the Salsa work from the TypeScript team: microsoft/TypeScript#4789 |
@jwulf Yes it does and .jsx files now support the basic function -- autocomplete brackets...( in version 0.10.2) If you try to return two nodes in |
Not a fix, but here is a workaround for using VS Code with JSX:
|
js-is-jsx extension + eslint extension looks like the best combo for now, as you will get both syntax highlight and hinting. |
Yes makes sense, thanks (updated my comment above). |
That's really a huge tradeoff between form (highlighting) and function (intellisense), which IMO is the distinguishing feature of Code. Sublime Text otherwise has an excellent highlighting support for JSX already. Here's my +1 to a quick and full native JSX support in Code. |
I +1 as well. I have just started using WebStorm instead... Which I don't like nearly as much. |
@JustSayNO @prashaantt the other work around you can try is to disable the built in JS validation. Then you will still get some intellisense in JS but still no support for JSX intellisense. To disable the built-in JS validation add the following setting to your user or workspace settings: {
"javascript.validate.enable": false
} Please let me know what you think works better, than we can adjust the work around recommendation. |
@jwulf I have the same issue: I use the workaround with eslint + the corresponding vscode extension but the linting simply does not appear in vscode when I edit my .jsx files. However:
|
+1 IntelliSense is great, having it for JSX files would be cruc |
@mheiber I think that Salsa already does that. Check https://code.visualstudio.com/Updates#_javascript-salsa-preview |
Closing - Salsa will be the default for the February update and supports JSX. |
Thanks! I'll switch over to Salsa, looking forward to trying it out. Love
|
I think this is now easily fixed with the setting: "files.associations": {
"*.js": "javascriptreact"
} |
I know VSCode has not support JSX yet but it didn't appear so much error highlights in the last version, even I had already changed my language mode into
Plain Text
.The text was updated successfully, but these errors were encountered: