Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
Fix IntelliSense when separator is `--` (#628) * Fix IntelliSense when separator is `--` * Tidy up
Signature
-----BEGIN PGP SIGNATURE----- wsBcBAABCAAQBQJjR8r3CRBK7hj4Ov3rIwAAk3UIALJmGGXCCy58xyrxRx0IPMuU GE4WewEA9ShyMzQsVPLaYfyM/wPy3f7kYWujIQF8cISn47mVB5eC1VnqKgOebDYO tf3ZlzP1qNvN7w3MEVO7/8IHqaZj6La7Zm0+eHq9X8uP7jSbKhTBQ3BGgFiFMGyS pnlkq2bJg0HnNmpD62rBmmfh1F5MJP8GrGjsw7oboPZCNiGQwV/ncrh1pxuATVjx vNNt9ih9TlYaXJNJq4df4fdIdNnZP+UyKHasg+W5j5Y6ToGPR0N58uvCh+9Uv3fT nWxxWDQHDbNbugCS9Khcd41OkBqiwS25II7lr5iL5ployk2z7H+84BkYsIaBf5o= =Pldg -----END PGP SIGNATURE-----
Brad Cornes <hello@bradley.dev>
2 years ago
2 changed files, 27 additions(+), 56 deletions(-)
M packages/tailwindcss-language-server/src/server.ts -> packages/tailwindcss-language-server/src/server.ts
diff --git a/packages/tailwindcss-language-server/src/server.ts b/packages/tailwindcss-language-server/src/server.ts
index 15d1900718a734e3701f979434ff7480448c4c58..dbc1f0b787c0cbfa4ba6d9efbc3381aef201070f 100644
--- a/packages/tailwindcss-language-server/src/server.ts
+++ b/packages/tailwindcss-language-server/src/server.ts
@@ -1504,7 +1504,10 @@       documentSelector: null,
       resolveProvider: true,
       triggerCharacters: [
         ...TRIGGER_CHARACTERS,
-        ...projects.map((project) => project.state.separator).filter(Boolean),
+        ...projects
+          .map((project) => project.state.separator)
+          .filter((sep) => typeof sep === 'string')
+          .map((sep) => sep.slice(-1)),
       ].filter(Boolean),
     })
 
M packages/tailwindcss-language-service/src/util/getVariantsFromClassName.ts -> packages/tailwindcss-language-service/src/util/getVariantsFromClassName.ts
diff --git a/packages/tailwindcss-language-service/src/util/getVariantsFromClassName.ts b/packages/tailwindcss-language-service/src/util/getVariantsFromClassName.ts
index 795569ed5202ba470be1a7c17afdacdd60b2686a..10dfe90c7cf4d353d820a43f32ed880f5fc490c8 100644
--- a/packages/tailwindcss-language-service/src/util/getVariantsFromClassName.ts
+++ b/packages/tailwindcss-language-service/src/util/getVariantsFromClassName.ts
@@ -6,7 +6,7 @@   state: State,
   className: string
 ): { variants: string[]; offset: number } {
   let allVariants = Object.keys(state.variants)
-  let parts = Array.from(splitAtTopLevelOnly(className, state.separator)).filter(Boolean)
+  let parts = splitAtTopLevelOnly(className, state.separator).filter(Boolean)
   let variants = new Set<string>()
   let offset = 0
 
@@ -29,66 +29,34 @@
   return { variants: Array.from(variants), offset }
 }
 
-const REGEX_SPECIAL = /[\\^$.*+?()[\]{}|]/g
-const REGEX_HAS_SPECIAL = RegExp(REGEX_SPECIAL.source)
-
-function regexEscape(string: string): string {
-  return string && REGEX_HAS_SPECIAL.test(string)
-    ? string.replace(REGEX_SPECIAL, '\\$&')
-    : string || ''
-}
-
-function* splitAtTopLevelOnly(input: string, separator: string): Generator<string> {
-  let SPECIALS = new RegExp(`[(){}\\[\\]${regexEscape(separator)}]`, 'g')
+// https://github.com/tailwindlabs/tailwindcss/blob/a8a2e2a7191fbd4bee044523aecbade5823a8664/src/util/splitAtTopLevelOnly.js
+function splitAtTopLevelOnly(input: string, separator: string): string[] {
+  let stack: string[] = []
+  let parts: string[] = []
+  let lastPos = 0
 
-  let depth = 0
-  let lastIndex = 0
-  let found = false
-  let separatorIndex = 0
-  let separatorStart = 0
-  let separatorLength = separator.length
-
-  // Find all paren-like things & character
-  // And only split on commas if they're top-level
-  for (let match of input.matchAll(SPECIALS)) {
-    let matchesSeparator = match[0] === separator[separatorIndex]
-    let atEndOfSeparator = separatorIndex === separatorLength - 1
-    let matchesFullSeparator = matchesSeparator && atEndOfSeparator
-
-    if (match[0] === '(') depth++
-    if (match[0] === ')') depth--
-    if (match[0] === '[') depth++
-    if (match[0] === ']') depth--
-    if (match[0] === '{') depth++
-    if (match[0] === '}') depth--
+  for (let idx = 0; idx < input.length; idx++) {
+    let char = input[idx]
 
-    if (matchesSeparator && depth === 0) {
-      if (separatorStart === 0) {
-        separatorStart = match.index
+    if (stack.length === 0 && char === separator[0]) {
+      if (separator.length === 1 || input.slice(idx, idx + separator.length) === separator) {
+        parts.push(input.slice(lastPos, idx))
+        lastPos = idx + separator.length
       }
-
-      separatorIndex++
     }
 
-    if (matchesFullSeparator && depth === 0) {
-      found = true
-
-      yield input.substring(lastIndex, separatorStart)
-      lastIndex = separatorStart + separatorLength
-    }
-
-    if (separatorIndex === separatorLength) {
-      separatorIndex = 0
-      separatorStart = 0
+    if (char === '(' || char === '[' || char === '{') {
+      stack.push(char)
+    } else if (
+      (char === ')' && stack[stack.length - 1] === '(') ||
+      (char === ']' && stack[stack.length - 1] === '[') ||
+      (char === '}' && stack[stack.length - 1] === '{')
+    ) {
+      stack.pop()
     }
   }
 
-  // Provide the last segment of the string if available
-  // Otherwise the whole string since no `char`s were found
-  // This mirrors the behavior of string.split()
-  if (found) {
-    yield input.substring(lastIndex)
-  } else {
-    yield input
-  }
+  parts.push(input.slice(lastPos))
+
+  return parts
 }