Coder Social home page Coder Social logo

Please, JSX support about vim-css-color HOT 13 CLOSED

ap avatar ap commented on July 18, 2024
Please, JSX support

from vim-css-color.

Comments (13)

ap avatar ap commented on July 18, 2024 1

And that is hereby done, so there you go. šŸ˜„

Share and enjoy.

from vim-css-color.

ap avatar ap commented on July 18, 2024

To my knowledge, Vim does not ship syntax highlighting for JSX. I assume you use a plugin for that? If yes, which? I found mxw/vim-jsx; is there another? And if you know: are there several popular plugins that I should all support?

(If not a plugin, how have you set this up? Is there an ā€œofficialā€ documentation somewhere?)

from vim-css-color.

joeytwiddle avatar joeytwiddle commented on July 18, 2024

For what it's worth, that's the one I use, and I never tried another. 600 stars can't be wrong!

from vim-css-color.

chapati23 avatar chapati23 commented on July 18, 2024

for now at least just aliasing filetype javascript.jsx to javascript would already be a huge step forward as that'd at least bring back normal color highlighting outside of jsx-definitions (it's very typical for a react-project to mix normal javascript and jsx)

from vim-css-color.

fakenickels avatar fakenickels commented on July 18, 2024

Sorry about the delay to reply @ap.
And yes, I use vim-jsx from @mxw.

from vim-css-color.

ap avatar ap commented on July 18, 2024

No prob, sorry Iā€™ve not gotten around to this yet. Will do soon.

from vim-css-color.

ap avatar ap commented on July 18, 2024

OK, so I finally got around to this. And it looks like youā€™ll have to help me out here fellas.

First off, what I did: I installed pangloss/vim-javascript and mxw/vim-jsx, and then I created a file example.jsx and pasted some JSX snippets I found on the web with inline styles in them into the file. Andā€¦ it already works for me?

So I checked set ft? and found it says javascript, not jsx or something else, which evidently triggers the JS support I have longed added to css-color.

Does that ft value mean I didnā€™t install the JSX plugin right? Or was it changed in the time since this ticket was created? (Maybe something like @chapati23ā€™s suggestion was done upstream?)

What I get is that color references within strings in a JSX file are highlighted as their color value. Looks fine to me. But I donā€™t (if it wasnā€™t obvious) use JSX myself, so I have no idea what else a JSX user might expect. Is there anything else the plugin should be doing?

In shortā€¦ is there anything for me to do here?

from vim-css-color.

mxw avatar mxw commented on July 18, 2024

JSX files should have javascript.jsx as the syntax. The vim runtime understands this to mean "both javascript and jsx" (this behavior isn't documented anywhere except via Google search).

If you're doing string equality comparisons against the value of the ft or filetype option, then you'll need to account for javascript.jsx specifically (and probably also jsx.javascript). If you're leveraging the vim runtime to include the appropriate files (e.g., with your after/syntax/javascript.vim), then things should Just Work.

If pangloss/vim-javascript + mxw/vim-jsx isn't giving you javascript.jsx filetypes in your *.jsx files, then either you have a very old version of the latter, or you have some other filedetect autocmds that are overriding mine.

from vim-css-color.

ap avatar ap commented on July 18, 2024

Oh hi there, @mxw.

If you're doing string equality comparisons against the value of the ft or filetype option

I donā€™t.

If pangloss/vim-javascript + mxw/vim-jsx isn't giving you javascript.jsx filetypes in your *.jsx files

It doesnā€™t. I cloned them just before writing that comment, so ā€œold versionā€ is not the explanation. Will have to investigate.

If you're leveraging the vim runtime to include the appropriate files (e.g., with your after/syntax/javascript.vim), then things should Just Work.

If I pipe my example JSX file into Vim from stdin so that Vim wonā€™t know what it is, and then set ft=javascript.jsx in that buffer manually, then all of pangloss/vim-javascript + mxw/vim-jsx + ap/vim-css-color get loaded into the buffer, and colours are highlighted just the way they get highlighted in any JS code. Soā€¦ am I done?

However, I donā€™t see any difference between set ft=javascript and set ft=javascript.jsx. Is there supposed to be? Or to ask differently, what is an example snippet where I should see a difference?


And in the same vein: is there any syntax in JSX that can contain colour references which the JS support alone doesnā€™t know to highlight? And if so, can someone here supply me a snippet of JSX which illustrates that syntax?

from vim-css-color.

mxw avatar mxw commented on July 18, 2024

If the filetype is set to javascript and not at any point to javascript.jsx (or some other filetype sequence including jsx), I would be surprised if any vim-jsx scripts ran... all the files are named jsx.vim, which to my knowledge means they are executed only if the filetype sequence includes jsx. Maybe there's some alternate dot-extension vim runtime include logic I'm not aware of?

@apā€”Is it possible you have other JS-related packages besides this one, pangloss/vim-javascript, and mxw/vim-jsx? Your package doesn't do anything complicated with filetype detection, so I don't see why the filetype would just be javascript for your *.jsx files otherwise.

Also, looking at your after/syntax/javascript.vim, it doesn't reference any pangloss/vim-javascript syntax elements (which are all called jsFooBar; yours are all javaScriptFooBar, which matches the default vim JS syntax file), so I'm guessing that (at least one) root issue here is that this package simply doesn't support coloration under pangloss/vim-javascript.

from vim-css-color.

ap avatar ap commented on July 18, 2024

OK, so I found problem #1: pangloss/vim-javascript was getting loaded, but it wasnā€™t actually running, since Vimā€™s default Javascript plugin was getting loaded first. That was caused by my handrolled plugin manager, which I fixed in ap-miscellanea/dotvim@665c5bd

But that didnā€™t fix the filetype detection! (Problem #2.) I still only get javascript in ft when I open example.jsx. I donā€™t know why yet.

I would be surprised if any vim-jsx scripts ran...

As explained ā€“ I did :set ft=javascript.jsx manually, just to see what would happen, so I could put off debugging the rest of my setup for later. And that did load vim-jsx just as youā€™d expect. But vim-jsx requires pangloss/vim-javascript, which was getting loaded but was not actually running because it was suppressed by the stock Vim Javascript plugin. So even though I could force Vim to load vim-jsx, the plugin couldnā€™t do anything useful. Now that Iā€™ve fixed my plugin precedence problems, inline markup in JSX is actually getting highlighted by vim-jsxā€¦ when I load it forcibly. (For some reason Vim still insists that JSX files are just javascript, not javascript.jsx, as I said.)

So anyway! Iā€™ve pushed 8d64e3d which adds support for pangloss/vim-javascript. And that adds support for (at least some) colouring inside JSX files as well.

Is there anything more for me to do here?

from vim-css-color.

mxw avatar mxw commented on July 18, 2024

How's this look to the users?

Those vim-javascript syntax elements look about right to me. If you want to highlight JSX attributes, you could add a jsx.vim syntax file, and turn on highlighting for the appropriate XML syntax elements (from the default xml.vim syntax file).

from vim-css-color.

ap avatar ap commented on July 18, 2024

Huh, thatā€™s a good point: I donā€™t have any XML support in css-color. If I did, it would get invoked on JSX files automatically. So Iā€™ma fix that first. And at that point, JSX support is basically there, without any explicit support for JSX as such.

Except, JSX can contain inline CSS, including function-style colour references (rgb(), rgba(), hsl()), which neither the Javascript nor the XML colour support turns on. So I actually do need explicit support for JSX, just to turn on that bit.

from vim-css-color.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.