diff --git a/packages/tailwindcss-language-service/src/documentColorProvider.ts b/packages/tailwindcss-language-service/src/documentColorProvider.ts index cab39e7e93c547b733c331fa34f64ef8cf10c2e4..dac832f646da92365e4ef4edc5844bc0e52f45a7 100644 --- a/packages/tailwindcss-language-service/src/documentColorProvider.ts +++ b/packages/tailwindcss-language-service/src/documentColorProvider.ts @@ -8,7 +8,6 @@ import { getColor, getColorFromValue, culoriColorToVscodeColor } from './util/color' import { stringToPath } from './util/stringToPath' import type { TextDocument, ColorInformation } from 'vscode-languageserver' import dlv from 'dlv' -import { dedupeByRange } from './util/array' export async function getDocumentColors( state: State, @@ -46,5 +45,5 @@ colors.push({ range: fn.ranges.path, color: culoriColorToVscodeColor(color) }) } }) - return dedupeByRange(colors) + return colors } diff --git a/packages/tailwindcss-language-service/src/util/array.ts b/packages/tailwindcss-language-service/src/util/array.ts index 0c5b5f2ed348149f3b3c0c9d3c61f72fb9d90f45..f7c16b8a3b8eee8efc35fbb9db78eb4ee33d15c3 100644 --- a/packages/tailwindcss-language-service/src/util/array.ts +++ b/packages/tailwindcss-language-service/src/util/array.ts @@ -1,19 +1,9 @@ -import type { Range } from 'vscode-languageserver' -import { rangesEqual } from './rangesEqual' - export function dedupe(arr: Array): Array { return arr.filter((value, index, self) => self.indexOf(value) === index) } export function dedupeBy(arr: Array, transform: (item: T) => any): Array { return arr.filter((value, index, self) => self.map(transform).indexOf(transform(value)) === index) -} - -export function dedupeByRange(arr: Array): Array { - return arr.filter( - (classList, classListIndex) => - classListIndex === arr.findIndex((c) => rangesEqual(c.range, classList.range)) - ) } export function ensureArray(value: T | T[]): T[] { diff --git a/packages/tailwindcss-language-service/src/util/find.ts b/packages/tailwindcss-language-service/src/util/find.ts index 8dd6ad93cad17673a1eebac6de4e6ccea88a19d2..edcb59529869ed0bbdcf4f559a5fb160300f3e71 100644 --- a/packages/tailwindcss-language-service/src/util/find.ts +++ b/packages/tailwindcss-language-service/src/util/find.ts @@ -5,10 +5,12 @@ import { isCssContext, isCssDoc } from './css' import { isHtmlContext } from './html' import { isWithinRange } from './isWithinRange' import { isJsxContext } from './js' -import { dedupeByRange, flatten } from './array' +import { flatten } from './array' import { getClassAttributeLexer, getComputedClassAttributeLexer } from './lexers' import { getLanguageBoundaries } from './getLanguageBoundaries' import { resolveRange } from './resolveRange' +import dlv from 'dlv' +import { rangesEqual } from './rangesEqual' import Regex from 'becke-ch--regex--s0-0-v1--base--pl--lib' import { getTextWithoutComments } from './doc' @@ -280,6 +282,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, @@ -293,7 +302,7 @@ classLists = findClassListsInCssRange(doc, range) } else { classLists = await findClassListsInHtmlRange(state, doc, mode, range) } - return dedupeByRange([ + return dedupeClassLists([ ...classLists, ...(includeCustom ? await findCustomClassLists(state, doc, range) : []), ]) @@ -310,7 +319,7 @@ let boundaries = getLanguageBoundaries(state, doc) if (!boundaries) return [] - return dedupeByRange( + return dedupeClassLists( flatten([ ...(await Promise.all( boundaries