Skip to content
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

React jsx/tsx #283

Open
zelphir opened this issue Feb 10, 2021 · 9 comments
Open

React jsx/tsx #283

zelphir opened this issue Feb 10, 2021 · 9 comments

Comments

@zelphir
Copy link

zelphir commented Feb 10, 2021

Comments using the default ft in .tsx files doesn't work, it still adds // . The only way I got it working was setting the ft to javascript.jsx, then comments were working fine for both jsx and normal js. I also tried setting the ft to javascriptreact but it didn't work either.

Screenshot 2021-02-10 at 16 42 32

Screenshot 2021-02-10 at 16 42 05

@tomtom
Copy link
Owner

tomtom commented Feb 11, 2021

Which version do you use?
Could you please provide me an code example?
I assume it uses typescriptreact (//) instead of tsx ({* ... *}).
What's the value of g:tcomment#filetype#guess? Does it help to set it to 1?
Does let g:tcomment#filetype#guess_typescriptreact = 1 help?

@tomtom
Copy link
Owner

tomtom commented Feb 11, 2021

I assume jsx works properly because the filetype is javascript.jsx and g:tcomment#filetype#guess_javascript = 1.

@zelphir
Copy link
Author

zelphir commented Feb 11, 2021

I'm of latest master (2de3885).

As code example it's just a basic react jsx but using typescript, so something like:

export default function MyComp() {  
  const data = 1

  return (
    <div>
      <span>{data}</span>
    </div>
  )
}

Running:

set ft ==> filetype=typescriptreact
let g:tcomment#filetype#guess ==> g:tcomment#filetype#guess #0 

let g:tcomment#filetype#guess_typescriptreact = 1 doesn't make any difference 😢

Forcing the filetype to typescript.tsx doesn't work either.

@kuntau
Copy link

kuntau commented Feb 15, 2021

Hi. I just encounter this issue too but setting

let g:tcomment#filetype#guess_typescriptreact = 1

solve the problem. I hope tcomment can do this automatically, the extension always *.tsx

Cheers.

@s0meone
Copy link

s0meone commented Feb 16, 2021

I'm having the same problem, setting let g:tcomment#filetype#guess_typescriptreact = 1 only works for commenting not uncommenting. I've collected some debug info on the exact same cursor position, hope this helps fixing the issue:

With let g:tcomment#filetype#guess = 0

TCOMMENT: &ft = typescriptreact => typescriptreact
TCOMMENT: stx = tsxAttrib => tsxAttrib
TCOMMENT: ct  = {'_args': {'beg': 27, 'fallbackFiletype': '', 'end': 27, 'filetype': 'typescriptreact', 'comment_mode': ''}, 'commentstring': '{/* %s */}', 'mode': '', 'filetype': 'tsx'}

With let g:tcomment#filetype#guess = 1 or let g:tcomment#filetype#guess_typescriptreact = 1 (same results), commenting works, but uncommenting doesn't:

TCOMMENT: &ft = typescriptreact => typescriptreact
TCOMMENT: stx = tsxAttrib => tsxAttrib
TCOMMENT: ct  = {'_args': {'beg': 27, 'fallbackFiletype': '', 'end': 27, 'filetype': 'typescriptreact', 'comment_mode': ''}, 'commentstring': '{/* %s */}', 'mode': '', 'filetype': 'tsx'}

With the cursor in the commented JSX code (on an attribute):

TCOMMENT: &ft = typescriptreact => typescriptreact
TCOMMENT: stx = tsxBlockComment => tsxBlockComment
TCOMMENT: ct  = {'rxmid': '', 'rxend': '', '_args': {'beg': 27, 'fallbackFiletype': '', 'end': 27, 'filetype': 'typescriptreact', 'comment_mode': ''}, 'commentstring': '// %s', 'commentstring_rx': '\%%(// %s\|/* %s */\)', 'mode': '', 'filetype': 'typescript', 'replacements': {'*/': {'subst': '|)}>#', 'guard_rx': '^\s*/\?\*'}, '/*': {'subst': '#<{(|', 'guard_rx': '^\s*/\?\*'}}, 'rxbeg': '\*\+'}

I noticed that the comment string changes to the wrong format when the cursor is in the commented block.

@gegoune
Copy link

gegoune commented Mar 19, 2021

In Vue files it also just comments every block with <!-- -->.

@eduardoarandah
Copy link

In Vue files it also just comments every block with <!-- -->.

@cloggier Posted a solution for vue here #284

@gegoune
Copy link

gegoune commented Mar 22, 2021

@eduardoarandah Thanks, I would rather keep on using treesitter.

@gegoune
Copy link

gegoune commented Mar 26, 2021

@eduardoarandah You can now use treesitter with https://github.com/JoosepAlviste/nvim-ts-context-commentstring and any commentstring based commenting plugin (I use https://github.com/terrortylor/nvim-comment).

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

No branches or pull requests

6 participants