@@ -891,7 +891,6 @@ namespace ts.server {
891
891
info . close ( fileExists ) ;
892
892
this . stopWatchingConfigFilesForClosedScriptInfo ( info ) ;
893
893
894
- this . openFiles . delete ( info . path ) ;
895
894
const canonicalFileName = this . toCanonicalFileName ( info . fileName ) ;
896
895
if ( this . openFilesWithNonRootedDiskPath . get ( canonicalFileName ) === info ) {
897
896
this . openFilesWithNonRootedDiskPath . delete ( canonicalFileName ) ;
@@ -927,16 +926,19 @@ namespace ts.server {
927
926
p . markAsDirty ( ) ;
928
927
}
929
928
}
929
+
930
930
if ( projectsToRemove ) {
931
931
for ( const project of projectsToRemove ) {
932
932
this . removeProject ( project ) ;
933
933
}
934
934
935
935
// collect orphaned files and assign them to inferred project just like we treat open of a file
936
936
this . openFiles . forEach ( ( projectRootPath , path ) => {
937
- const f = this . getScriptInfoForPath ( path as Path ) ;
938
- if ( f . isOrphan ( ) ) {
939
- this . assignOrphanScriptInfoToInferredProject ( f , projectRootPath ) ;
937
+ if ( info . path !== path ) {
938
+ const f = this . getScriptInfoForPath ( path as Path ) ;
939
+ if ( f . isOrphan ( ) ) {
940
+ this . assignOrphanScriptInfoToInferredProject ( f , projectRootPath ) ;
941
+ }
940
942
}
941
943
} ) ;
942
944
@@ -945,6 +947,8 @@ namespace ts.server {
945
947
// we wont end up creating same script infos
946
948
}
947
949
950
+ this . openFiles . delete ( info . path ) ;
951
+
948
952
// If the current info is being just closed - add the watcher file to track changes
949
953
// But if file was deleted, handle that part
950
954
if ( fileExists ) {
@@ -1141,7 +1145,7 @@ namespace ts.server {
1141
1145
* This is called by inferred project whenever script info is added as a root
1142
1146
*/
1143
1147
/* @internal */
1144
- startWatchingConfigFilesForInferredProjectRoot ( info : ScriptInfo , projectRootPath : NormalizedPath | undefined ) {
1148
+ startWatchingConfigFilesForInferredProjectRoot ( info : ScriptInfo ) {
1145
1149
Debug . assert ( info . isScriptOpen ( ) ) ;
1146
1150
this . forEachConfigFileLocation ( info , ( configFileName , canonicalConfigFilePath ) => {
1147
1151
let configFileExistenceInfo = this . configFileExistenceInfoCache . get ( canonicalConfigFilePath ) ;
@@ -1163,7 +1167,7 @@ namespace ts.server {
1163
1167
! this . getConfiguredProjectByCanonicalConfigFilePath ( canonicalConfigFilePath ) ) {
1164
1168
this . createConfigFileWatcherOfConfigFileExistence ( configFileName , canonicalConfigFilePath , configFileExistenceInfo ) ;
1165
1169
}
1166
- } , projectRootPath ) ;
1170
+ } ) ;
1167
1171
}
1168
1172
1169
1173
/**
@@ -1194,14 +1198,14 @@ namespace ts.server {
1194
1198
* The server must start searching from the directory containing
1195
1199
* the newly opened file.
1196
1200
*/
1197
- private forEachConfigFileLocation ( info : ScriptInfo ,
1198
- action : ( configFileName : NormalizedPath , canonicalConfigFilePath : string ) => boolean | void ,
1199
- projectRootPath ?: NormalizedPath ) {
1200
-
1201
+ private forEachConfigFileLocation ( info : ScriptInfo , action : ( configFileName : NormalizedPath , canonicalConfigFilePath : string ) => boolean | void ) {
1201
1202
if ( this . syntaxOnly ) {
1202
1203
return undefined ;
1203
1204
}
1204
1205
1206
+ Debug . assert ( this . openFiles . has ( info . path ) ) ;
1207
+ const projectRootPath = this . openFiles . get ( info . path ) ;
1208
+
1205
1209
let searchPath = asNormalizedPath ( getDirectoryPath ( info . fileName ) ) ;
1206
1210
1207
1211
while ( ! projectRootPath || containsPath ( projectRootPath , searchPath , this . currentDirectory , ! this . host . useCaseSensitiveFileNames ) ) {
@@ -1236,13 +1240,12 @@ namespace ts.server {
1236
1240
* The server must start searching from the directory containing
1237
1241
* the newly opened file.
1238
1242
*/
1239
- private getConfigFileNameForFile ( info : ScriptInfo , projectRootPath : NormalizedPath | undefined ) {
1243
+ private getConfigFileNameForFile ( info : ScriptInfo ) {
1240
1244
Debug . assert ( info . isScriptOpen ( ) ) ;
1241
1245
this . logger . info ( `Search path: ${ getDirectoryPath ( info . fileName ) } ` ) ;
1242
1246
const configFileName = this . forEachConfigFileLocation ( info ,
1243
1247
( configFileName , canonicalConfigFilePath ) =>
1244
1248
this . configFileExists ( configFileName , canonicalConfigFilePath , info ) ,
1245
- projectRootPath
1246
1249
) ;
1247
1250
if ( configFileName ) {
1248
1251
this . logger . info ( `For info: ${ info . fileName } :: Config file name: ${ configFileName } ` ) ;
@@ -1905,7 +1908,7 @@ namespace ts.server {
1905
1908
// we first detect if there is already a configured project created for it: if so,
1906
1909
// we re- read the tsconfig file content and update the project only if we havent already done so
1907
1910
// otherwise we create a new one.
1908
- const configFileName = this . getConfigFileNameForFile ( info , this . openFiles . get ( path ) ) ;
1911
+ const configFileName = this . getConfigFileNameForFile ( info ) ;
1909
1912
if ( configFileName ) {
1910
1913
const project = this . findConfiguredProjectByProjectName ( configFileName ) ;
1911
1914
if ( ! project ) {
@@ -2008,9 +2011,10 @@ namespace ts.server {
2008
2011
let configFileErrors : ReadonlyArray < Diagnostic > ;
2009
2012
2010
2013
const info = this . getOrCreateScriptInfoOpenedByClientForNormalizedPath ( fileName , projectRootPath ? this . getNormalizedAbsolutePath ( projectRootPath ) : this . currentDirectory , fileContent , scriptKind , hasMixedContent ) ;
2014
+ this . openFiles . set ( info . path , projectRootPath ) ;
2011
2015
let project : ConfiguredProject | ExternalProject | undefined = this . findExternalProjectContainingOpenScriptInfo ( info ) ;
2012
2016
if ( ! project && ! this . syntaxOnly ) { // Checking syntaxOnly is an optimization
2013
- configFileName = this . getConfigFileNameForFile ( info , projectRootPath ) ;
2017
+ configFileName = this . getConfigFileNameForFile ( info ) ;
2014
2018
if ( configFileName ) {
2015
2019
project = this . findConfiguredProjectByProjectName ( configFileName ) ;
2016
2020
if ( ! project ) {
@@ -2048,7 +2052,6 @@ namespace ts.server {
2048
2052
}
2049
2053
2050
2054
Debug . assert ( ! info . isOrphan ( ) ) ;
2051
- this . openFiles . set ( info . path , projectRootPath ) ;
2052
2055
2053
2056
// Remove the configured projects that have zero references from open files.
2054
2057
// This was postponed from closeOpenFile to after opening next file,
0 commit comments