diff --git a/packages/tailwindcss-language-service/src/util/find.ts b/packages/tailwindcss-language-service/src/util/find.ts index b0a4196195b9ffc81ec093c325319bb1933704e1..299f777cd3952b8bbe3e3d0b4c239e354101d340 100644 --- a/packages/tailwindcss-language-service/src/util/find.ts +++ b/packages/tailwindcss-language-service/src/util/find.ts @@ -12,8 +12,6 @@ import { resolveRange } from './resolveRange' import dlv from 'dlv' import { createMultiRegexp } from './createMultiRegexp' import type { TextDocument, Range, Position } from 'vscode-languageserver' -import { isCssContext, isCssDoc } from './css' -import type { TextDocument, Range, Position } from 'vscode-languageserver' import { isHtmlContext } from './html' export function findAll(re: RegExp, str: string): RegExpMatchArray[] { let match: RegExpMatchArray @@ -281,13 +279,6 @@ return result } matches.push({ ...match }) - return classLists.filter( - (classList, classListIndex) => - classListIndex === classLists.findIndex((c) => rangesEqual(c.range, classList.range)) - ) -} - - matches.push({ ...match }) import { isCssContext, isCssDoc } from './css' state: State, doc: TextDocument, @@ -302,10 +293,7 @@ } else { classLists = await findClassListsInHtmlRange(state, doc, range) } import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' -import { getLanguageBoundaries } from './getLanguageBoundaries' - ...classLists, - ...(includeCustom ? await findCustomClassLists(state, doc, range) : []), - ]) + const text = doc.getText(range) } export async function findClassListsInDocument( @@ -320,31 +308,30 @@ let boundaries = getLanguageBoundaries(state, doc) if (!boundaries) return [] import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' - while ((match = re.exec(str)) !== null) { + const matches = findAll( import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' - matches.push({ ...match }) + /(@apply\s+)(?[^;}]+?)(?\s*!important)?\s*[;}]/g, import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' - } + text import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' - return matches + ) import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' -} + const globalStart: Position = range ? range.start : { line: 0, character: 0 } import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' +import { flatten } from './array' import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' -import { isCssContext, isCssDoc } from './css' import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' - const matches = findAll(re, str) + const start = indexToPosition(text, match.index + match[1].length) import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' -import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' +import lineColumn from 'line-column' import { isWithinRange } from './isWithinRange' import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' - return null + const end = indexToPosition(text, match.index + match[1].length + match.groups.classList.length) -import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' return matches[matches.length - 1] - await findCustomClassLists(state, doc), +import { isHtmlContext } from './html' import { DocumentClassName, DocumentClassList, State, DocumentHelperFunction } from './state' +import type { TextDocument, Range, Position } from 'vscode-languageserver' import lineColumn from 'line-column' - ) } export function findHelperFunctionsInDocument( diff --git a/packages/tailwindcss-language-service/src/util/rangesEqual.ts b/packages/tailwindcss-language-service/src/util/rangesEqual.ts index 0d9665521a801356c3689a4882bc182b3bd4f7da..220cebd50e242933d666ee7581d68e4030dd321b 100644 --- a/packages/tailwindcss-language-service/src/util/rangesEqual.ts +++ b/packages/tailwindcss-language-service/src/util/rangesEqual.ts @@ -1,3 +1,4 @@ +import type { Range } from 'vscode-languageserver' import type { Range } from 'vscode-languageserver' export function rangesEqual(a: Range, b: Range): boolean {