3
3
import * as vscode from 'vscode'
4
4
import { dirname } from 'path'
5
5
const 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' )
7
8
const dlv = require ( 'dlv' )
8
9
const Color = require ( 'color' )
9
10
@@ -172,29 +173,55 @@ function createCompletionItemProvider({
172
173
}
173
174
}
174
175
176
+ let screens = Object . keys ( dlv ( config , 'screens' , { } ) )
177
+ let states = [ 'hover' , 'focus' , 'active' , 'group-hover' ]
178
+
175
179
if ( typeof str !== 'undefined' ) {
180
+ console . log ( str )
176
181
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.' )
178
190
. replace ( / \. $ / , '' )
179
191
. replace ( / ^ \. / , '' )
180
192
. replace ( / \. / g, '.children.' )
181
193
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
+
182
211
if ( pth !== '' ) {
183
212
const itms =
184
- prefixedItems &&
185
- str . indexOf ( '.' ) === 0 &&
186
- str . indexOf ( separator ) === - 1
213
+ prefixedItems && str . indexOf ( '.' ) === 0 && ! hasSep
187
214
? dlv ( prefixedItems , pth )
188
215
: dlv ( items , pth )
189
216
if ( itms ) {
190
- return Object . keys ( itms . children ) . map ( x => itms . children [ x ] . item )
217
+ return getItemsWithRange ( itms . children )
191
218
}
192
219
}
193
220
194
- if ( str . indexOf ( separator ) === - 1 ) {
221
+ if ( ! hasSep ) {
195
222
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 )
198
225
}
199
226
200
227
return [ ]
@@ -207,6 +234,14 @@ function createCompletionItemProvider({
207
234
)
208
235
}
209
236
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
+
210
245
function createConfigItemProvider ( {
211
246
languages,
212
247
items,
@@ -419,7 +454,7 @@ class TailwindIntellisense {
419
454
420
455
const separator = dlv ( tailwind . config , 'options.separator' , ':' )
421
456
422
- if ( separator !== ':' ) return
457
+ // if (separator !== ':') return
423
458
424
459
this . _items = createItems ( tailwind . classNames , separator , tailwind . config )
425
460
this . _prefixedItems = createItems (
0 commit comments