Skip to content

Include jsx in filetype when extension is tsx #140

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

Closed
wants to merge 1 commit into from

Conversation

chaucerbao
Copy link
Contributor

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
Copy link
Contributor Author

@leafgarland, any thoughts on this?

@leafgarland
Copy link
Owner

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

@chaucerbao
Copy link
Contributor Author

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

@chaucerbao
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

@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.

@leafgarland
Copy link
Owner

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

@chaucerbao
Copy link
Contributor Author

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

@bttf
Copy link

bttf commented Nov 12, 2018

ping @leafgarland @chaucerbao

@chaucerbao
Copy link
Contributor Author

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

@leafgarland
Copy link
Owner

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.

@chaucerbao
Copy link
Contributor Author

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
Copy link
Contributor Author

Just cleaning up

@chaucerbao chaucerbao closed this Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants