import postcss from "postcss" ; import tailwind from "tailwindcss" ; import { LanguageServiceContext } from "./language-service" ; const classNameRegex = /\.((?:\\:|[^:\s])+)/gi ; export async function populateCompletions ( context , configPath ) { const result = await postcss ( tailwind ( configPath ) ) . process ( `@tailwind components; @tailwind utilities;` ) ; context . completionEntries . clear ( ) ; result . root ?. walkRules ( ( rule ) => { rule . selector . match ( classNameRegex ) ?. forEach ( ( match ) => { const className = match . slice ( 1 ) . replace ( /\\/g , "" ) ; if ( className ) { addClassNameToCompletions ( className , context ) ; } } ) ; } ) ; } export function addClassNameToCompletions ( className , context ) { const parts = className . split ( ":" ) ; const variants = parts . slice ( 0 , - 1 ) ; const baseClassName = parts [ parts . length - 1 ] ; context . completionEntries . set ( baseClassName , { name : baseClassName } ) ; for ( const variant of variants ) { context . completionEntries . set ( `${ variant }:` , { name : `${ variant }:` } ) ; } }