@@ -1142,7 +1142,7 @@ namespace ts.server {
11421142 return this . getPosition ( args , scriptInfo ) ;
11431143 }
11441144
1145- private getFileAndProject ( args : protocol . FileRequestArgs ) : { file : NormalizedPath , project : Project } {
1145+ private getFileAndProject ( args : protocol . FileRequestArgs ) : FileAndProject {
11461146 return this . getFileAndProjectWorker ( args . file , args . projectFileName ) ;
11471147 }
11481148
@@ -1738,9 +1738,23 @@ namespace ts.server {
17381738 }
17391739
17401740 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 > ;
17441758 }
17451759
17461760 private getCodeFixes ( args : protocol . CodeFixRequestArgs , simplifiedResult : boolean ) : ReadonlyArray < protocol . CodeFixAction > | ReadonlyArray < CodeFixAction > | undefined {
@@ -1810,10 +1824,12 @@ namespace ts.server {
18101824 }
18111825
18121826 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 ) ) ;
18171833 }
18181834
18191835 private convertTextChangeToCodeEdit ( change : TextChange , scriptInfo : ScriptInfo ) : protocol . CodeEdit {
@@ -2303,6 +2319,19 @@ namespace ts.server {
23032319 private getPreferences ( file : NormalizedPath ) : UserPreferences {
23042320 return this . projectService . getPreferences ( file ) ;
23052321 }
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 ;
23062335 }
23072336
23082337 function mapTextChangesToCodeEdits ( textChanges : FileTextChanges , sourceFile : SourceFile | undefined ) : protocol . FileCodeEdits {
0 commit comments