headwind.nvim icon indicating copy to clipboard operation
headwind.nvim copied to clipboard

bug when used with classnames package

Open kyle-mccarthy opened this issue 3 years ago • 5 comments

I have a typescript file that contains a react component and one of HTML elements uses the classnames utility to manage the element's classNames property. When trying to save the component + headwind.nvim resorts the classnames, it outputs invalid JSX. (see gif)

2021-05-26 10 29 11

BTW thanks for this plugin! All the existing headwind integrations are outdated and don't work with Tailwind 2 or JIT.

kyle-mccarthy avatar May 26 '21 15:05 kyle-mccarthy

It does look like using treesitter fixes the issue; however, I haven't been using treesitter because it causes some problems that are unrelated to your plugin.

Would any of the regexes mentioned in this PR help?

kyle-mccarthy avatar May 26 '21 19:05 kyle-mccarthy

I used the wrong github account for those replies.... here they are for context.

I'll try out this scenario... are you using treesitter integration? This scenario is a little tricky using the pattern approach... I would highly recommend using the treesitter setting instead of using the pattern approach. This scenario is hard to target using lua patterns. I will add steps on how to use treesitter. If you already are using treesitter and have the parser installed, you just need to enable the treesiter flag during setup.

@kyle-mccarthy Treesitter is just a parser. It won't cause you any problems to have the parser installed. You don't have to use the any highlighting or any other plugins that use treesitter. You just need the parser for your language installed.

I think the problem here is how it calculates the range to replace... the new line is messing it up.

steelsojka avatar May 27 '21 11:05 steelsojka

Is there a new line? I think that it just wraps currently without inserting a line break.

Also to preface this, I know this isn't the right place for me get treesitter assistance but I want to explain why I haven't enabled it. My main problems with treesitter are errors when editing a file with a language (like vim) that doesn't have a parser, also, for some unknown reason, saving a file takes longer with treesitter enabled, and saving a file intermittently triggers an error and writes Error detected while processing BufWritePre Autocommands for '*'.

I haven't had the time to debug the errors further though, but since treesitter didn't exactly work out of the box I haven't been using it.

kyle-mccarthy avatar May 27 '21 17:05 kyle-mccarthy

@kyle-mccarthy You don't have to enable any highlighting module for treesitter. You can just install the parser and this plugin will use it. Treesitter does nothing on it's own. It's just an api for plugins to use. I recommend just installing the nvim-treesitter plugin and installing the parser for javascript (or typescript). You don't even need to setup the nvim-treesitter plugin. It's purely just for compiling the parser.

steelsojka avatar May 27 '21 17:05 steelsojka

Also, I think it's treating the function call as a class and that's why it's messing it up.

steelsojka avatar May 27 '21 17:05 steelsojka