@@ -1683,7 +1683,7 @@ namespace FourSlash {
16831683 if ( this . enableFormatting ) {
16841684 const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , offset , ch , this . formatCodeSettings ) ;
16851685 if ( edits . length ) {
1686- offset += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
1686+ offset += this . applyEdits ( this . activeFile . fileName , edits ) ;
16871687 }
16881688 }
16891689 }
@@ -1756,7 +1756,7 @@ namespace FourSlash {
17561756 if ( this . enableFormatting ) {
17571757 const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , offset , ch , this . formatCodeSettings ) ;
17581758 if ( edits . length ) {
1759- offset += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
1759+ offset += this . applyEdits ( this . activeFile . fileName , edits ) ;
17601760 }
17611761 }
17621762 }
@@ -1775,7 +1775,7 @@ namespace FourSlash {
17751775 if ( this . enableFormatting ) {
17761776 const edits = this . languageService . getFormattingEditsForRange ( this . activeFile . fileName , start , offset , this . formatCodeSettings ) ;
17771777 if ( edits . length ) {
1778- this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
1778+ this . applyEdits ( this . activeFile . fileName , edits ) ;
17791779 }
17801780 }
17811781
@@ -1810,9 +1810,7 @@ namespace FourSlash {
18101810 * @returns The number of characters added to the file as a result of the edits.
18111811 * May be negative.
18121812 */
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 {
18161814 let runningOffset = 0 ;
18171815
18181816 forEachTextChange ( edits , edit => {
@@ -1833,14 +1831,6 @@ namespace FourSlash {
18331831 runningOffset += editDelta ;
18341832 } ) ;
18351833
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-
18441834 return runningOffset ;
18451835 }
18461836
@@ -1856,17 +1846,17 @@ namespace FourSlash {
18561846
18571847 public formatDocument ( ) {
18581848 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 ) ;
18601850 }
18611851
18621852 public formatSelection ( start : number , end : number ) {
18631853 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 ) ;
18651855 }
18661856
18671857 public formatOnType ( pos : number , key : string ) {
18681858 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 ) ;
18701860 }
18711861
18721862 private editScriptAndUpdateMarkers ( fileName : string , editStart : number , editEnd : number , newText : string ) {
@@ -2414,7 +2404,7 @@ namespace FourSlash {
24142404
24152405 if ( options . applyChanges ) {
24162406 for ( const change of action . changes ) {
2417- this . applyEdits ( change . fileName , change . textChanges , /*isFormattingEdit*/ false ) ;
2407+ this . applyEdits ( change . fileName , change . textChanges ) ;
24182408 }
24192409 this . verifyNewContentAfterChange ( options , action . changes . map ( c => c . fileName ) ) ;
24202410 }
@@ -2497,7 +2487,7 @@ namespace FourSlash {
24972487
24982488 private applyChanges ( changes : readonly ts . FileTextChanges [ ] ) : void {
24992489 for ( const change of changes ) {
2500- this . applyEdits ( change . fileName , change . textChanges , /*isFormattingEdit*/ false ) ;
2490+ this . applyEdits ( change . fileName , change . textChanges ) ;
25012491 }
25022492 }
25032493
@@ -2525,7 +2515,7 @@ namespace FourSlash {
25252515 ts . Debug . assert ( codeFix . changes . length === 1 ) ;
25262516 const change = ts . first ( codeFix . changes ) ;
25272517 ts . Debug . assert ( change . fileName === fileName ) ;
2528- this . applyEdits ( change . fileName , change . textChanges , /*isFormattingEdit*/ false ) ;
2518+ this . applyEdits ( change . fileName , change . textChanges ) ;
25292519 const text = range ? this . rangeText ( range ) : this . getFileContent ( this . activeFile . fileName ) ;
25302520 actualTextArray . push ( text ) ;
25312521 scriptInfo . updateContent ( originalContent ) ;
@@ -2929,7 +2919,7 @@ namespace FourSlash {
29292919
29302920 const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , this . formatCodeSettings , range , refactorName , actionName , ts . emptyOptions ) ! ;
29312921 for ( const edit of editInfo . edits ) {
2932- this . applyEdits ( edit . fileName , edit . textChanges , /*isFormattingEdit*/ false ) ;
2922+ this . applyEdits ( edit . fileName , edit . textChanges ) ;
29332923 }
29342924
29352925 let renameFilename : string | undefined ;
@@ -3045,7 +3035,7 @@ namespace FourSlash {
30453035 const editInfo = this . languageService . getEditsForRefactor ( marker . fileName , formattingOptions , marker . position , refactorNameToApply , actionName , ts . emptyOptions ) ! ;
30463036
30473037 for ( const edit of editInfo . edits ) {
3048- this . applyEdits ( edit . fileName , edit . textChanges , /*isFormattingEdit*/ false ) ;
3038+ this . applyEdits ( edit . fileName , edit . textChanges ) ;
30493039 }
30503040 const actualContent = this . getFileContent ( marker . fileName ) ;
30513041
0 commit comments