@@ -142,7 +142,6 @@ private List<CorrectionExtent> GetCorrections(
142142 // TODO Handle case where only one param is left after correction and there is a
143143 // comma left after the param.
144144
145- var editableText = new EditableText ( funcDefnAst . Extent . Text ) ;
146145 // replace whatif/confirm extent starting with the last character of the previous parameter and ending with the last character of the whatif/confirm/parameter. This will take care of the trailing comma.
147146 // the next parameter
148147 // TODO Do not incrementally correct the text as it may lead to a situation in which a following
@@ -151,15 +150,11 @@ private List<CorrectionExtent> GetCorrections(
151150 if ( whatIfIndex != - 1 )
152151 {
153152 correctionExtents . Add ( GetCorrectionExtent ( whatIfIndex , parameterAsts ) ) ;
154- var shiftedCorrectionExtent = Normalize ( funcDefnAst . Extent , correctionExtents . Last ( ) ) ;
155- editableText = editableText . ApplyEdit ( shiftedCorrectionExtent ) ;
156153 }
157154
158155 if ( confirmIndex != - 1 )
159156 {
160157 correctionExtents . Add ( GetCorrectionExtent ( confirmIndex , parameterAsts ) ) ;
161- var shiftedCorrectionExtent = Normalize ( funcDefnAst . Extent , correctionExtents . Last ( ) ) ;
162- editableText = editableText . ApplyEdit ( shiftedCorrectionExtent ) ;
163158 }
164159
165160 if ( paramBlockAst != null )
@@ -191,11 +186,34 @@ private List<CorrectionExtent> GetCorrections(
191186 // add cmdletbinding attribute and add supportsshouldprocess to it.
192187 }
193188
189+ // sort in descending order of start position
190+ correctionExtents . Sort ( ( x , y ) => {
191+ var xRange = ( Range ) x ;
192+ var yRange = ( Range ) y ;
193+ return xRange . Start < yRange . Start ? 1 : ( xRange . Start == yRange . Start ? 0 : - 1 ) ;
194+ } ) ;
195+
196+ var editableText = new EditableText ( funcDefnAst . Extent . Text ) ;
197+ foreach ( var correctionExtent in correctionExtents )
198+ {
199+ var shiftedCorrectionExtent = Normalize ( funcDefnAst . Extent , correctionExtent ) ;
200+ editableText = editableText . ApplyEdit ( shiftedCorrectionExtent ) ;
201+ }
202+
203+ var result = new List < CorrectionExtent > ( ) ;
204+ result . Add (
205+ new CorrectionExtent (
206+ funcDefnAst . Extent . StartLineNumber ,
207+ funcDefnAst . Extent . EndLineNumber ,
208+ funcDefnAst . Extent . StartColumnNumber ,
209+ funcDefnAst . Extent . EndColumnNumber ,
210+ editableText . ToString ( ) ,
211+ funcDefnAst . Extent . File ) ) ;
212+ return result ;
194213 // This is how we handle multiple edits.
195214 // create separate edits
196215 // apply those edits to the original script extent1
197216 // and then give the corrected extent as suggested correction.
198- return correctionExtents ;
199217 }
200218
201219 // doesn't seem right. The arguments should be of same type.
0 commit comments