@@ -85,19 +85,19 @@ 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
90
return this . languageClient . sendRequest (
89
91
ScriptFileMarkersRequest . type ,
90
92
{
91
93
filePath : document . fileName ,
92
94
settings : this . getSettings ( rule )
93
95
} )
94
96
. then ( ( result : ScriptFileMarkersRequestResultParams ) => {
95
-
96
- // TODO modify undo stops to make sure all the edits
97
- // can be undone and redone in a single step
97
+ markers = result . markers ;
98
98
99
99
// sort in decending order of the edits
100
- result . markers . sort ( function ( a : ScriptFileMarker , b : ScriptFileMarker ) : number {
100
+ markers . sort ( function ( a : ScriptFileMarker , b : ScriptFileMarker ) : number {
101
101
let leftOperand : number = a . correction . edits [ 0 ] . startLineNumber ,
102
102
rightOperand : number = b . correction . edits [ 0 ] . startLineNumber ;
103
103
if ( leftOperand < rightOperand ) {
@@ -108,13 +108,31 @@ class PSDocumentFormattingEditProvider implements vscode.DocumentFormattingEditP
108
108
return 0 ;
109
109
}
110
110
} ) ;
111
- return this . applyEdits ( result . markers , 0 ) ;
111
+
112
+ // We cannot handle multiple edits on the same line hence we
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 ) ;
120
+ }
121
+ }
122
+ }
112
123
113
124
// we do not return a valid array because our text edits
114
125
// need to be executed in a particular order and it is
115
126
// easier if we perform the edits ourselves
127
+ return this . applyEdit ( uniqueMarkers , 0 , index ) ;
116
128
} )
117
129
. then ( ( ) => {
130
+
131
+ // execute the same rule again if we left out violations
132
+ // on the same line
133
+ if ( uniqueMarkers . length !== markers . length ) {
134
+ return this . executeRulesInOrder ( document , options , index ) ;
135
+ }
118
136
return this . executeRulesInOrder ( document , options , index + 1 ) ;
119
137
} ) ;
120
138
} else {
0 commit comments