Skip to content

Class detection works only when strings begin and end with whitespace #372

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

Closed
michaelschufi opened this issue Jul 22, 2021 · 3 comments
Closed

Comments

@michaelschufi
Copy link

Hi

I am desperately trying to make the intellisense work with multi-line strings using the class regex setting.

Goal
I want to have all the strings in here "stringed together" in one class attribute context:

cls(
  "relative flex-1 flex flex-col max-w-xs w-full bg-indigo-700",
  "transition bg-gray-50 ease-in-out duration-300 transform",
  sidebarIsOpen ? "translate-x-0" : "-translate-x-full",
),

The problem
Using the regex

"tailwindCSS.experimental.classRegex": [
    "cls\\(([^)]*)\\)",
  ],

it only partially works.

As you can see, the suggestions for the second class, for example, works:
image

But the first and last one of the first string, does not:
image

The strings with single classes in them also don't work.

The magic trick
If I add a space to the start and the end of each string, it magically works:

image


It would be awesome if this problem could be fixed. Personally, I also don't mind the warnings, since I defined that everything inside cls(...) should be one group.

This may fix some problems other people are having coming from tailwindlabs/tailwindcss#7553.

@geekox86
Copy link

I have the same problem, though using my custom classRegex ["tw[^`]*`?", "tw`([^`]*)?"] and tw as string template literal that simply split the string classes into array.

Autocomplete works when pressing space but not enters. Please, advise.

@87vrvk9k
Copy link

Same problem here

@bradlc
Copy link
Contributor

bradlc commented Aug 13, 2021

Hey @michaelschufi. Here's a configuration that should fix your issue, and also prevent the incorrect warnings:

"tailwindCSS.experimental.classRegex": [
  ["\\bcls\\(([^)]+)\\)", "\"([^\"]*)\""]
],

With your existing configuration the set of classes is parsed as follows:

Group 1
=======
"relative
flex-1
flex
flex-col
max-w-xs
w-full
bg-indigo-700",
"transition
bg-gray-50
ease-in-out
duration-300
transform",
sidebarIsOpen
?
"translate-x-0"
:
"-translate-x-full",

With the updated configuration they are parsed like this:

Group 1
=======
relative
flex-1
flex
flex-col
max-w-xs
w-full
bg-indigo-700

Group 2
=======
transition
bg-gray-50
ease-in-out
duration-300
transform

Group 3
=======
translate-x-0

Group 4
=======
-translate-x-full

Check out my comment over on tailwindlabs/tailwindcss#7553 for more information. I hope that helps!

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

4 participants