@@ -19,7 +19,7 @@ namespace ts.codefix {
19
19
errorCodes,
20
20
getCodeActions ( context ) {
21
21
const typeChecker = context . program . getTypeChecker ( ) ;
22
- const info = getInfo ( context . sourceFile , context . span . start , context . errorCode , typeChecker , context . program ) ;
22
+ const info = getInfo ( context . sourceFile , context . span . start , context . errorCode , typeChecker , context . program , context . formatContext ) ;
23
23
if ( ! info ) {
24
24
return undefined ;
25
25
}
@@ -50,7 +50,7 @@ namespace ts.codefix {
50
50
51
51
return createCombinedCodeActions ( textChanges . ChangeTracker . with ( context , changes => {
52
52
eachDiagnostic ( context , errorCodes , diag => {
53
- const info = getInfo ( diag . file , diag . start , diag . code , checker , context . program ) ;
53
+ const info = getInfo ( diag . file , diag . start , diag . code , checker , context . program , context . formatContext ) ;
54
54
if ( ! info || ! addToSeen ( seen , getNodeId ( info . parentDeclaration ) + "#" + info . token . text ) ) {
55
55
return ;
56
56
}
@@ -141,6 +141,7 @@ namespace ts.codefix {
141
141
readonly properties : Symbol [ ] ;
142
142
readonly parentDeclaration : ObjectLiteralExpression ;
143
143
readonly indentation ?: number ;
144
+ readonly trimLeadingWhiteSpaces ?: boolean ;
144
145
}
145
146
146
147
interface JsxAttributesInfo {
@@ -150,7 +151,7 @@ namespace ts.codefix {
150
151
readonly parentDeclaration : JsxOpeningLikeElement ;
151
152
}
152
153
153
- function getInfo ( sourceFile : SourceFile , tokenPos : number , errorCode : number , checker : TypeChecker , program : Program ) : Info | undefined {
154
+ function getInfo ( sourceFile : SourceFile , tokenPos : number , errorCode : number , checker : TypeChecker , program : Program , formatContext : formatting . FormatContext ) : Info | undefined {
154
155
// The identifier of the missing property. eg:
155
156
// this.missing = 1;
156
157
// ^^^^^^^
@@ -171,7 +172,10 @@ namespace ts.codefix {
171
172
172
173
const properties = arrayFrom ( checker . getUnmatchedProperties ( checker . getTypeAtLocation ( parent ) , checker . getTypeAtLocation ( param ) , /* requireOptionalProperties */ false , /* matchDiscriminantProperties */ false ) ) ;
173
174
if ( ! length ( properties ) ) return undefined ;
174
- return { kind : InfoKind . ObjectLiteral , token : param . name , properties, indentation : 0 , parentDeclaration : parent } ;
175
+
176
+ const formatOptions = getFormatCodeSettingsForWriting ( formatContext , sourceFile ) ;
177
+ const indentation = formatting . SmartIndenter . getIndentation ( getLineStartPositionForPosition ( tokenPos , sourceFile ) , sourceFile , formatOptions , getLineStartPositionForPosition ( tokenPos , sourceFile ) === tokenPos ) ;
178
+ return { kind : InfoKind . ObjectLiteral , token : param . name , properties, indentation, trimLeadingWhiteSpaces : true , parentDeclaration : parent } ;
175
179
}
176
180
177
181
if ( ! isMemberName ( token ) ) return undefined ;
@@ -490,7 +494,8 @@ namespace ts.codefix {
490
494
const options = {
491
495
leadingTriviaOption : textChanges . LeadingTriviaOption . Exclude ,
492
496
trailingTriviaOption : textChanges . TrailingTriviaOption . Exclude ,
493
- indentation : info . indentation
497
+ indentation : info . indentation ,
498
+ trimLeadingWhiteSpaces : info . trimLeadingWhiteSpaces ,
494
499
} ;
495
500
changes . replaceNode ( context . sourceFile , info . parentDeclaration , factory . createObjectLiteralExpression ( [ ...info . parentDeclaration . properties , ...props ] , /*multiLine*/ true ) , options ) ;
496
501
}
0 commit comments