1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
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,
@@ -290,7 +298,10 @@ classLists = findClassListsInCssRange(doc, range)
} else {
classLists = await findClassListsInHtmlRange(state, doc, range)
}
- return [...classLists, ...(includeCustom ? await findCustomClassLists(state, doc, range) : [])]
+ return dedupeClassLists([
+ ...classLists,
+ ...(includeCustom ? await findCustomClassLists(state, doc, range) : []),
+ ])
}
export async function findClassListsInDocument(
@@ -304,17 +315,19 @@
let boundaries = getLanguageBoundaries(state, doc)
if (!boundaries) return []
- return flatten([
- ...(await Promise.all(
- boundaries
- .filter((b) => b.type === 'html' || b.type === 'jsx')
- .map(({ range }) => findClassListsInHtmlRange(state, doc, range))
- )),
- ...boundaries
- .filter((b) => b.type === 'css')
- .map(({ range }) => findClassListsInCssRange(doc, range)),
- await findCustomClassLists(state, doc),
- ])
+ return dedupeClassLists(
+ flatten([
+ ...(await Promise.all(
+ boundaries
+ .filter((b) => b.type === 'html' || b.type === 'jsx')
+ .map(({ range }) => findClassListsInHtmlRange(state, doc, range))
+ )),
+ ...boundaries
+ .filter((b) => b.type === 'css')
+ .map(({ range }) => findClassListsInCssRange(doc, range)),
+ await findCustomClassLists(state, doc),
+ ])
+ )
}
export function findHelperFunctionsInDocument(
|