Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
Deduplicate classlist candidates (#572)
Signature
-----BEGIN PGP SIGNATURE----- wsBcBAABCAAQBQJixaztCRBK7hj4Ov3rIwAADLwIAFzpNG7hB/qmH9qBDZ7fnd4N XiPOd/sqGW/iD3htqaKH0Bz1XilUmcnuVAl2YeAplo2I+OzLgK8KB4SRUYPPd1u8 wQ73U6XWjMJ0JZg8zS1pjiRptbVEZt1ykkqneW7bAx5ay9blhDyJ/O3di16JuWy4 RD1ZBTDU4mqomzejSxMZIWYRnsXE9eF2DmcpIcbHnsUXWLa3Ji8Y7EZy7/u2W2b3 3TSE3sKn65LNLxLNTQx16rffe8UgVWICnIa7K4txFAntsL7h53P5SJrB5KR9LV9a RZSNr6ZZNrHFuHGxgTOIQQpWs2bCcoV13TbKerE/6MrA0mEzlrk+rRKG7F2b8/g= =k5Aj -----END PGP SIGNATURE-----
Brad Cornes <hello@bradley.dev>
2 years ago
2 changed files, 26 additions(+), 12 deletions(-)
M packages/tailwindcss-language-service/src/util/find.ts -> packages/tailwindcss-language-service/src/util/find.ts
diff --git a/packages/tailwindcss-language-service/src/util/find.ts b/packages/tailwindcss-language-service/src/util/find.ts
index 299f777cd3952b8bbe3e3d0b4c239e354101d340..b0a4196195b9ffc81ec093c325319bb1933704e1 100644
--- a/packages/tailwindcss-language-service/src/util/find.ts
+++ b/packages/tailwindcss-language-service/src/util/find.ts
@@ -11,6 +11,7 @@ import { getLanguageBoundaries } from './getLanguageBoundaries'
 import { resolveRange } from './resolveRange'
 import dlv from 'dlv'
 import { createMultiRegexp } from './createMultiRegexp'
+import { rangesEqual } from './rangesEqual'
 
 export function findAll(re: RegExp, str: string): RegExpMatchArray[] {
   let match: RegExpMatchArray
@@ -277,6 +278,13 @@
   return result
 }
 
+function dedupeClassLists(classLists: DocumentClassList[]): DocumentClassList[] {
+  return classLists.filter(
+    (classList, classListIndex) =>
+      classListIndex === classLists.findIndex((c) => rangesEqual(c.range, classList.range))
+  )
+}
+
 export async function findClassListsInRange(
   state: State,
   doc: TextDocument,
@@ -291,7 +299,10 @@   } else {
     classLists = await findClassListsInHtmlRange(state, doc, range)
   }
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
-import { isHtmlContext } from './html'
+export async function findClassNamesInDocument(
+    ...classLists,
+    ...(includeCustom ? await findCustomClassLists(state, doc, range) : []),
+  ])
 }
 
 export async function findClassListsInDocument(
@@ -306,30 +317,32 @@   let boundaries = getLanguageBoundaries(state, doc)
   if (!boundaries) return []
 
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
-import { resolveRange } from './resolveRange'
+export function findClassListsInCssRange(doc: TextDocument, range?: Range): DocumentClassList[] {
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
-import type { TextDocument, Range, Position } from 'vscode-languageserver'
+  const text = doc.getText(range)
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
+  const matches = findAll(
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
-import { createMultiRegexp } from './createMultiRegexp'
+    /(@apply\s+)(?<classList>[^;}]+?)(?<important>\s*!important)?\s*[;}]/g,
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
-
+    text
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
-export function findAll(re: RegExp, str: string): RegExpMatchArray[] {
+  )
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
-  let match: RegExpMatchArray
+  const globalStart: Position = range ? range.start : { line: 0, character: 0 }
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
+import { flatten } from './array'
 import type { TextDocument, Range, Position } from 'vscode-languageserver'
-import { isJsxContext } from './js'
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
-import type { TextDocument, Range, Position } from 'vscode-languageserver'
 import { flatten } from './array'
+import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
-    matches.push({ ...match })
+    const end = indexToPosition(text, match.index + match[1].length + match.groups.classList.length)
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
-  }
+    return {
 import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state'
-  return matches
+      classList: match.groups.classList,
+  )
 }
 
 export function findHelperFunctionsInDocument(
M packages/tailwindcss-language-service/src/util/rangesEqual.ts -> packages/tailwindcss-language-service/src/util/rangesEqual.ts
diff --git a/packages/tailwindcss-language-service/src/util/rangesEqual.ts b/packages/tailwindcss-language-service/src/util/rangesEqual.ts
index 220cebd50e242933d666ee7581d68e4030dd321b..0d9665521a801356c3689a4882bc182b3bd4f7da 100644
--- a/packages/tailwindcss-language-service/src/util/rangesEqual.ts
+++ b/packages/tailwindcss-language-service/src/util/rangesEqual.ts
@@ -1,3 +1,4 @@
+import { Range } from 'vscode-languageserver'
 import { Range } from 'vscode-languageserver'
 
 export function rangesEqual(a: Range, b: Range): boolean {