@@ -24,7 +24,7 @@ const HTML_TYPES = [
24
24
'nunjucks' ,
25
25
'haml'
26
26
]
27
- const CSS_TYPES = [ 'css' , 'sass' , 'scss' , 'less' , 'postcss' , ' stylus']
27
+ const CSS_TYPES = [ 'css' , 'sass' , 'scss' , 'less' , 'stylus' ]
28
28
29
29
export async function activate ( context : vscode . ExtensionContext ) {
30
30
let tw
@@ -103,15 +103,16 @@ export function deactivate() {}
103
103
104
104
function createCompletionItemProvider ( {
105
105
items,
106
+ prefixedItems,
106
107
languages,
107
108
regex,
108
109
triggerCharacters,
109
110
config,
110
- prefix = '' ,
111
111
enable = ( ) => true ,
112
112
emmet = false
113
113
} : {
114
114
items ?
115
+ prefixedItems ?
115
116
languages ?: string [ ]
116
117
regex ?: RegExp
117
118
triggerCharacters ?: string [ ]
@@ -177,14 +178,21 @@ function createCompletionItemProvider({
177
178
. replace ( / \. / g, '.children.' )
178
179
179
180
if ( pth !== '' ) {
180
- const itms = dlv ( items , pth )
181
+ const itms =
182
+ prefixedItems &&
183
+ str . indexOf ( '.' ) === 0 &&
184
+ str . indexOf ( separator ) === - 1
185
+ ? dlv ( prefixedItems , pth )
186
+ : dlv ( items , pth )
181
187
if ( itms ) {
182
- return prefixItems ( itms . children , str , prefix )
188
+ return Object . keys ( itms . children ) . map ( x => itms . children [ x ] . item )
183
189
}
184
190
}
185
191
186
192
if ( str . indexOf ( separator ) === - 1 ) {
187
- return prefixItems ( items , str , prefix )
193
+ return prefixedItems && str . indexOf ( '.' ) === 0
194
+ ? Object . keys ( prefixedItems ) . map ( x => prefixedItems [ x ] . item )
195
+ : Object . keys ( items ) . map ( x => items [ x ] . item )
188
196
}
189
197
190
198
return [ ]
@@ -282,7 +290,7 @@ function depthOf(obj) {
282
290
return level
283
291
}
284
292
285
- function createItems ( classNames , separator , config , parent = '' ) {
293
+ function createItems ( classNames , separator , config , prefix = '' , parent = '' ) {
286
294
let items = { }
287
295
let i = 0
288
296
@@ -292,6 +300,7 @@ function createItems(classNames, separator, config, parent = '') {
292
300
key ,
293
301
vscode . CompletionItemKind . Constant
294
302
)
303
+ item . filterText = item . insertText = `${ prefix } ${ key } `
295
304
item . sortText = naturalExpand ( i . toString ( ) )
296
305
if ( key !== 'container' && key !== 'group' ) {
297
306
if ( parent ) {
@@ -318,6 +327,7 @@ function createItems(classNames, separator, config, parent = '') {
318
327
`${ key } ${ separator } ` ,
319
328
vscode . CompletionItemKind . Constant
320
329
)
330
+ item . filterText = item . insertText = `${ prefix } ${ key } ${ separator } `
321
331
item . sortText = naturalExpand ( i . toString ( ) )
322
332
item . command = { title : '' , command : 'editor.action.triggerSuggest' }
323
333
if ( key === 'hover' || key === 'focus' || key === 'active' ) {
@@ -335,7 +345,7 @@ function createItems(classNames, separator, config, parent = '') {
335
345
}
336
346
items [ key ] = {
337
347
item,
338
- children : createItems ( classNames [ key ] , separator , config , key )
348
+ children : createItems ( classNames [ key ] , separator , config , prefix , key )
339
349
}
340
350
i ++
341
351
}
@@ -391,6 +401,7 @@ class TailwindIntellisense {
391
401
private _disposable : vscode . Disposable
392
402
private _tailwind
393
403
private _items
404
+ private _prefixedItems
394
405
private _configItems
395
406
private _prefixedConfigItems
396
407
@@ -409,6 +420,12 @@ class TailwindIntellisense {
409
420
if ( separator !== ':' ) return
410
421
411
422
this . _items = createItems ( tailwind . classNames , separator , tailwind . config )
423
+ this . _prefixedItems = createItems (
424
+ tailwind . classNames ,
425
+ separator ,
426
+ tailwind . config ,
427
+ '.'
428
+ )
412
429
this . _configItems = createConfigItems ( tailwind . config )
413
430
this . _prefixedConfigItems = createConfigItems ( tailwind . config , '.' )
414
431
@@ -427,11 +444,21 @@ class TailwindIntellisense {
427
444
this . _providers . push (
428
445
createCompletionItemProvider ( {
429
446
items : this . _items ,
447
+ prefixedItems : this . _prefixedItems ,
430
448
languages : CSS_TYPES ,
431
449
regex : / @ a p p l y ( [ ^ ; } ] * ) $ / ,
432
450
triggerCharacters : [ '.' , separator ] ,
433
- config : tailwind . config ,
434
- prefix : '.'
451
+ config : tailwind . config
452
+ } )
453
+ )
454
+ this . _providers . push (
455
+ createCompletionItemProvider ( {
456
+ items : this . _items ,
457
+ prefixedItems : this . _items ,
458
+ languages : [ 'postcss' ] ,
459
+ regex : / @ a p p l y ( [ ^ ; } ] * ) $ / ,
460
+ triggerCharacters : [ '.' , separator ] ,
461
+ config : tailwind . config
435
462
} )
436
463
)
437
464
@@ -538,6 +565,12 @@ class TailwindIntellisense {
538
565
items : this . _prefixedConfigItems
539
566
} )
540
567
)
568
+ this . _providers . push (
569
+ createConfigItemProvider ( {
570
+ languages : [ 'postcss' ] ,
571
+ items : this . _configItems
572
+ } )
573
+ )
541
574
542
575
this . _providers . push (
543
576
createConfigItemProvider ( {
0 commit comments