@@ -3,16 +3,33 @@ namespace ts {
3
3
export function getEditsForFileRename ( program : Program , oldFilePath : string , newFilePath : string , host : LanguageServiceHost , formatContext : formatting . FormatContext ) : ReadonlyArray < FileTextChanges > {
4
4
const pathUpdater = getPathUpdater ( oldFilePath , newFilePath , host ) ;
5
5
return textChanges . ChangeTracker . with ( { host, formatContext } , changeTracker => {
6
+ updateTsconfigFiles ( program , changeTracker , oldFilePath , newFilePath ) ;
6
7
for ( const { sourceFile, toUpdate } of getImportsToUpdate ( program , oldFilePath ) ) {
7
8
const newPath = pathUpdater ( isRef ( toUpdate ) ? toUpdate . fileName : toUpdate . text ) ;
8
9
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 ) ;
10
11
changeTracker . replaceRangeWithText ( sourceFile , range , isRef ( toUpdate ) ? newPath : removeFileExtension ( newPath ) ) ;
11
12
}
12
13
}
13
14
} ) ;
14
15
}
15
16
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
+
16
33
interface ToUpdate {
17
34
readonly sourceFile : SourceFile ;
18
35
readonly toUpdate : StringLiteralLike | FileReference ;
@@ -52,4 +69,8 @@ namespace ts {
52
69
return ensurePathIsRelative ( normalizePath ( combinePaths ( getDirectoryPath ( oldPath ) , rel ) ) ) ;
53
70
} ;
54
71
}
72
+
73
+ function createStringRange ( node : StringLiteralLike , sourceFile : SourceFileLike ) : TextRange {
74
+ return createTextRange ( node . getStart ( sourceFile ) + 1 , node . end - 1 ) ;
75
+ }
55
76
}
0 commit comments