Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
classRegex: increase search range, make search global (#129)
Brad Cornes <bradlc41@gmail.com>
4 years ago
1 changed files, 49 additions(+), 40 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 0ba869c889e75e4ebfd6c23c17698c104fdd3475..0cdff6335af81f60c4e76a8d6a187c71a1d6fa36 100644
--- a/packages/tailwindcss-language-service/src/completionProvider.ts
+++ b/packages/tailwindcss-language-service/src/completionProvider.ts
@@ -205,56 +205,65 @@   const settings = await getDocumentSettings(state, document)
   const regexes = dlv(settings, 'experimental.classRegex', [])
   if (regexes.length === 0) return null
 
-  const searchRange = {
-    start: { line: Math.max(position.line - 10, 0), character: 0 },
-    end: { line: position.line + 10, character: 0 },
+  const positionOffset = document.offsetAt(position)
+
+  const searchRange: Range = {
+    start: document.positionAt(Math.max(0, positionOffset - 500)),
+    end: document.positionAt(positionOffset + 500),
   }
 
   let str = document.getText(searchRange)
 
   for (let i = 0; i < regexes.length; i++) {
-    let [containerRegex, classRegex] = Array.isArray(regexes[i])
-      ? regexes[i]
-      : [regexes[i]]
-    containerRegex = new MultiRegexp(new RegExp(containerRegex))
     try {
-      const match = containerRegex.execForGroup(str, 1)
-      if (match === null) {
-        throw Error()
-      }
-      const searchStart = document.offsetAt(searchRange.start)
-      const matchStart = searchStart + match.start
-      const matchEnd = searchStart + match.end
-      const cursor = document.offsetAt(position)
-      if (cursor >= matchStart && cursor <= matchEnd) {
-        let classList
+      let [containerRegex, classRegex] = Array.isArray(regexes[i])
+        ? regexes[i]
+        : [regexes[i]]
+
+      containerRegex = new MultiRegexp(new RegExp(containerRegex, 'g'))
+      let containerMatch
+
+      while ((containerMatch = containerRegex.execForGroup(str, 1)) !== null) {
+        console.log(containerMatch)
+        const searchStart = document.offsetAt(searchRange.start)
+        const matchStart = searchStart + containerMatch.start
+        const matchEnd = searchStart + containerMatch.end
+        const cursor = document.offsetAt(position)
+        if (cursor >= matchStart && cursor <= matchEnd) {
+          let classList
+
+          if (classRegex) {
+            classRegex = new MultiRegexp(new RegExp(classRegex, 'g'))
+            let classMatch
+
+            while (
+              (classMatch = classRegex.execForGroup(
+                containerMatch.match,
+                1
+              )) !== null
+            ) {
+              const classMatchStart = matchStart + classMatch.start
+              const classMatchEnd = matchStart + classMatch.end
+              if (cursor >= classMatchStart && cursor <= classMatchEnd) {
+                classList = classMatch.match.substr(0, cursor - classMatchStart)
+              }
+            }
 
-        if (classRegex) {
-          classRegex = new MultiRegexp(new RegExp(classRegex, 'g'))
-          let classMatch
-          while (
-            (classMatch = classRegex.execForGroup(match.match, 1)) !== null
-          ) {
-            const classMatchStart = matchStart + classMatch.start
-            const classMatchEnd = matchStart + classMatch.end
-            if (cursor >= classMatchStart && cursor <= classMatchEnd) {
-              classList = classMatch.match.substr(0, cursor - classMatchStart)
+            if (typeof classList === 'undefined') {
+              throw Error()
             }
-          }
-          if (typeof classList === 'undefined') {
-            throw Error()
+          } else {
+            classList = containerMatch.match.substr(0, cursor - matchStart)
           }
-        } else {
-          classList = match.match.substr(0, cursor - matchStart)
-        }
 
-        return completionsFromClassList(state, classList, {
-          start: {
-            line: position.line,
-            character: position.character - classList.length,
-          },
-          end: position,
-        })
+          return completionsFromClassList(state, classList, {
+            start: {
+              line: position.line,
+              character: position.character - classList.length,
+            },
+            end: position,
+          })
+        }
       }
     } catch (_) {}
   }