@@ -36,7 +36,7 @@ import { Codicon } from 'vs/base/common/codicons';
36
36
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar' ;
37
37
38
38
export const Context = {
39
- Visible : new RawContextKey < boolean > ( 'CodeActionMenuVisible ' , false , localize ( 'CodeActionMenuVisible ' , "Whether the code action list widget is visible" ) )
39
+ Visible : new RawContextKey < boolean > ( 'codeActionMenuVisible ' , false , localize ( 'codeActionMenuVisible ' , "Whether the code action list widget is visible" ) )
40
40
} ;
41
41
42
42
interface CodeActionWidgetDelegate {
@@ -304,6 +304,15 @@ export class CodeActionMenu extends Disposable implements IEditorContribution {
304
304
} ) ;
305
305
}
306
306
307
+ /**
308
+ * Checks if the setting has disabled/enabled headers in the code action widget.
309
+ */
310
+ private isCodeActionWidgetHeadersDisabled ( model : ITextModel ) : boolean {
311
+ return this . _configurationService . getValue ( 'editor.experimental.useCustomCodeActionMenu.toggleHeaders' , {
312
+ resource : model . uri
313
+ } ) ;
314
+ }
315
+
307
316
private _onListSelection ( e : IListEvent < ICodeActionMenuItem > ) : void {
308
317
if ( e . elements . length ) {
309
318
e . elements . forEach ( element => {
@@ -422,81 +431,95 @@ export class CodeActionMenu extends Disposable implements IEditorContribution {
422
431
renderDisposables . add ( this . codeActionList . value . onDidChangeSelection ( e => this . _onListSelection ( e ) ) ) ;
423
432
renderDisposables . add ( this . _editor . onDidLayoutChange ( ( ) => this . hideCodeActionWidget ( ) ) ) ;
424
433
425
- // Filters and groups code actions by their group
426
- const menuEntries : IAction [ ] [ ] = [ ] ;
427
-
428
- // Code Action Groups
429
- const quickfixGroup : IAction [ ] = [ ] ;
430
- const extractGroup : IAction [ ] = [ ] ;
431
- const convertGroup : IAction [ ] = [ ] ;
432
- const surroundGroup : IAction [ ] = [ ] ;
433
- const sourceGroup : IAction [ ] = [ ] ;
434
- const separatorGroup : IAction [ ] = [ ] ;
435
- const documentationGroup : IAction [ ] = [ ] ;
436
- const otherGroup : IAction [ ] = [ ] ;
437
-
438
- inputArray . forEach ( ( item ) => {
439
- if ( item instanceof CodeActionAction ) {
440
- const optionKind = item . action . kind ;
441
-
442
- if ( CodeActionKind . SurroundWith . contains ( new CodeActionKind ( String ( optionKind ) ) ) ) {
443
- surroundGroup . push ( item ) ;
444
- } else if ( CodeActionKind . QuickFix . contains ( new CodeActionKind ( String ( optionKind ) ) ) ) {
445
- quickfixGroup . push ( item ) ;
446
- } else if ( CodeActionKind . Extract . contains ( new CodeActionKind ( String ( optionKind ) ) ) ) {
447
- extractGroup . push ( item ) ;
448
- } else if ( CodeActionKind . Convert . contains ( new CodeActionKind ( String ( optionKind ) ) ) ) {
449
- convertGroup . push ( item ) ;
450
- } else if ( CodeActionKind . Source . contains ( new CodeActionKind ( String ( optionKind ) ) ) ) {
451
- sourceGroup . push ( item ) ;
452
- } else if ( optionKind === CodeActionMenu . documentationID ) {
453
- documentationGroup . push ( item ) ;
454
- } else {
455
- // Pushes all the other actions to the "Other" group
456
- otherGroup . push ( item ) ;
457
- }
458
-
459
- } else if ( item . id === `vs.actions.separator` ) {
460
- separatorGroup . push ( item ) ;
461
- }
462
- } ) ;
434
+ const model = this . _editor . getModel ( ) ;
463
435
464
- menuEntries . push ( quickfixGroup , extractGroup , convertGroup , surroundGroup , sourceGroup , otherGroup , separatorGroup , documentationGroup ) ;
436
+ if ( ! model ) {
437
+ return renderDisposables ;
438
+ }
465
439
466
- const menuEntriesToPush = ( menuID : string , entry : IAction [ ] ) => {
467
- totalActionEntries . push ( menuID ) ;
468
- totalActionEntries . push ( ...entry ) ;
469
- numHeaders ++ ;
470
- } ;
471
- // Creates flat list of all menu entries with headers as separators
472
440
let numHeaders = 0 ;
473
441
const totalActionEntries : ( IAction | string ) [ ] = [ ] ;
474
- menuEntries . forEach ( entry => {
475
- if ( entry . length > 0 && entry [ 0 ] instanceof CodeActionAction ) {
476
- const firstAction = entry [ 0 ] . action . kind ;
477
- if ( CodeActionKind . SurroundWith . contains ( new CodeActionKind ( String ( firstAction ) ) ) ) {
478
- menuEntriesToPush ( localize ( 'codeAction.widget.id.surround' , 'Surround With...' ) , entry ) ;
479
- } else if ( CodeActionKind . QuickFix . contains ( new CodeActionKind ( String ( firstAction ) ) ) ) {
480
- menuEntriesToPush ( localize ( 'codeAction.widget.id.quickfix' , 'Quick Fix...' ) , entry ) ;
481
- } else if ( CodeActionKind . Extract . contains ( new CodeActionKind ( String ( firstAction ) ) ) ) {
482
- menuEntriesToPush ( localize ( 'codeAction.widget.id.extract' , 'Extract...' ) , entry ) ;
483
- } else if ( CodeActionKind . Convert . contains ( new CodeActionKind ( String ( firstAction ) ) ) ) {
484
- menuEntriesToPush ( localize ( 'codeAction.widget.id.convert' , 'Convert...' ) , entry ) ;
485
- } else if ( CodeActionKind . Source . contains ( new CodeActionKind ( String ( firstAction ) ) ) ) {
486
- menuEntriesToPush ( localize ( 'codeAction.widget.id.source' , 'Source Action...' ) , entry ) ;
487
-
488
- } else if ( firstAction === CodeActionMenu . documentationID ) {
489
- totalActionEntries . push ( ...entry ) ;
490
- } else {
491
- // Takes and flattens all the `other` actions
492
- menuEntriesToPush ( localize ( 'codeAction.widget.id.more' , 'More Actions...' ) , entry ) ;
442
+
443
+ // Checks if headers are disabled.
444
+ if ( this . isCodeActionWidgetHeadersDisabled ( model ) ) {
445
+ totalActionEntries . push ( ...inputArray ) ;
446
+
447
+ } else {
448
+ // Filters and groups code actions by their group
449
+ const menuEntries : IAction [ ] [ ] = [ ] ;
450
+
451
+ // Code Action Groups
452
+ const quickfixGroup : IAction [ ] = [ ] ;
453
+ const extractGroup : IAction [ ] = [ ] ;
454
+ const convertGroup : IAction [ ] = [ ] ;
455
+ const surroundGroup : IAction [ ] = [ ] ;
456
+ const sourceGroup : IAction [ ] = [ ] ;
457
+ const separatorGroup : IAction [ ] = [ ] ;
458
+ const documentationGroup : IAction [ ] = [ ] ;
459
+ const otherGroup : IAction [ ] = [ ] ;
460
+
461
+ inputArray . forEach ( ( item ) => {
462
+ if ( item instanceof CodeActionAction ) {
463
+ const optionKind = item . action . kind ;
464
+
465
+ if ( CodeActionKind . SurroundWith . contains ( new CodeActionKind ( String ( optionKind ) ) ) ) {
466
+ surroundGroup . push ( item ) ;
467
+ } else if ( CodeActionKind . QuickFix . contains ( new CodeActionKind ( String ( optionKind ) ) ) ) {
468
+ quickfixGroup . push ( item ) ;
469
+ } else if ( CodeActionKind . Extract . contains ( new CodeActionKind ( String ( optionKind ) ) ) ) {
470
+ extractGroup . push ( item ) ;
471
+ } else if ( CodeActionKind . Convert . contains ( new CodeActionKind ( String ( optionKind ) ) ) ) {
472
+ convertGroup . push ( item ) ;
473
+ } else if ( CodeActionKind . Source . contains ( new CodeActionKind ( String ( optionKind ) ) ) ) {
474
+ sourceGroup . push ( item ) ;
475
+ } else if ( optionKind === CodeActionMenu . documentationID ) {
476
+ documentationGroup . push ( item ) ;
477
+ } else {
478
+ // Pushes all the other actions to the "Other" group
479
+ otherGroup . push ( item ) ;
480
+ }
481
+
482
+ } else if ( item . id === `vs.actions.separator` ) {
483
+ separatorGroup . push ( item ) ;
493
484
}
494
- } else {
495
- // case for separator - separators are not codeActionAction typed
485
+ } ) ;
486
+
487
+ menuEntries . push ( quickfixGroup , extractGroup , convertGroup , surroundGroup , sourceGroup , otherGroup , separatorGroup , documentationGroup ) ;
488
+
489
+ const menuEntriesToPush = ( menuID : string , entry : IAction [ ] ) => {
490
+ totalActionEntries . push ( menuID ) ;
496
491
totalActionEntries . push ( ...entry ) ;
497
- }
492
+ numHeaders ++ ;
493
+ } ;
494
+ // Creates flat list of all menu entries with headers as separators
495
+ menuEntries . forEach ( entry => {
496
+ if ( entry . length > 0 && entry [ 0 ] instanceof CodeActionAction ) {
497
+ const firstAction = entry [ 0 ] . action . kind ;
498
+ if ( CodeActionKind . SurroundWith . contains ( new CodeActionKind ( String ( firstAction ) ) ) ) {
499
+ menuEntriesToPush ( localize ( 'codeAction.widget.id.surround' , 'Surround With...' ) , entry ) ;
500
+ } else if ( CodeActionKind . QuickFix . contains ( new CodeActionKind ( String ( firstAction ) ) ) ) {
501
+ menuEntriesToPush ( localize ( 'codeAction.widget.id.quickfix' , 'Quick Fix...' ) , entry ) ;
502
+ } else if ( CodeActionKind . Extract . contains ( new CodeActionKind ( String ( firstAction ) ) ) ) {
503
+ menuEntriesToPush ( localize ( 'codeAction.widget.id.extract' , 'Extract...' ) , entry ) ;
504
+ } else if ( CodeActionKind . Convert . contains ( new CodeActionKind ( String ( firstAction ) ) ) ) {
505
+ menuEntriesToPush ( localize ( 'codeAction.widget.id.convert' , 'Convert...' ) , entry ) ;
506
+ } else if ( CodeActionKind . Source . contains ( new CodeActionKind ( String ( firstAction ) ) ) ) {
507
+ menuEntriesToPush ( localize ( 'codeAction.widget.id.source' , 'Source Action...' ) , entry ) ;
508
+
509
+ } else if ( firstAction === CodeActionMenu . documentationID ) {
510
+ totalActionEntries . push ( ...entry ) ;
511
+ } else {
512
+ // Takes and flattens all the `other` actions
513
+ menuEntriesToPush ( localize ( 'codeAction.widget.id.more' , 'More Actions...' ) , entry ) ;
514
+ }
515
+ } else {
516
+ // case for separator - separators are not codeActionAction typed
517
+ totalActionEntries . push ( ...entry ) ;
518
+ }
498
519
499
- } ) ;
520
+ } ) ;
521
+
522
+ }
500
523
501
524
// Populating the list widget and tracking enabled options.
502
525
totalActionEntries . forEach ( ( item , index ) => {
0 commit comments