Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
Improve extraction for variable colors (#638)
Signature
-----BEGIN PGP SIGNATURE----- wsBcBAABCAAQBQJjUTggCRBK7hj4Ov3rIwAAsLUIAJSVkldYxqZzz6iQ30jqQe48 TG90di9rtOBolEUcHAgAeO3Punx+cKVJZzTzwFPAiu+q3a6Wexo76sGjAWSqqFM0 DoWnuw67PoiuVeu4qJGtOm/EyRoxmQ9bowIO2KS/CSKKudh6bgZl3cGv077p/cE+ ujaha70VwCea25LXar7SQrmfHVjzcTq2DfYF+hTtzyS1ngty1NTDjHJaADB5m4eH /LKEv5IvxbNWw/ENsPm5TAY+tOH+NgvG3XfY+2k8qpoy3XuE3wfn8KpASLM45i5Q e2xpzprCiF5NxVXNydkUexoW8wRfMTdV1qUn/8/pX8Kt15unt8EmqCT7otNIC24= =wLaE -----END PGP SIGNATURE-----
Brad Cornes <hello@bradley.dev>
2 years ago
1 changed files, 8 additions(+), 2 deletions(-)
M packages/tailwindcss-language-service/src/util/color.ts -> packages/tailwindcss-language-service/src/util/color.ts
diff --git a/packages/tailwindcss-language-service/src/util/color.ts b/packages/tailwindcss-language-service/src/util/color.ts
index 8334a180d2594f43233b4ceb938feac4974cf701..b7b55ca6e3a5bfe3b2b725a80d9000e463cbd576 100644
--- a/packages/tailwindcss-language-service/src/util/color.ts
+++ b/packages/tailwindcss-language-service/src/util/color.ts
@@ -42,16 +42,22 @@ }
 
 // https://github.com/khalilgharbaoui/coloregex
 const colorRegex = new RegExp(
-  `(?:^|\\s|\\(|,)(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\\((-?[\\d.]+%?(\\s*[,/]\\s*|\\s+)+){2,3}\\s*([\\d.]+%?|var\\([^)]+\\))?\\)|transparent|currentColor|${Object.keys(
+  `(?:^|\\s|\\(|,)(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\\(\\s*(-?[\\d.]+%?(\\s*[,/]\\s*|\\s+)+){2,3}\\s*([\\d.]+%?|var\\([^)]+\\))?\\)|transparent|currentColor|${Object.keys(
     namedColors
   ).join('|')})(?:$|\\s|\\)|,)`,
   'gi'
 )
 
+function replaceColorVarsWithTheirDefaults(str: string): string {
+  // rgb(var(--primary, 66 66 66))
+  // -> rgb(66 66 66)
+  return str.replace(/((?:rgb|hsl)a?\(\s*)var\([^,]+,\s*([^)]+)\)/gi, '$1$2')
+}
+
 function getColorsInString(str: string): (culori.Color | KeywordColor)[] {
   if (/(?:box|drop)-shadow/.test(str)) return []
 
-  return Array.from(str.matchAll(colorRegex), (match) => {
+  return Array.from(replaceColorVarsWithTheirDefaults(str).matchAll(colorRegex), (match) => {
     let color = match[1].replace(/var\([^)]+\)/, '1')
     return getKeywordColor(color) ?? culori.parse(color)
   }).filter(Boolean)