Coder Social home page Coder Social logo

Better JSX / TSX support about doom-one.vim HOT 17 CLOSED

romgrk avatar romgrk commented on May 28, 2024
Better JSX / TSX support

from doom-one.vim.

Comments (17)

romgrk avatar romgrk commented on May 28, 2024 1

Right, do you think I should open an issue on vim-jsx-improve's repo?

Yes, open an issue with them let's see what they think.

font / terminal are you using

Roxterm with "SauceCodePro Nerd Font" which is the patched version of "Source Code Pro" from the nerd fonts repo.

from doom-one.vim.

romgrk avatar romgrk commented on May 28, 2024 1

I have something like this to auto-switch the filetype to what I want:

" $config_dir/after/ftplugin/javascript.vim
if &ft ==# 'javascript.jsx'
  finish
end

function! s:set_jsx()
  if &ft ==# 'javascript'
    setfiletype javascript.jsx
  end
endfunc
call timer_start(0, {->s:set_jsx()})

Note that typescriptreact is the correct FT for typescript files.

For the typescript highlights not being shown due to HTHML groups not loaded, maybe you should add something like in after/ftplugin/typescript.vim:

# pseudo-code
if not(html_is_loaded()):
  load_runtime('syntax/html.vim')

I'll close the issue because I don't see any of the behavior above being the responsability of the colorscheme, but you can re-open if you see something that should be done here.

from doom-one.vim.

romgrk avatar romgrk commented on May 28, 2024

Are you using a jsx/tsx filetype plugin? If so which one?

from doom-one.vim.

AnatoleLucet avatar AnatoleLucet commented on May 28, 2024

Yes, I'm using vim-jsx-improve
https://github.com/neoclide/vim-jsx-improve

from doom-one.vim.

romgrk avatar romgrk commented on May 28, 2024

And does other colorschemes work with JSX? Can you tell me the output of echom &filetype? Is it set to javascript.jsx, and if not does setfiletype javascript.jsx solves the issue?

from doom-one.vim.

AnatoleLucet avatar AnatoleLucet commented on May 28, 2024

And does other colorschemes work with JSX?

I've used rakr/vim-one for a long time, and it's working without any issue for jsx.

Can you tell me the output of echom &filetype

typescriptreact

Is it set to javascript.jsx, and if not does setfiletype javascript.jsx solves the issue?

No, unfortunately it doesn't.

from doom-one.vim.

romgrk avatar romgrk commented on May 28, 2024

With your cursor over one of the non-highlighted groups, run the folllowing command.

com! SynStack              call SyntaxStack()
fu! SyntaxStack() "                                                          {{{
    let synNames = []
    let lastID       = 0
    for id in synstack(line("."), col("."))
        call add(synNames, synIDattr(id, "name"))
        let lastID = id
    endfor
    if lastID == 0 | return | end
    echohl synIDattr(synIDtrans(lastID), "name")
    echon synIDattr(synIDtrans(lastID), "name")
    echon ' ' . string(synNames)
    echohl None
endfu "                                                                      }}}

from doom-one.vim.

AnatoleLucet avatar AnatoleLucet commented on May 28, 2024

With my cursor on one of the non-highlighted jsx element:

image

from doom-one.vim.

romgrk avatar romgrk commented on May 28, 2024

And is the highlighting issue fixed if you open an html file before opening a typescriptreact file? (in the same neovim instance)

from doom-one.vim.

AnatoleLucet avatar AnatoleLucet commented on May 28, 2024

yes

from doom-one.vim.

AnatoleLucet avatar AnatoleLucet commented on May 28, 2024

If I apply another scheme before this one, the jsx syntax is going to be from the other scheme.

from doom-one.vim.

romgrk avatar romgrk commented on May 28, 2024

From what I understand, this issue belongs to https://github.com/neoclide/vim-jsx-improve. The typescriptreact syntax expects other highlight groups to be defined, but those are not defined. The javascript.jsx syntax from the same repository doesn't seem to have the issue. For example jsxComponentName is correctly linked to Statement, while tsxIntrisicTagName is linked to htmlTagName. I 100% understand that they want it colored as HTML is, but they should be doing the loading if required.

It's definitely not the colorscheme's job to link htmlTagName or tsxIntrisicTagName to Statement, that's the filetype/syntax plugin's job. This should be fixed in the syntax plugin.

Open the issue with that repository to get their opinion, I might consider fixing it here if they provide a convincing reason to.

from doom-one.vim.

romgrk avatar romgrk commented on May 28, 2024

Also I don't understand why your JSX doesn't work. Mine does, I use the same plugin.
Screenshot from 2020-11-19 16-56-25

Provide more details with the above command about the jsx groups. Use verbose hi jsxXxxx to print more details where those groups were defined.

from doom-one.vim.

AnatoleLucet avatar AnatoleLucet commented on May 28, 2024

Right, do you think I should open an issue on vim-jsx-improve's repo?

Provide more details with the above command about the jsx groups. Use verbose hi jsxXxxx to print more details where those groups were defined.

Not sure if I correctly understand what you mean.
But:
image

This one is only there once I've opened an html file and the highlighting is working:
image

Totally unrelated question: what font / terminal are you using? Everything look so good and smooth compared to my vim 😄

from doom-one.vim.

kiprasmel avatar kiprasmel commented on May 28, 2024

hey lads -- I have the same issue, but for me, the following advice works:

@romgrk

And does other colorschemes work with JSX? Can you tell me the output of echom &filetype? Is it set to javascript.jsx, and if not does setfiletype javascript.jsx solves the issue?

(setting the filetype to javascript.jsx) solves the issue. Also, just renaming the file from .tsx to .jsx also works.

I tried looking for typescript-related issues in the vim-jsx-improve repo, but didn't find much:

https://github.com/neoclide/vim-jsx-improve/issues?q=is%3Aissue+sort%3Aupdated-desc+typescript

The neoclide/vim-jsx-improve#16 issue suggested some fixes, but they don't seem to help either. Any ideas?

from doom-one.vim.

romgrk avatar romgrk commented on May 28, 2024

Sorry I'm not sure I understand, is there still an issue after you set the filetype to javascript.jsx? If not, why isn't that enough?

from doom-one.vim.

kiprasmel avatar kiprasmel commented on May 28, 2024

The issue does indeed disappear when I set the filetype to javascript.jsx.

How would I do that automatically for all .tsx files, and should I do that in the first place?

from doom-one.vim.

Related Issues (14)

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.