@@ -1142,7 +1142,7 @@ namespace ts.server {
1142
1142
return this . getPosition ( args , scriptInfo ) ;
1143
1143
}
1144
1144
1145
- private getFileAndProject ( args : protocol . FileRequestArgs ) : { file : NormalizedPath , project : Project } {
1145
+ private getFileAndProject ( args : protocol . FileRequestArgs ) : FileAndProject {
1146
1146
return this . getFileAndProjectWorker ( args . file , args . projectFileName ) ;
1147
1147
}
1148
1148
@@ -1738,9 +1738,23 @@ namespace ts.server {
1738
1738
}
1739
1739
1740
1740
private getEditsForFileRename ( args : protocol . GetEditsForFileRenameRequestArgs , simplifiedResult : boolean ) : ReadonlyArray < protocol . FileCodeEdits > | ReadonlyArray < FileTextChanges > {
1741
- const { file, project } = this . getFileAndProject ( args ) ;
1742
- const changes = project . getLanguageService ( ) . getEditsForFileRename ( toNormalizedPath ( args . oldFilePath ) , toNormalizedPath ( args . newFilePath ) , this . getFormatOptions ( file ) , this . getPreferences ( file ) ) ;
1743
- return simplifiedResult ? this . mapTextChangesToCodeEdits ( project , changes ) : changes ;
1741
+ const oldPath = toNormalizedPath ( args . oldFilePath ) ;
1742
+ const newPath = toNormalizedPath ( args . newFilePath ) ;
1743
+ const formatOptions = this . getHostFormatOptions ( ) ;
1744
+ const preferences = this . getHostPreferences ( ) ;
1745
+
1746
+ const changes : ( protocol . FileCodeEdits | FileTextChanges ) [ ] = [ ] ;
1747
+ this . projectService . forEachProject ( project => {
1748
+ if ( project . isOrphan ( ) || ! project . languageServiceEnabled ) return ;
1749
+ for ( const fileTextChanges of project . getLanguageService ( ) . getEditsForFileRename ( oldPath , newPath , formatOptions , preferences ) ) {
1750
+ // Subsequent projects may make conflicting edits to the same file -- just go with the first.
1751
+ if ( ! changes . some ( f => f . fileName === fileTextChanges . fileName ) ) {
1752
+ changes . push ( simplifiedResult ? this . mapTextChangeToCodeEdit ( project , fileTextChanges ) : fileTextChanges ) ;
1753
+ }
1754
+ }
1755
+ } ) ;
1756
+
1757
+ return changes as ReadonlyArray < protocol . FileCodeEdits > | ReadonlyArray < FileTextChanges > ;
1744
1758
}
1745
1759
1746
1760
private getCodeFixes ( args : protocol . CodeFixRequestArgs , simplifiedResult : boolean ) : ReadonlyArray < protocol . CodeFixAction > | ReadonlyArray < CodeFixAction > | undefined {
@@ -1810,10 +1824,12 @@ namespace ts.server {
1810
1824
}
1811
1825
1812
1826
private mapTextChangesToCodeEdits ( project : Project , textChanges : ReadonlyArray < FileTextChanges > ) : protocol . FileCodeEdits [ ] {
1813
- return textChanges . map ( change => {
1814
- const path = normalizedPathToPath ( toNormalizedPath ( change . fileName ) , this . host . getCurrentDirectory ( ) , fileName => this . getCanonicalFileName ( fileName ) ) ;
1815
- return mapTextChangesToCodeEdits ( change , project . getSourceFileOrConfigFile ( path ) ) ;
1816
- } ) ;
1827
+ return textChanges . map ( change => this . mapTextChangeToCodeEdit ( project , change ) ) ;
1828
+ }
1829
+
1830
+ private mapTextChangeToCodeEdit ( project : Project , change : FileTextChanges ) : protocol . FileCodeEdits {
1831
+ const path = normalizedPathToPath ( toNormalizedPath ( change . fileName ) , this . host . getCurrentDirectory ( ) , fileName => this . getCanonicalFileName ( fileName ) ) ;
1832
+ return mapTextChangesToCodeEdits ( change , project . getSourceFileOrConfigFile ( path ) ) ;
1817
1833
}
1818
1834
1819
1835
private convertTextChangeToCodeEdit ( change : TextChange , scriptInfo : ScriptInfo ) : protocol . CodeEdit {
@@ -2303,6 +2319,19 @@ namespace ts.server {
2303
2319
private getPreferences ( file : NormalizedPath ) : UserPreferences {
2304
2320
return this . projectService . getPreferences ( file ) ;
2305
2321
}
2322
+
2323
+ private getHostFormatOptions ( ) : FormatCodeSettings {
2324
+ return this . projectService . getHostFormatCodeOptions ( ) ;
2325
+ }
2326
+
2327
+ private getHostPreferences ( ) : UserPreferences {
2328
+ return this . projectService . getHostPreferences ( ) ;
2329
+ }
2330
+ }
2331
+
2332
+ interface FileAndProject {
2333
+ readonly file : NormalizedPath ;
2334
+ readonly project : Project ;
2306
2335
}
2307
2336
2308
2337
function mapTextChangesToCodeEdits ( textChanges : FileTextChanges , sourceFile : SourceFile | undefined ) : protocol . FileCodeEdits {
0 commit comments