Skip to content

Add a means to debug slow regexes #1545

@andreww2012

Description

@andreww2012

What version of VS Code are you using?

v1.108.0

What version of Tailwind CSS IntelliSense are you using?

v0.14.29

What version of Tailwind CSS are you using?

v4.1.14

What package manager are you using?

pnpm

What operating system are you using?

Windows

Tailwind CSS Stylesheet (v4) or config file (v3)

Not relevant

VS Code settings

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

Reproduction URL

N/A

Describe your issue

Hello!

Initially I added this classRegex to my VSCode settings to recognize clsx calls. However, it turned out not be ideal (was ignoring some calls) so I improved it a bit to handle my case (see "VS Code settings" above). Then I started to notice that Tailwind IntelliSense stops working in about 1 minite after Extension host is loaded. It just stucks on "Loading" when I'm hovering over any valid Tailwind class. I enabled tracing by setting "tailwindcss-intellisense.trace.server": "verbose" and noticed that I'm not receiving responses from the server. Then I basically guessed that this might be related to potential polynomial/exponential backtracking in my regex and was right. I fixed the regex with regexp/no-super-linear-backtracking ESLint rule and afrer restarting the Extension host the IL was working like a charm.

The fixed regex

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

(yes, only a siggle + sign was removed)

With that said, I'd like to propose adding a means to debug slow regexes. Maybe server response should time out after a certain period (if it's even possible to implement because regex operations are blocking)?. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions