heybourn / headwind

An opinionated Tailwind CSS class sorter built for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=heybourn.headwind
MIT License
1.38k stars 46 forks source link

Support for scala files? #96

Closed hth2 closed 3 years ago

hth2 commented 3 years ago

My typical scala code looks as follows:

  sb(modal)(
    doApply("fixed left-0 top-0 w-full h-full z-10")
  )

I tried to add the following to headwind.classRegex these lines

        "scala": "\\B@doApply\\(\"([_a-zA-Z0-9\\s\\-\\:\\/]+)\"\\)",
        "plaintext": "\\B@doApply\\(\"([_a-zA-Z0-9\\s\\-\\:\\/]+)\"\\)",

but it doesn't seem to work. Headwind works properly for css files. I have the official scala plugin installed, and restarted vs code after changing the settings.

Any hint what I can try?

heybourn commented 3 years ago

Are you sure that regex is correct? Looping in @praveenperera for this one.

hth2 commented 3 years ago

I derived the pattern from the existing patterns for other languages.

Now I have tested in nodejs and it seems correct:

> r = new RegExp("\\B@doApply\\(\"([_a-zA-Z0-9\\s\\-\\:\\/]+)\"\\)")
/\B@doApply\("([_a-zA-Z0-9\s\-\:\/]+)"\)/

> r.test('@doApply("fixed left-0 top-0 w-full h-full z-10")')
true

> '@doApply("fixed left-0 top-0 w-full h-full z-10")'.match(r)
[
  '@doApply("fixed left-0 top-0 w-full h-full z-10")',
  'fixed left-0 top-0 w-full h-full z-10',
  index: 0,
  input: '@doApply("fixed left-0 top-0 w-full h-full z-10")',
  groups: undefined
]
>
imjoshellis commented 3 years ago
"scala": "\\B@doApply\\(\"([_a-zA-Z0-9\\s\\-\\:\\/]+)\"\\)"

Works fine for me in a .scala file, including sorting and removing duplicates.

Input

 sb(modal)(
    @doApply("left-0 fixed left-0 top-0 w-full h-full z-10")
  )

Output

  sb(modal)(
    @doApply("fixed top-0 left-0 z-10 w-full h-full")
  )

In your original post, you don't have an @ before doApply.

I'm not a Scala programmer, so I have no idea which syntax is correct, but to make the regex work, it requires the @ before doApply. Otherwise, remove the @ from the regex.

I know this issue is old, but I hope this helps.

hth2 commented 3 years ago

thank you for your comment.

Indeed I messed it up with the @ char. Now I removed it from the regex (and reload) but still it doesn't work for scala & plaintext. Most likely I missed something, but could not figure it out after lot of attempts. Will give another try later.

imjoshellis commented 3 years ago

Now I removed it from the regex (and reload) but still it doesn't work for scala & plaintext.

After commenting, I noticed I was having weird issues getting the regex to load correctly after changing it.

Not sure what is happening, but I agree there was something going on that makes adjusting the regex config unreliable.