@@ -8,26 +8,57 @@ namespace ts.codefix {
88 const token = getTokenAtPosition ( sourceFile , start ) ;
99 const checker = context . program . getTypeChecker ( ) ;
1010
11- if ( token . kind === SyntaxKind . Identifier && isClassLike ( token . parent ) ) {
12- const classDeclaration = < ClassDeclaration > token . parent ;
13- const startPos : number = classDeclaration . members . pos ;
11+ if ( ! ( token . kind === SyntaxKind . Identifier && isClassLike ( token . parent ) ) ) {
12+ return undefined ;
13+ }
14+ const classDecl = < ClassDeclaration > token . parent ;
15+ const startPos : number = classDecl . members . pos ;
16+
17+ const implementedTypeNodes = getClassImplementsHeritageClauseElements ( classDecl ) ;
18+ const implementedTypes = implementedTypeNodes . map ( checker . getTypeFromTypeReference ) ;
19+ const resolvedImplementedTypes = implementedTypes . map ( checker . resolveStructuredTypeMembers ) ;
20+
21+ let result : CodeAction [ ] | undefined = undefined ;
22+
23+ for ( const resolvedType of resolvedImplementedTypes ) {
24+ const insertion = getMissingMembersInsertion ( classDecl , resolvedType , checker , context . newLineCharacter ) ;
25+ result = pushAction ( insertion , getLocaleSpecificMessage ( Diagnostics . Implement_interface_on_class ) , result ) ;
26+ }
27+
28+ // TODO: (arozga) Get this working and figure out how to test it reliably.
29+ /*
30+ // If there are multiple objects, we additionally try to generate a combined fix that simultaneously implements all types.
31+ const intersectionType = checker.getIntersectionType(implementedTypes);
32+ if(intersectionType.flags & TypeFlags.Intersection) {
33+ const resolvedIntersectionType = checker.resolveStructuredTypeMembers(<IntersectionType>intersectionType)
34+ const insertion = getMissingMembersInsertion(classDecl, resolvedIntersectionType, checker, context.newLineCharacter);
35+ result = pushAction(insertion, "stubbed locale message", result)
36+ }
37+ */
1438
15- const insertion = getMissingInterfaceMembersInsertion ( classDeclaration , checker , context . newLineCharacter ) ;
39+ return result ;
1640
41+ function pushAction ( insertion : string , description : string , result ?: CodeAction [ ] ) : CodeAction [ ] {
1742 if ( insertion && insertion . length ) {
18- return [ {
19- description : getLocaleSpecificMessage ( Diagnostics . Implement_interface_on_class ) ,
43+ const newAction : CodeAction = {
44+ description : description ,
2045 changes : [ {
2146 fileName : sourceFile . fileName ,
2247 textChanges : [ {
2348 span : { start : startPos , length : 0 } ,
2449 newText : insertion
2550 } ]
2651 } ]
27- } ] ;
52+ } ;
53+ if ( result ) {
54+ result . push ( newAction ) ;
55+ }
56+ else {
57+ result = [ newAction ] ;
58+ }
2859 }
60+ return result ;
2961 }
30- return undefined ;
3162 }
3263 } ) ;
3364}
0 commit comments