@@ -85,21 +85,21 @@ class PSDocumentFormattingEditProvider implements vscode.DocumentFormattingEditP
85
85
index : number ) : Thenable < TextEdit [ ] > | TextEdit [ ] {
86
86
if ( this . languageClient !== null && index < this . ruleOrder . length ) {
87
87
let rule = this . ruleOrder [ index ] ;
88
- let uniqueMarkers : ScriptFileMarker [ ] = [ ] ;
89
- let markers : ScriptFileMarker [ ] ;
88
+ let uniqueEdits : ScriptRegion [ ] = [ ] ;
89
+ let edits : ScriptRegion [ ] ;
90
90
return this . languageClient . sendRequest (
91
91
ScriptFileMarkersRequest . type ,
92
92
{
93
93
filePath : document . fileName ,
94
94
settings : this . getSettings ( rule )
95
95
} )
96
96
. then ( ( result : ScriptFileMarkersRequestResultParams ) => {
97
- markers = result . markers ;
97
+ edits = result . markers . map ( m => { return m . correction . edits [ 0 ] ; } ) ;
98
98
99
99
// 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 ;
103
103
if ( leftOperand < rightOperand ) {
104
104
return 1 ;
105
105
} else if ( leftOperand > rightOperand ) {
@@ -111,26 +111,26 @@ class PSDocumentFormattingEditProvider implements vscode.DocumentFormattingEditP
111
111
112
112
// We cannot handle multiple edits on the same line hence we
113
113
// 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 ) ;
120
120
}
121
121
}
122
122
}
123
123
124
124
// we do not return a valid array because our text edits
125
125
// need to be executed in a particular order and it is
126
126
// easier if we perform the edits ourselves
127
- return this . applyEdit ( uniqueMarkers , 0 , index ) ;
127
+ return this . applyEdit ( uniqueEdits , 0 , index ) ;
128
128
} )
129
129
. then ( ( ) => {
130
130
131
131
// execute the same rule again if we left out violations
132
132
// on the same line
133
- if ( uniqueMarkers . length !== markers . length ) {
133
+ if ( uniqueEdits . length !== edits . length ) {
134
134
return this . executeRulesInOrder ( document , options , index ) ;
135
135
}
136
136
return this . executeRulesInOrder ( document , options , index + 1 ) ;
@@ -140,14 +140,14 @@ class PSDocumentFormattingEditProvider implements vscode.DocumentFormattingEditP
140
140
}
141
141
}
142
142
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 ) {
145
145
return ;
146
146
}
147
147
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 ) ;
149
149
let undoStopBefore = ! this . aggregateUndoStop || ( ruleIndex === 0 && markerIndex === 0 ) ;
150
- let edit : ScriptRegion = markers [ markerIndex ] . correction . edits [ 0 ] ;
150
+ let edit : ScriptRegion = edits [ markerIndex ] ;
151
151
return Window . activeTextEditor . edit ( ( editBuilder ) => {
152
152
editBuilder . replace (
153
153
new vscode . Range (
@@ -161,7 +161,7 @@ class PSDocumentFormattingEditProvider implements vscode.DocumentFormattingEditP
161
161
undoStopAfter : undoStopAfter ,
162
162
undoStopBefore : undoStopBefore
163
163
} ) . then ( ( isEditApplied ) => {
164
- return this . applyEdit ( markers , markerIndex + 1 , ruleIndex ) ;
164
+ return this . applyEdit ( edits , markerIndex + 1 , ruleIndex ) ;
165
165
} ) ; // TODO handle rejection
166
166
}
167
167
0 commit comments