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

IntelliSense in VS Code gives suggestions outside strings #229

Open
bradleyayers opened this issue Dec 3, 2024 · 2 comments
Open

IntelliSense in VS Code gives suggestions outside strings #229

bradleyayers opened this issue Dec 3, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@bradleyayers
Copy link

bradleyayers commented Dec 3, 2024

Describe the bug
When I type else { I get a suggestion {}-[], and when I press enter it's accepted and I end up with else {}-[].

To Reproduce
Steps to reproduce the behavior:

Create a .ts file with:

const response = await fetch(`https://raw.githubusercontent.com/foo/bar-baz/refs/heads/master/readme.txt`);

if (true) 

Then after the if (true) type {

Expected behavior
No auto complete

Screenshots

image

Desktop (please complete the following information):

  • VS Code + Tailwind CSS IntelliSense extension

Additional context

I've tracked it down to the regex suggested in https://www.tailwind-variants.org/docs/getting-started

{
  "tailwindCSS.experimental.classRegex": [
    ["([\"'`][^\"'`]*.*?[\"'`])", "[\"'`]([^\"'`]*).*?[\"'`]"]
  ]
}

Instead I'm now using this (but it's too early to tell if it's good)

{
  "tailwindCSS.experimental.classRegex": [
    ["(`.*?`)", "(\".*?\")", "('.*?')"],
  ]
}
@bradleyayers bradleyayers added the bug Something isn't working label Dec 3, 2024
@iangrayhazzard
Copy link

iangrayhazzard commented Dec 30, 2024

Doesn't the suggested regex also start autocompleting tailwind classes inside any string in the document? I'd suggest we make it tv() specific, like clsx and cva:

["tv\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]

@EthanBarlo
Copy link

This seems to work best for me.
First it limits the scope within the tv({}) object,
Then it will give IntelliSense to any quoted ("", '', ``) string within that object.

"tailwindCSS.experimental.classRegex": [
   ["tv\\(\\{([\\s\\S]*?)\\}\\)", "['\"`]([^'\"`]*)['\"`]"]
]

Since we're scoping it to the tv({}) object it means nothing else within the project should have random IntelliSense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants