@@ -431,6 +431,81 @@ class TailwindIntellisense {
431
431
432
432
this . _providers = [ ]
433
433
434
+ this . _providers . push (
435
+ vscode . commands . registerCommand (
436
+ 'tailwind.refactor-class-names' ,
437
+ ( document , range ) => {
438
+ let original = document . getText ( range )
439
+
440
+ let order = [
441
+ 'hover' ,
442
+ 'group-hover' ,
443
+ 'active' ,
444
+ 'focus' ,
445
+ 'sm' ,
446
+ 'md' ,
447
+ 'lg' ,
448
+ 'xl'
449
+ ]
450
+
451
+ let next = original
452
+ . split ( / \s + / )
453
+ . sort ( ( a , b ) => {
454
+ let aPrefix = a . match ( / ^ ( [ ^ : ] + ) : / )
455
+ let bPrefix = b . match ( / ^ ( [ ^ : ] + ) : / )
456
+ if ( ! aPrefix && bPrefix ) return - 1
457
+ if ( ! bPrefix && aPrefix ) return 1
458
+ if ( ! aPrefix && ! bPrefix ) return 0
459
+ // at this point they both have a prefix
460
+ aPrefix = aPrefix [ 1 ]
461
+ bPrefix = bPrefix [ 1 ]
462
+
463
+ if ( aPrefix === bPrefix ) return 0
464
+
465
+ if (
466
+ order . indexOf ( aPrefix ) === - 1 &&
467
+ order . indexOf ( bPrefix ) === - 1
468
+ )
469
+ return 0
470
+ if (
471
+ order . indexOf ( aPrefix ) !== - 1 &&
472
+ order . indexOf ( bPrefix ) === - 1
473
+ )
474
+ return - 1
475
+ if (
476
+ order . indexOf ( bPrefix ) !== - 1 &&
477
+ order . indexOf ( aPrefix ) === - 1
478
+ )
479
+ return 1
480
+
481
+ return order . indexOf ( aPrefix ) - order . indexOf ( bPrefix )
482
+ } )
483
+ . join ( ' ' )
484
+
485
+ let edit = new vscode . WorkspaceEdit ( )
486
+ edit . replace ( document . uri , range , next )
487
+ vscode . workspace . applyEdit ( edit )
488
+ }
489
+ )
490
+ )
491
+
492
+ this . _providers . push (
493
+ vscode . languages . registerCodeActionsProvider ( HTML_TYPES , {
494
+ provideCodeActions ( document , range ) {
495
+ let action = new vscode . CodeAction (
496
+ 'Arrange class names' ,
497
+ vscode . CodeActionKind . Refactor
498
+ )
499
+ action . command = {
500
+ title : 'refactor-class-names' ,
501
+ command : 'tailwind.refactor-class-names' ,
502
+ arguments : [ document , range ]
503
+ }
504
+ return [ action ]
505
+ }
506
+ } )
507
+ )
508
+
434
509
this . _providers . push (
435
510
createCompletionItemProvider ( {
436
511
items : this . _items ,
0 commit comments