typescript-vim icon indicating copy to clipboard operation
typescript-vim copied to clipboard

Include `jsx` in filetype when extension is `tsx`

Open chaucerbao opened this issue 7 years ago • 12 comments

Following the convention that the filetype for .jsx files is javascript.jsx, .tsx files should also include the jsx filetype.

This enables syntax highlighting for the JSX portion in .tsx files.

chaucerbao avatar Jun 09 '18 21:06 chaucerbao

@leafgarland, any thoughts on this?

chaucerbao avatar Jun 16 '18 05:06 chaucerbao

Hi @chaucerbao do you use a tsx syntax like ianks/vim-tsx? I'd like to know how this affects using, not using that.

leafgarland avatar Jun 20 '18 02:06 leafgarland

I do not use ianks/vim-tsx. I use mxw/vim-jsx which only handles the JSX fragments.

chaucerbao avatar Jun 20 '18 18:06 chaucerbao

Here's a tiny example of the typescript setup (left), versus a typescript.jsx setup (right).

jsx difference

On the left, there is minimal/basic highlighting of the JSX portion of the code, but on the right, the JSX tags and attributes are accounted for, and there is no interference with the non-JSX portions.

chaucerbao avatar Jun 20 '18 18:06 chaucerbao

I notice that ianks/vim-tsx sets the filetype to typescript.tsx

autocmd BufNewFile,BufRead *.tsx set filetype=typescript.tsx

However, I don't think tsx should be in the filetype, tsx is more like a file extension that represents "Typescript with JSX".

chaucerbao avatar Jun 20 '18 18:06 chaucerbao

@leafgarland, it looks like you've already accounted for ianks/vim-tsx with this code. I've run your plugin alone (with the JSX update), as well as both your and ianks/vim-tsx plugins together, and ianks/vim-tsx seems to take precedence when both are loaded (filetype becomes typescript.tsx).

Is that your experience as well? If so, then this update should be pretty safe.

chaucerbao avatar Jun 27 '18 05:06 chaucerbao

Nice work, thanks. I'll double check on my setup and merge if no issues.

leafgarland avatar Jun 29 '18 03:06 leafgarland

@leafgarland, have you run into any issues with this?

chaucerbao avatar Jul 18 '18 18:07 chaucerbao

ping @leafgarland @chaucerbao

bttf avatar Nov 12 '18 23:11 bttf

@bttf Not much for me to do here. Just waiting to see if the PR works for @leafgarland

chaucerbao avatar Nov 19 '18 19:11 chaucerbao

I tried this out with mxw/vim-jsx and some syntax highlighting broke. It looked like once it got inside a jsxRegion it never came out and the rest of the file had broken syntax highlighting.

It still works ok with ianks/vim-tsx and without either.

leafgarland avatar Feb 20 '19 04:02 leafgarland

Oh interesting. I've been running vim-jsx through vim-polyglot without issues for a long time. However, I just noticed that vim-polyglot has recently started using a fork since mxw/vim-jsx "appears to have been abandoned".

I imagine others would have run into the issue you're seeing, but I haven't come across any mentions of it yet, in this (current) thread, or this one

chaucerbao avatar Mar 05 '19 02:03 chaucerbao

Just cleaning up

chaucerbao avatar Aug 02 '23 01:08 chaucerbao