@@ -12,7 +12,8 @@ import {
1212 DocumentFormattingEditProvider , 
1313 DocumentRangeFormattingEditProvider , 
1414 Range , 
15-  TextEditor 
15+  TextEditor , 
16+  TextLine 
1617}  from  'vscode' ; 
1718import  {  LanguageClient ,  RequestType  }  from  'vscode-languageclient' ; 
1819import  Window  =  vscode . window ; 
@@ -181,12 +182,6 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
181182 return  this . emptyPromise ; 
182183 } 
183184
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- 
190185 let  textEdits : Thenable < TextEdit [ ] >  =  this . executeRulesInOrder ( editor ,  range ,  options ,  0 ) ; 
191186 this . lockDocument ( document ,  textEdits ) ; 
192187 PSDocumentFormattingEditProvider . showStatusBar ( document ,  textEdits ) ; 
@@ -203,9 +198,10 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
203198 PSDocumentFormattingEditProvider . disposeAllStatusBars ( ) ; 
204199 } 
205200
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  } ) ; 
209205 } 
210206
211207 private  getEditor ( document : TextDocument ) : TextEditor  { 
@@ -262,8 +258,12 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
262258 // have changed the original layout 
263259 if  ( range  !==  null )  { 
264260 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   } )   } ) ; 
266262 } 
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 ) ; 
267267 } 
268268
269269 // reset line difference to 0 
0 commit comments