@@ -1683,7 +1683,7 @@ namespace FourSlash {
1683
1683
if ( this . enableFormatting ) {
1684
1684
const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , offset , ch , this . formatCodeSettings ) ;
1685
1685
if ( edits . length ) {
1686
- offset += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
1686
+ offset += this . applyEdits ( this . activeFile . fileName , edits ) ;
1687
1687
}
1688
1688
}
1689
1689
}
@@ -1756,7 +1756,7 @@ namespace FourSlash {
1756
1756
if ( this . enableFormatting ) {
1757
1757
const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , offset , ch , this . formatCodeSettings ) ;
1758
1758
if ( edits . length ) {
1759
- offset += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
1759
+ offset += this . applyEdits ( this . activeFile . fileName , edits ) ;
1760
1760
}
1761
1761
}
1762
1762
}
@@ -1775,7 +1775,7 @@ namespace FourSlash {
1775
1775
if ( this . enableFormatting ) {
1776
1776
const edits = this . languageService . getFormattingEditsForRange ( this . activeFile . fileName , start , offset , this . formatCodeSettings ) ;
1777
1777
if ( edits . length ) {
1778
- this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
1778
+ this . applyEdits ( this . activeFile . fileName , edits ) ;
1779
1779
}
1780
1780
}
1781
1781
@@ -1810,9 +1810,7 @@ namespace FourSlash {
1810
1810
* @returns The number of characters added to the file as a result of the edits.
1811
1811
* May be negative.
1812
1812
*/
1813
- private applyEdits ( fileName : string , edits : readonly ts . TextChange [ ] , isFormattingEdit : boolean ) : number {
1814
- // Get a snapshot of the content of the file so we can make sure any formatting edits didn't destroy non-whitespace characters
1815
- const oldContent = this . getFileContent ( fileName ) ;
1813
+ private applyEdits ( fileName : string , edits : readonly ts . TextChange [ ] ) : number {
1816
1814
let runningOffset = 0 ;
1817
1815
1818
1816
forEachTextChange ( edits , edit => {
@@ -1833,14 +1831,6 @@ namespace FourSlash {
1833
1831
runningOffset += editDelta ;
1834
1832
} ) ;
1835
1833
1836
- if ( isFormattingEdit ) {
1837
- const newContent = this . getFileContent ( fileName ) ;
1838
-
1839
- if ( this . removeWhitespace ( newContent ) !== this . removeWhitespace ( oldContent ) ) {
1840
- this . raiseError ( "Formatting operation destroyed non-whitespace content" ) ;
1841
- }
1842
- }
1843
-
1844
1834
return runningOffset ;
1845
1835
}
1846
1836
@@ -1856,17 +1846,17 @@ namespace FourSlash {
1856
1846
1857
1847
public formatDocument ( ) {
1858
1848
const edits = this . languageService . getFormattingEditsForDocument ( this . activeFile . fileName , this . formatCodeSettings ) ;
1859
- this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
1849
+ this . applyEdits ( this . activeFile . fileName , edits ) ;
1860
1850
}
1861
1851
1862
1852
public formatSelection ( start : number , end : number ) {
1863
1853
const edits = this . languageService . getFormattingEditsForRange ( this . activeFile . fileName , start , end , this . formatCodeSettings ) ;
1864
- this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
1854
+ this . applyEdits ( this . activeFile . fileName , edits ) ;
1865
1855
}
1866
1856
1867
1857
public formatOnType ( pos : number , key : string ) {
1868
1858
const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , pos , key , this . formatCodeSettings ) ;
1869
- this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
1859
+ this . applyEdits ( this . activeFile . fileName , edits ) ;
1870
1860
}
1871
1861
1872
1862
private editScriptAndUpdateMarkers ( fileName : string , editStart : number , editEnd : number , newText : string ) {
@@ -2414,7 +2404,7 @@ namespace FourSlash {
2414
2404
2415
2405
if ( options . applyChanges ) {
2416
2406
for ( const change of action . changes ) {
2417
- this . applyEdits ( change . fileName , change . textChanges , /*isFormattingEdit*/ false ) ;
2407
+ this . applyEdits ( change . fileName , change . textChanges ) ;
2418
2408
}
2419
2409
this . verifyNewContentAfterChange ( options , action . changes . map ( c => c . fileName ) ) ;
2420
2410
}
@@ -2497,7 +2487,7 @@ namespace FourSlash {
2497
2487
2498
2488
private applyChanges ( changes : readonly ts . FileTextChanges [ ] ) : void {
2499
2489
for ( const change of changes ) {
2500
- this . applyEdits ( change . fileName , change . textChanges , /*isFormattingEdit*/ false ) ;
2490
+ this . applyEdits ( change . fileName , change . textChanges ) ;
2501
2491
}
2502
2492
}
2503
2493
@@ -2525,7 +2515,7 @@ namespace FourSlash {
2525
2515
ts . Debug . assert ( codeFix . changes . length === 1 ) ;
2526
2516
const change = ts . first ( codeFix . changes ) ;
2527
2517
ts . Debug . assert ( change . fileName === fileName ) ;
2528
- this . applyEdits ( change . fileName , change . textChanges , /*isFormattingEdit*/ false ) ;
2518
+ this . applyEdits ( change . fileName , change . textChanges ) ;
2529
2519
const text = range ? this . rangeText ( range ) : this . getFileContent ( this . activeFile . fileName ) ;
2530
2520
actualTextArray . push ( text ) ;
2531
2521
scriptInfo . updateContent ( originalContent ) ;
@@ -2929,7 +2919,7 @@ namespace FourSlash {
2929
2919
2930
2920
const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , this . formatCodeSettings , range , refactorName , actionName , ts . emptyOptions ) ! ;
2931
2921
for ( const edit of editInfo . edits ) {
2932
- this . applyEdits ( edit . fileName , edit . textChanges , /*isFormattingEdit*/ false ) ;
2922
+ this . applyEdits ( edit . fileName , edit . textChanges ) ;
2933
2923
}
2934
2924
2935
2925
let renameFilename : string | undefined ;
@@ -3045,7 +3035,7 @@ namespace FourSlash {
3045
3035
const editInfo = this . languageService . getEditsForRefactor ( marker . fileName , formattingOptions , marker . position , refactorNameToApply , actionName , ts . emptyOptions ) ! ;
3046
3036
3047
3037
for ( const edit of editInfo . edits ) {
3048
- this . applyEdits ( edit . fileName , edit . textChanges , /*isFormattingEdit*/ false ) ;
3038
+ this . applyEdits ( edit . fileName , edit . textChanges ) ;
3049
3039
}
3050
3040
const actualContent = this . getFileContent ( marker . fileName ) ;
3051
3041
0 commit comments