Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
update custom regex support (#129) fixes "ors" in regexes
Brad Cornes <bradlc41@gmail.com>
4 years ago
1 changed files, 60 additions(+), 8 deletions(-)
M packages/tailwindcss-language-service/src/completionProvider.ts -> packages/tailwindcss-language-service/src/completionProvider.ts
diff --git a/packages/tailwindcss-language-service/src/completionProvider.ts b/packages/tailwindcss-language-service/src/completionProvider.ts
index 825a2e334412bea16ebd4e5e37b1b5a087005d55..6aa6d24f3d50ad353acf2173cb140d53484f1cf9 100644
--- a/packages/tailwindcss-language-service/src/completionProvider.ts
+++ b/packages/tailwindcss-language-service/src/completionProvider.ts
@@ -197,6 +197,62 @@
   return null
 }
 
+function createMultiRegexp(regexString: string) {
+  let insideCharClass = false
+  let captureGroupIndex = -1
+
+  for (let i = 0; i < regexString.length; i++) {
+    if (
+      !insideCharClass &&
+      regexString[i] === '[' &&
+      regexString[i - 1] !== '\\'
+    ) {
+      insideCharClass = true
+    } else if (
+      insideCharClass &&
+      regexString[i] === ']' &&
+      regexString[i - 1] !== '\\'
+    ) {
+      insideCharClass = false
+    } else if (
+      !insideCharClass &&
+      regexString[i] === '(' &&
+      regexString.substr(i + 1, 2) !== '?:'
+    ) {
+      captureGroupIndex = i
+      break
+    }
+  }
+
+  const re = /(?:[^\\]|^)\(\?:/g
+  let match: RegExpExecArray
+  let nonCaptureGroupIndexes: number[] = []
+
+  while ((match = re.exec(regexString)) !== null) {
+    if (match[0].startsWith('(')) {
+      nonCaptureGroupIndexes.push(match.index)
+    } else {
+      nonCaptureGroupIndexes.push(match.index + 1)
+    }
+  }
+
+  const regex = new MultiRegexp(
+    new RegExp(
+      regexString.replace(re, (m) => m.substr(0, m.length - 2)),
+      'g'
+    )
+  )
+
+  let groupIndex =
+    1 + nonCaptureGroupIndexes.filter((i) => i < captureGroupIndex).length
+
+  return {
+    exec: (str: string) => {
+      return regex.execForGroup(str, groupIndex)
+    },
+  }
+}
+
 async function provideCustomClassNameCompletions(
   state: State,
   document: TextDocument,
@@ -221,11 +277,11 @@       let [containerRegex, classRegex] = Array.isArray(regexes[i])
         ? regexes[i]
         : [regexes[i]]
 
-import { stringifyScreen, Screen } from './util/screens'
   Range,
+  }
       let containerMatch
 
-import { stringifyScreen, Screen } from './util/screens'
+    },
   CompletionList,
         const searchStart = document.offsetAt(searchRange.start)
         const matchStart = searchStart + containerMatch.start
@@ -235,17 +291,13 @@         if (cursor >= matchStart && cursor <= matchEnd) {
           let classList
 
           if (classRegex) {
-import isObject from './util/isObject'
   Range,
+    let keys = parts.slice(0, i).filter(Boolean)
             let classMatch
 
             while (
-              (classMatch = classRegex.execForGroup(
-import { State } from './util/state'
+    },
   Position,
-  Position,
-                1
-              )) !== null
             ) {
               const classMatchStart = matchStart + classMatch.start
               const classMatchEnd = matchStart + classMatch.end