@@ -3,16 +3,33 @@ namespace ts {
33 export function getEditsForFileRename ( program : Program , oldFilePath : string , newFilePath : string , host : LanguageServiceHost , formatContext : formatting . FormatContext ) : ReadonlyArray < FileTextChanges > {
44 const pathUpdater = getPathUpdater ( oldFilePath , newFilePath , host ) ;
55 return textChanges . ChangeTracker . with ( { host, formatContext } , changeTracker => {
6+ updateTsconfigFiles ( program , changeTracker , oldFilePath , newFilePath ) ;
67 for ( const { sourceFile, toUpdate } of getImportsToUpdate ( program , oldFilePath ) ) {
78 const newPath = pathUpdater ( isRef ( toUpdate ) ? toUpdate . fileName : toUpdate . text ) ;
89 if ( newPath !== undefined ) {
9- const range = isRef ( toUpdate ) ? toUpdate : createTextRange ( toUpdate . getStart ( sourceFile ) + 1 , toUpdate . end - 1 ) ;
10+ const range = isRef ( toUpdate ) ? toUpdate : createStringRange ( toUpdate , sourceFile ) ;
1011 changeTracker . replaceRangeWithText ( sourceFile , range , isRef ( toUpdate ) ? newPath : removeFileExtension ( newPath ) ) ;
1112 }
1213 }
1314 } ) ;
1415 }
1516
17+ function updateTsconfigFiles ( program : Program , changeTracker : textChanges . ChangeTracker , oldFilePath : string , newFilePath : string ) : void {
18+ const cfg = program . getCompilerOptions ( ) . configFile ;
19+ if ( ! cfg ) return ;
20+ const oldFile = cfg . jsonObject && getFilesEntry ( cfg . jsonObject , oldFilePath ) ;
21+ if ( oldFile ) {
22+ changeTracker . replaceRangeWithText ( cfg , createStringRange ( oldFile , cfg ) , newFilePath ) ;
23+ }
24+ }
25+
26+ function getFilesEntry ( cfg : ObjectLiteralExpression , fileName : string ) : StringLiteral | undefined {
27+ const filesProp = find ( cfg . properties , ( prop ) : prop is PropertyAssignment =>
28+ isPropertyAssignment ( prop ) && isStringLiteral ( prop . name ) && prop . name . text === "files" ) ;
29+ const files = filesProp && filesProp . initializer ;
30+ return files && isArrayLiteralExpression ( files ) ? find ( files . elements , ( e ) : e is StringLiteral => isStringLiteral ( e ) && e . text === fileName ) : undefined ;
31+ }
32+
1633 interface ToUpdate {
1734 readonly sourceFile : SourceFile ;
1835 readonly toUpdate : StringLiteralLike | FileReference ;
@@ -52,4 +69,8 @@ namespace ts {
5269 return ensurePathIsRelative ( normalizePath ( combinePaths ( getDirectoryPath ( oldPath ) , rel ) ) ) ;
5370 } ;
5471 }
72+
73+ function createStringRange ( node : StringLiteralLike , sourceFile : SourceFileLike ) : TextRange {
74+ return createTextRange ( node . getStart ( sourceFile ) + 1 , node . end - 1 ) ;
75+ }
5576}
0 commit comments