@@ -2758,11 +2758,11 @@ namespace FourSlash {
27582758 }
27592759 }
27602760
2761- private getSelection ( ) {
2762- return ( {
2761+ private getSelection ( ) : ts . TextRange {
2762+ return {
27632763 pos : this . currentCaretPosition ,
27642764 end : this . selectionEnd === - 1 ? this . currentCaretPosition : this . selectionEnd
2765- } ) ;
2765+ } ;
27662766 }
27672767
27682768 public verifyRefactorAvailable ( negative : boolean , name : string , actionName ?: string ) {
@@ -2803,7 +2803,7 @@ namespace FourSlash {
28032803 }
28042804 }
28052805
2806- public applyRefactor ( { refactorName, actionName, actionDescription } : FourSlashInterface . ApplyRefactorOptions ) {
2806+ public applyRefactor ( { refactorName, actionName, actionDescription, newContent : newContentWithRenameMarker } : FourSlashInterface . ApplyRefactorOptions ) {
28072807 const range = this . getSelection ( ) ;
28082808 const refactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , range ) ;
28092809 const refactor = refactors . find ( r => r . name === refactorName ) ;
@@ -2823,6 +2823,35 @@ namespace FourSlash {
28232823 for ( const edit of editInfo . edits ) {
28242824 this . applyEdits ( edit . fileName , edit . textChanges , /*isFormattingEdit*/ false ) ;
28252825 }
2826+
2827+ const { renamePosition, newContent } = parseNewContent ( ) ;
2828+
2829+ this . verifyCurrentFileContent ( newContent ) ;
2830+
2831+ if ( renamePosition === undefined ) {
2832+ if ( editInfo . renameLocation !== undefined ) {
2833+ this . raiseError ( `Did not expect a rename location, got ${ editInfo . renameLocation } ` ) ;
2834+ }
2835+ }
2836+ else {
2837+ // TODO: test editInfo.renameFilename value
2838+ assert . isDefined ( editInfo . renameFilename ) ;
2839+ if ( renamePosition !== editInfo . renameLocation ) {
2840+ this . raiseError ( `Expected rename position of ${ renamePosition } , but got ${ editInfo . renameLocation } ` ) ;
2841+ }
2842+ }
2843+
2844+ function parseNewContent ( ) : { renamePosition : number | undefined , newContent : string } {
2845+ const renamePosition = newContentWithRenameMarker . indexOf ( "/*RENAME*/" ) ;
2846+ if ( renamePosition === - 1 ) {
2847+ return { renamePosition : undefined , newContent : newContentWithRenameMarker } ;
2848+ }
2849+ else {
2850+ const newContent = newContentWithRenameMarker . slice ( 0 , renamePosition ) + newContentWithRenameMarker . slice ( renamePosition + "/*RENAME*/" . length ) ;
2851+ return { renamePosition, newContent } ;
2852+ }
2853+ }
2854+
28262855 }
28272856
28282857 public verifyFileAfterApplyingRefactorAtMarker (
@@ -4319,6 +4348,7 @@ namespace FourSlashInterface {
43194348 refactorName : string ;
43204349 actionName : string ;
43214350 actionDescription : string ;
4351+ newContent : string ;
43224352 }
43234353
43244354 export interface CompletionsAtOptions {
0 commit comments