tomtom / tcomment_vim

An extensible & universal comment vim-plugin that also handles embedded filetypes

Home Page:http://www.vim.org/scripts/script.php?script_id=1173

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't uncomment HTML in JSX files

kkoomen opened this issue · comments

No matter which keystroke I use, I can't uncomment HTML in JSX files.

tcomment-jsx-uncomment-bug

Could you please tell me, at each step, the result of :call tcomment#debug#CollectInfo() at the beginning of the line in question. Thanks.

| = cursor

Scenario

import React, { Component } from 'react';

class Test extends Component {
  render() {
    return (
      |<div className="Test" />
    );
  }
}

export default Test;

Debug

TCOMMENT: &ft = javascript.jsx
TCOMMENT: ft  = javascript.jsx
TCOMMENT: stx = jsx
TCOMMENT: ct  = {'commentstring': '{/* %s */}', 'mode': '', 'filetype': 'jsx'}

Scenario (pressed gcc)

import React, { Component } from 'react';

class Test extends Component {
  render() {
    return (
      |{/* <div className="Test" /> */}
    );
  }
}

export default Test;

Debug


TCOMMENT: &ft = javascript.jsx
TCOMMENT: ft  = javascript.jsx
TCOMMENT: stx = javascriptObjectBraces
TCOMMENT: ct  = {'rxmid': '', 'rxend': '', 'commentstring': '// %s', 'commentstring_rx': '\%%(// %s\|/* %s */\)', 'mode': '', 'filetype': 'javascript', 'replacements': {'*/': {'subst': '|)}>#', 'guard_rx': '^\s*/\?\*'}, '/*': {'subst': '#<{(|', 'guard_rx': '^\s*/\?\*'}}, 'rxbeg': '\*\+'}

I think this should already give you enough information.

BTW what software did you use to create the screencast?

@tomtom It does makes sense, but here's the thing: JSX should use {/* ... /*} only when the cursor is in or surrounded by HTML. When the cursor is at a location which is just javascript, it should just the // plain javascript syntax. Will you fix this? Because you closed this issue without reason.


I used Kap to record a part of the screen.

@tomtom I pulled from master and this is indeed fixed. Thanks!

@tomtom thanks for another improvement!
This has been bugging me since you last made the improvements that made commenting work well (thanks!), which sadly revealed the uncommenting to still be troublesome. I felt guilty continuously asking for improvements, when you'd already been responsive and helpful, and decided to wait until it bugged me enough to open a PR. I see it's already picked up! Thanks for that!

Sadly, this doesn't seem to be working for me. Can we reopen?
Version is 46d8351, which is master as of right now.
Keystrokes are: gcc gcc g<c g<c
Debug info for each step, starting with the state before any commenting is:

TCOMMENT: &ft = javascript.jsx
TCOMMENT: ft  = javascript.jsx
TCOMMENT: stx = jsx
TCOMMENT: ct  = {'commentstring': '{/* %s */}', 'commentstring_rx': '\%%(// %s\|{/* %s */}\)', 'mode': '', 'filetype': 'jsx'}
TCOMMENT: &ft = javascript.jsx
TCOMMENT: ft  = javascript.jsx
TCOMMENT: stx = javascriptBraces
TCOMMENT: ct  = {'rxmid': '', 'rxend': '', 'commentstring': '// %s', 'commentstring_rx': '\%%(// %s\|/* %s */\)', 'mode': '', 'filetype': 'javascript', 'replacements': {'*/': {'subst': '|)}>#', 'guard_rx': '^\s*/\?\*'}, '/*': {'subst': '#<{(|', 'guard_rx': '^\s*/\?\*'}}, 'rxbeg': '\*\+'}

TCOMMENT: &ft = javascript.jsx
TCOMMENT: ft  = javascript.jsx
TCOMMENT: stx = jsxRegion
TCOMMENT: ct  = {'commentstring': '{/* %s */}', 'commentstring_rx': '\%%(// %s\|{/* %s */}\)', 'mode': '', 'filetype': 'jsx'}

comment-jsx-1

Same for tsx files.

Let me know if I can be of any more help!

@kkoomen this Kap thing is neat by the way. If I can ever offer you a hot thank you beverage of choice let me know!

demo-tcomment-working

@alextes I am on 46d8351 as well now and this is what I have ^ -- which works as expected, so re-opening is not needed I suppose. Do you have neovim?

@kkoomen yup, neovim, I'll try and rule out plugins.

othree/yajs.vim and mxw/vim-jsx together break this. Thanks for the hint kkoomen. I'll see if I can solve it. Mind telling me what you use for JSX highlighting in the meantime?

Yup, certain @tomtom , but a friendly person already pointed out it's plugins interfering. To be specific ohtree/yajs.vim doesn't assign a jsx syntax group but a JS one. I'll link the issue when I get around to creating it.

@alextes I had some issues once using vim-jsx before, but they seem to be solved.

I am using vim-polyglot these days which supports a massive amount of languages to get a good syntax highlighting. It is an up-to-date repository. I do recommend to use this rather then scraping your own packages of the internet ;)

Recently I've come across the same issue. Except that I've tried pretty much every jsx syntax plugin and it still gives me the behavior described by OP. Using vim-polyglot doesn't work either. If this is an issue with the jsx syntax plugins and not related to tcomment please let me know and I'll open an issue in the correct repo. I'll post the result of tcomment#debug#CollectInfo() when trying to uncomment JSX if it's of any help. I'm using a .js file, but the behavior using .jsx / .tsx is the same.

TCOMMENT: &ft = javascript => javascript
TCOMMENT: stx = jsxElement => jsxElement
TCOMMENT: ct  = {'rxmid': '', 'rxend': '', 'commentstring': '// %s', 'commentstring_rx': '\%%(// %s\|/* %s */\)', 'mode': '', 'filetype': 'javascript', 'replacements': {'*/': {'subst': '|)}>#', 'guard_rx': '^\s*/\?\*'}, '/*': {'subst': '#<{(|', 'guard_rx': '^\s*/\?\*'}}, 'rxbeg': '\*\+'}

I'm sorry but I cannot follow the thread that closely. Could you please describe exactly what you're trying to achieve. JSX files seem to work fine with the default vim plugins. But I don't do jsx and I need some help to find out what's going wrong.

It would also help if you installed tlib and the run Tlibtraceset --file=tcomment.log +tcommentas described in :help tcomment-debug.

@tomtom It's the same issue with uncommenting discussed earlier (gif originally by alextes):

comment-jsx-1

Here's the output of running Tlibtraceset --file=tcomment.log +tcomment: https://pastebin.com/pQd00zqV

As of jsx-plugins I'm using vim-polyglot but I've used pretty much all of jsx plugins available right now and the issue still persists.