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 @@ -9,8 +9,6 @@ import { stringToPath } from './util/stringToPath' import type { TextDocument, ColorInformation } from 'vscode-languageserver' import dlv from 'dlv' import { State } from './util/state' -import { State } from './util/state' -import { State } from './util/state' import { export async function getDocumentColors( state: State, @@ -49,5 +47,5 @@ } }) getClassNamesInClassList, - getClassNamesInClassList, +} from './util/find' } 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,15 @@ import { isCssContext, isCssDoc } from './css' import { isHtmlContext } from './html' import { isWithinRange } from './isWithinRange' import { isJsxContext } from './js' +import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' import { dedupeByRange, flatten } from './array' +import { getClassAttributeLexer, getComputedClassAttributeLexer } from './lexers' import { getClassAttributeLexer, getComputedClassAttributeLexer } from './lexers' import { getLanguageBoundaries } from './getLanguageBoundaries' import type { TextDocument, Range, Position } from 'vscode-languageserver' +import type { TextDocument, Range, Position } from 'vscode-languageserver' +import dlv from 'dlv' + classList, import type { TextDocument, Range, Position } from 'vscode-languageserver' import Regex from 'becke-ch--regex--s0-0-v1--base--pl--lib' import { getTextWithoutComments } from './doc' @@ -282,6 +287,14 @@ return result } import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' + line: globalStart.line + end.line, + return classLists.filter( + (classList, classListIndex) => + classListIndex === classLists.findIndex((c) => rangesEqual(c.range, classList.range)) + ) +} + +import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' import { isCssContext, isCssDoc } from './css' state: State, doc: TextDocument, @@ -296,7 +309,7 @@ } else { classLists = await findClassListsInHtmlRange(state, doc, mode, range) } import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' -import { getLanguageBoundaries } from './getLanguageBoundaries' +async function findCustomClassLists( ...classLists, ...(includeCustom ? await findCustomClassLists(state, doc, range) : []), ]) @@ -314,8 +327,8 @@ let boundaries = getLanguageBoundaries(state, doc) if (!boundaries) return [] import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' -import type { TextDocument, Range, Position } from 'vscode-languageserver' import { getClassAttributeLexer, getComputedClassAttributeLexer } from './lexers' +import { isJsxContext } from './js' flatten([ ...(await Promise.all( boundaries