@@ -24,7 +24,7 @@ namespace ts {
24
24
}
25
25
26
26
export namespace codefix {
27
- const codeFixRegistrations : CodeFixRegistration [ ] [ ] = [ ] ;
27
+ const errorCodeToFixes = createMultiMap < CodeFixRegistration > ( ) ;
28
28
const fixIdToRegistration = createMap < CodeFixRegistration > ( ) ;
29
29
30
30
type DiagnosticAndArguments = DiagnosticMessage | [ DiagnosticMessage , string ] | [ DiagnosticMessage , string , string ] ;
@@ -48,12 +48,7 @@ namespace ts {
48
48
49
49
export function registerCodeFix ( reg : CodeFixRegistration ) {
50
50
for ( const error of reg . errorCodes ) {
51
- let registrations = codeFixRegistrations [ error ] ;
52
- if ( ! registrations ) {
53
- registrations = [ ] ;
54
- codeFixRegistrations [ error ] = registrations ;
55
- }
56
- registrations . push ( reg ) ;
51
+ errorCodeToFixes . add ( String ( error ) , reg ) ;
57
52
}
58
53
if ( reg . fixIds ) {
59
54
for ( const fixId of reg . fixIds ) {
@@ -63,29 +58,12 @@ namespace ts {
63
58
}
64
59
}
65
60
66
- export function getSupportedErrorCodes ( ) {
67
- return Object . keys ( codeFixRegistrations ) ;
61
+ export function getSupportedErrorCodes ( ) : string [ ] {
62
+ return arrayFrom ( errorCodeToFixes . keys ( ) ) ;
68
63
}
69
64
70
65
export function getFixes ( context : CodeFixContext ) : CodeFixAction [ ] {
71
- const fixes = codeFixRegistrations [ context . errorCode ] ;
72
- const allActions : CodeFixAction [ ] = [ ] ;
73
-
74
- forEach ( fixes , f => {
75
- const actions = f . getCodeActions ( context ) ;
76
- if ( actions && actions . length > 0 ) {
77
- for ( const action of actions ) {
78
- if ( action === undefined ) {
79
- context . host . log ( `Action for error code ${ context . errorCode } added an invalid action entry; please log a bug` ) ;
80
- }
81
- else {
82
- allActions . push ( action ) ;
83
- }
84
- }
85
- }
86
- } ) ;
87
-
88
- return allActions ;
66
+ return flatMap ( errorCodeToFixes . get ( String ( context . errorCode ) ) || emptyArray , f => f . getCodeActions ( context ) ) ;
89
67
}
90
68
91
69
export function getAllFixes ( context : CodeFixAllContext ) : CombinedCodeActions {
0 commit comments