@@ -12,7 +12,8 @@ import {
12
12
DocumentFormattingEditProvider ,
13
13
DocumentRangeFormattingEditProvider ,
14
14
Range ,
15
- TextEditor
15
+ TextEditor ,
16
+ TextLine
16
17
} from 'vscode' ;
17
18
import { LanguageClient , RequestType } from 'vscode-languageclient' ;
18
19
import Window = vscode . window ;
@@ -181,12 +182,6 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
181
182
return this . emptyPromise ;
182
183
}
183
184
184
- // Extend the range such that it starts at the first character of the
185
- // start line of the range.
186
- if ( range !== null ) {
187
- range = this . snapRangeToLineStart ( range ) ;
188
- }
189
-
190
185
let textEdits : Thenable < TextEdit [ ] > = this . executeRulesInOrder ( editor , range , options , 0 ) ;
191
186
this . lockDocument ( document , textEdits ) ;
192
187
PSDocumentFormattingEditProvider . showStatusBar ( document , textEdits ) ;
@@ -203,9 +198,10 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
203
198
PSDocumentFormattingEditProvider . disposeAllStatusBars ( ) ;
204
199
}
205
200
206
- private snapRangeToLineStart ( range : Range ) : Range {
207
- // TODO snap to the last character of the end line too!
208
- return range . with ( { start : range . start . with ( { character : 0 } ) } ) ;
201
+ private snapRangeToEdges ( range : Range , document : TextDocument ) : Range {
202
+ return range . with ( {
203
+ start : range . start . with ( { character : 0 } ) ,
204
+ end : document . lineAt ( range . end . line ) . range . end } ) ;
209
205
}
210
206
211
207
private getEditor ( document : TextDocument ) : TextEditor {
@@ -262,8 +258,12 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
262
258
// have changed the original layout
263
259
if ( range !== null ) {
264
260
if ( this . lineDiff !== 0 ) {
265
- range = range . with ( { end : range . end . translate ( { lineDelta : this . lineDiff } ) } ) ;
261
+ range = range . with ( { end : range . end . translate ( { lineDelta : this . lineDiff } ) } ) ;
266
262
}
263
+
264
+ // extend the range such that it starts at the first character of the
265
+ // start line of the range.
266
+ range = this . snapRangeToEdges ( range , document ) ;
267
267
}
268
268
269
269
// reset line difference to 0
0 commit comments