@@ -1142,15 +1142,27 @@ 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
1149
+ private getFileAndProjectForFileRename ( args : protocol . GetEditsForFileRenameRequestArgs ) : FileAndProject {
1150
+ const oldFilePath = toNormalizedPath ( args . oldFilePath ) ;
1151
+ const oldProject = this . projectService . getDefaultProjectForFile ( oldFilePath ) ;
1152
+ if ( oldProject ) return { file : oldFilePath , project : oldProject } ;
1153
+
1154
+ const newFilePath = toNormalizedPath ( args . newFilePath ) ;
1155
+ const newProject = this . projectService . getDefaultProjectForFile ( newFilePath ) ;
1156
+ if ( newProject ) return { file : newFilePath , project : newProject } ;
1157
+
1158
+ return Debug . assertDefined ( this . projectService . tryGetSomeFileInDirectory ( oldFilePath ) || this . projectService . tryGetSomeFileInDirectory ( newFilePath ) ) ;
1159
+ }
1160
+
1149
1161
private getFileAndLanguageServiceForSyntacticOperation ( args : protocol . FileRequestArgs ) {
1150
1162
// Since this is syntactic operation, there should always be project for the file
1151
1163
// we wouldnt have to ensure project but rather throw if we dont get project
1152
1164
const file = toNormalizedPath ( args . file ) ;
1153
- const project = this . getProject ( args . projectFileName ) || this . projectService . getDefaultProjectForFile ( file , /*ensureProject*/ false ) ;
1165
+ const project = this . getProject ( args . projectFileName ) || this . projectService . getDefaultProjectForFile ( file ) ;
1154
1166
if ( ! project ) {
1155
1167
return Errors . ThrowNoProject ( ) ;
1156
1168
}
@@ -1162,7 +1174,7 @@ namespace ts.server {
1162
1174
1163
1175
private getFileAndProjectWorker ( uncheckedFileName : string , projectFileName : string | undefined ) : { file : NormalizedPath , project : Project } {
1164
1176
const file = toNormalizedPath ( uncheckedFileName ) ;
1165
- const project = this . getProject ( projectFileName ) || this . projectService . getDefaultProjectForFile ( file , /*ensureProject*/ true ) ! ; // TODO: GH#18217
1177
+ const project = this . getProject ( projectFileName ) || this . projectService . ensureDefaultProjectForFile ( file ) ;
1166
1178
return { file, project } ;
1167
1179
}
1168
1180
@@ -1454,7 +1466,7 @@ namespace ts.server {
1454
1466
private createCheckList ( fileNames : string [ ] , defaultProject ?: Project ) : PendingErrorCheck [ ] {
1455
1467
return mapDefined < string , PendingErrorCheck > ( fileNames , uncheckedFileName => {
1456
1468
const fileName = toNormalizedPath ( uncheckedFileName ) ;
1457
- const project = defaultProject || this . projectService . getDefaultProjectForFile ( fileName , /*ensureProject*/ false ) ;
1469
+ const project = defaultProject || this . projectService . getDefaultProjectForFile ( fileName ) ;
1458
1470
return project && { fileName, project } ;
1459
1471
} ) ;
1460
1472
}
@@ -1731,7 +1743,7 @@ namespace ts.server {
1731
1743
}
1732
1744
1733
1745
private getEditsForFileRename ( args : protocol . GetEditsForFileRenameRequestArgs , simplifiedResult : boolean ) : ReadonlyArray < protocol . FileCodeEdits > | ReadonlyArray < FileTextChanges > {
1734
- const { file, project } = this . getFileAndProject ( args ) ;
1746
+ const { file, project } = this . getFileAndProjectForFileRename ( args ) ;
1735
1747
const changes = project . getLanguageService ( ) . getEditsForFileRename ( toNormalizedPath ( args . oldFilePath ) , toNormalizedPath ( args . newFilePath ) , this . getFormatOptions ( file ) , this . getPreferences ( file ) ) ;
1736
1748
return simplifiedResult ? this . mapTextChangesToCodeEdits ( project , changes ) : changes ;
1737
1749
}
@@ -1852,7 +1864,7 @@ namespace ts.server {
1852
1864
const lowPriorityFiles : NormalizedPath [ ] = [ ] ;
1853
1865
const veryLowPriorityFiles : NormalizedPath [ ] = [ ] ;
1854
1866
const normalizedFileName = toNormalizedPath ( fileName ) ;
1855
- const project = this . projectService . getDefaultProjectForFile ( normalizedFileName , /*ensureProject*/ true ) ! ;
1867
+ const project = this . projectService . ensureDefaultProjectForFile ( normalizedFileName ) ;
1856
1868
for ( const fileNameInProject of fileNamesInProject ) {
1857
1869
if ( this . getCanonicalFileName ( fileNameInProject ) === this . getCanonicalFileName ( fileName ) ) {
1858
1870
highPriorityFiles . push ( fileNameInProject ) ;
@@ -2295,6 +2307,11 @@ namespace ts.server {
2295
2307
}
2296
2308
}
2297
2309
2310
+ interface FileAndProject {
2311
+ readonly file : NormalizedPath ;
2312
+ readonly project : Project ;
2313
+ }
2314
+
2298
2315
function mapTextChangesToCodeEdits ( textChanges : FileTextChanges , sourceFile : SourceFile | undefined ) : protocol . FileCodeEdits {
2299
2316
Debug . assert ( ! ! textChanges . isNewFile === ! sourceFile ) ;
2300
2317
if ( sourceFile ) {
0 commit comments