33import * as vscode from 'vscode'
44import { dirname } from 'path'
55const htmlElements = require ( './htmlElements.js' )
6- const tailwindClassNames = require ( 'tailwind-class-names' )
6+ // const tailwindClassNames = require('tailwind-class-names')
7+ const tailwindClassNames = require ( '/Users/brad/Code/tailwind-class-names/dist' )
78const dlv = require ( 'dlv' )
89const Color = require ( 'color' )
910
@@ -172,29 +173,55 @@ function createCompletionItemProvider({
172173 }
173174 }
174175
176+ let screens = Object . keys ( dlv ( config , 'screens' , { } ) )
177+ let states = [ 'hover' , 'focus' , 'active' , 'group-hover' ]
178+
175179 if ( typeof str !== 'undefined' ) {
180+ console . log ( str )
176181 const pth = str
177- . replace ( new RegExp ( `${ separator } ` , 'g' ) , '.' )
182+ . replace (
183+ new RegExp (
184+ `^(${ [ ...screens , ...states ] . join ( '|' ) } )${ separator } ` ,
185+ 'g'
186+ ) ,
187+ '$1.'
188+ )
189+ . replace ( new RegExp ( `\\.(${ states . join ( '|' ) } )${ separator } ` ) , '.$1.' )
178190 . replace ( / \. $ / , '' )
179191 . replace ( / ^ \. / , '' )
180192 . replace ( / \. / g, '.children.' )
181193
194+ let hasSep = new RegExp (
195+ `^(${ [ ...screens , ...states ] . join ( '|' ) } )${ separator } `
196+ ) . test ( str )
197+ if ( ! hasSep && str . endsWith ( separator ) ) {
198+ // token.cancel()
199+ return getItemsWithRange (
200+ items ,
201+ new vscode . Range ( position . translate ( 0 , - str . length ) , position )
202+ )
203+ let mobNav = new vscode . CompletionItem (
204+ 'mob-nav-' ,
205+ vscode . CompletionItemKind . Constant
206+ )
207+ mobNav . range = new vscode . Range ( position . translate ( 0 , - 4 ) , position )
208+ return [ mobNav ]
209+ }
210+
182211 if ( pth !== '' ) {
183212 const itms =
184- prefixedItems &&
185- str . indexOf ( '.' ) === 0 &&
186- str . indexOf ( separator ) === - 1
213+ prefixedItems && str . indexOf ( '.' ) === 0 && ! hasSep
187214 ? dlv ( prefixedItems , pth )
188215 : dlv ( items , pth )
189216 if ( itms ) {
190- return Object . keys ( itms . children ) . map ( x => itms . children [ x ] . item )
217+ return getItemsWithRange ( itms . children )
191218 }
192219 }
193220
194- if ( str . indexOf ( separator ) === - 1 ) {
221+ if ( ! hasSep ) {
195222 return prefixedItems && str . indexOf ( '.' ) === 0
196- ? Object . keys ( prefixedItems ) . map ( x => prefixedItems [ x ] . item )
197- : Object . keys ( items ) . map ( x => items [ x ] . item )
223+ ? getItemsWithRange ( prefixedItems )
224+ : getItemsWithRange ( items )
198225 }
199226
200227 return [ ]
@@ -207,6 +234,14 @@ function createCompletionItemProvider({
207234 )
208235}
209236
237+ function getItemsWithRange ( items , range : vscode . Range = undefined ) {
238+ return Object . keys ( items ) . map ( x => {
239+ let i = items [ x ] . item
240+ i . range = range
241+ return i
242+ } )
243+ }
244+
210245function createConfigItemProvider ( {
211246 languages,
212247 items,
@@ -419,7 +454,7 @@ class TailwindIntellisense {
419454
420455 const separator = dlv ( tailwind . config , 'options.separator' , ':' )
421456
422- if ( separator !== ':' ) return
457+ // if (separator !== ':') return
423458
424459 this . _items = createItems ( tailwind . classNames , separator , tailwind . config )
425460 this . _prefixedItems = createItems (
0 commit comments