@@ -85,21 +85,21 @@ class PSDocumentFormattingEditProvider implements vscode.DocumentFormattingEditP
8585 index : number ) : Thenable < TextEdit [ ] > | TextEdit [ ] {
8686 if ( this . languageClient !== null && index < this . ruleOrder . length ) {
8787 let rule = this . ruleOrder [ index ] ;
88- let uniqueMarkers : ScriptFileMarker [ ] = [ ] ;
89- let markers : ScriptFileMarker [ ] ;
88+ let uniqueEdits : ScriptRegion [ ] = [ ] ;
89+ let edits : ScriptRegion [ ] ;
9090 return this . languageClient . sendRequest (
9191 ScriptFileMarkersRequest . type ,
9292 {
9393 filePath : document . fileName ,
9494 settings : this . getSettings ( rule )
9595 } )
9696 . then ( ( result : ScriptFileMarkersRequestResultParams ) => {
97- markers = result . markers ;
97+ edits = result . markers . map ( m => { return m . correction . edits [ 0 ] ; } ) ;
9898
9999 // sort in decending order of the edits
100- markers . sort ( function ( a : ScriptFileMarker , b : ScriptFileMarker ) : number {
101- let leftOperand : number = a . correction . edits [ 0 ] . startLineNumber ,
102- rightOperand : number = b . correction . edits [ 0 ] . startLineNumber ;
100+ edits . sort ( function ( a : ScriptRegion , b : ScriptRegion ) : number {
101+ let leftOperand : number = a . startLineNumber ,
102+ rightOperand : number = b . startLineNumber ;
103103 if ( leftOperand < rightOperand ) {
104104 return 1 ;
105105 } else if ( leftOperand > rightOperand ) {
@@ -111,26 +111,26 @@ class PSDocumentFormattingEditProvider implements vscode.DocumentFormattingEditP
111111
112112 // We cannot handle multiple edits on the same line hence we
113113 // filter the markers so that there is only one edit per line
114- if ( markers . length > 0 ) {
115- uniqueMarkers . push ( markers [ 0 ] ) ;
116- for ( let marker of markers . slice ( 1 ) ) {
117- if ( marker . correction . edits [ 0 ] . startLineNumber
118- !== uniqueMarkers [ uniqueMarkers . length - 1 ] . correction . edits [ 0 ] . startLineNumber ) {
119- uniqueMarkers . push ( marker ) ;
114+ if ( edits . length > 0 ) {
115+ uniqueEdits . push ( edits [ 0 ] ) ;
116+ for ( let edit of edits . slice ( 1 ) ) {
117+ if ( edit . startLineNumber
118+ !== uniqueEdits [ uniqueEdits . length - 1 ] . startLineNumber ) {
119+ uniqueEdits . push ( edit ) ;
120120 }
121121 }
122122 }
123123
124124 // we do not return a valid array because our text edits
125125 // need to be executed in a particular order and it is
126126 // easier if we perform the edits ourselves
127- return this . applyEdit ( uniqueMarkers , 0 , index ) ;
127+ return this . applyEdit ( uniqueEdits , 0 , index ) ;
128128 } )
129129 . then ( ( ) => {
130130
131131 // execute the same rule again if we left out violations
132132 // on the same line
133- if ( uniqueMarkers . length !== markers . length ) {
133+ if ( uniqueEdits . length !== edits . length ) {
134134 return this . executeRulesInOrder ( document , options , index ) ;
135135 }
136136 return this . executeRulesInOrder ( document , options , index + 1 ) ;
@@ -140,14 +140,14 @@ class PSDocumentFormattingEditProvider implements vscode.DocumentFormattingEditP
140140 }
141141 }
142142
143- applyEdit ( markers : ScriptFileMarker [ ] , markerIndex : number , ruleIndex : number ) : Thenable < void > {
144- if ( markerIndex >= markers . length ) {
143+ applyEdit ( edits : ScriptRegion [ ] , markerIndex : number , ruleIndex : number ) : Thenable < void > {
144+ if ( markerIndex >= edits . length ) {
145145 return ;
146146 }
147147
148- let undoStopAfter = ! this . aggregateUndoStop || ( ruleIndex === this . ruleOrder . length - 1 && markerIndex === markers . length - 1 ) ;
148+ let undoStopAfter = ! this . aggregateUndoStop || ( ruleIndex === this . ruleOrder . length - 1 && markerIndex === edits . length - 1 ) ;
149149 let undoStopBefore = ! this . aggregateUndoStop || ( ruleIndex === 0 && markerIndex === 0 ) ;
150- let edit : ScriptRegion = markers [ markerIndex ] . correction . edits [ 0 ] ;
150+ let edit : ScriptRegion = edits [ markerIndex ] ;
151151 return Window . activeTextEditor . edit ( ( editBuilder ) => {
152152 editBuilder . replace (
153153 new vscode . Range (
@@ -161,7 +161,7 @@ class PSDocumentFormattingEditProvider implements vscode.DocumentFormattingEditP
161161 undoStopAfter : undoStopAfter ,
162162 undoStopBefore : undoStopBefore
163163 } ) . then ( ( isEditApplied ) => {
164- return this . applyEdit ( markers , markerIndex + 1 , ruleIndex ) ;
164+ return this . applyEdit ( edits , markerIndex + 1 , ruleIndex ) ;
165165 } ) ; // TODO handle rejection
166166 }
167167
0 commit comments