File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2205,8 +2205,9 @@ namespace ts.projectSystem {
22052205 projectService . checkNumberOfProjects ( { } ) ;
22062206
22072207 for ( const f of [ f2 , f3 ] ) {
2208+ // There shouldnt be any script info as we closed the file that resulted in creation of it
22082209 const scriptInfo = projectService . getScriptInfoForNormalizedPath ( server . toNormalizedPath ( f . path ) ) ;
2209- assert . equal ( scriptInfo . containingProjects . length , 0 , `expect 0 containing projects for '${ f . path } '` ) ;
2210+ assert . equal ( scriptInfo , undefined , `expected script info to be closed: '${ f . path } '` ) ;
22102211 }
22112212 } ) ;
22122213
Original file line number Diff line number Diff line change @@ -827,10 +827,20 @@ namespace ts.server {
827827 this . assignScriptInfoToInferredProjectIfNecessary ( f , /*addToListOfOpenFiles*/ false ) ;
828828 }
829829 }
830+
831+ // Cleanup script infos that are not open and not part of any project
832+ this . deleteOrphanScriptInfoNotInAnyProject ( ) ;
830833 }
831- if ( info . containingProjects . length === 0 ) {
832- // if there are not projects that include this script info - delete it
833- this . filenameToScriptInfo . remove ( info . path ) ;
834+ }
835+
836+ private deleteOrphanScriptInfoNotInAnyProject ( ) {
837+ for ( const path of this . filenameToScriptInfo . getKeys ( ) ) {
838+ const info = this . filenameToScriptInfo . get ( path ) ;
839+ if ( ! info . isScriptOpen ( ) && info . containingProjects . length === 0 ) {
840+ // if there are not projects that include this script info - delete it
841+ info . stopWatcher ( ) ;
842+ this . filenameToScriptInfo . remove ( info . path ) ;
843+ }
834844 }
835845 }
836846
@@ -1418,6 +1428,8 @@ namespace ts.server {
14181428 for ( const p of this . inferredProjects ) {
14191429 p . updateGraph ( ) ;
14201430 }
1431+
1432+ this . deleteOrphanScriptInfoNotInAnyProject ( ) ;
14211433 this . printProjects ( ) ;
14221434 }
14231435
Original file line number Diff line number Diff line change @@ -11,11 +11,11 @@ namespace ts.server {
1111
1212 private filesWithChangedSetOfUnresolvedImports : Path [ ] ;
1313
14- private readonly resolveModuleName : typeof resolveModuleName ;
14+ private resolveModuleName : typeof resolveModuleName ;
1515 readonly trace : ( s : string ) => void ;
1616 readonly realpath ?: ( path : string ) => string ;
1717
18- constructor ( private readonly host : ServerHost , private readonly project : Project , private readonly cancellationToken : HostCancellationToken ) {
18+ constructor ( private readonly host : ServerHost , private project : Project , private readonly cancellationToken : HostCancellationToken ) {
1919 this . cancellationToken = new ThrottledCancellationToken ( cancellationToken , project . projectService . throttleWaitMilliseconds ) ;
2020 this . getCanonicalFileName = ts . createGetCanonicalFileName ( this . host . useCaseSensitiveFileNames ) ;
2121
@@ -47,6 +47,11 @@ namespace ts.server {
4747 }
4848 }
4949
50+ dispose ( ) {
51+ this . project = undefined ;
52+ this . resolveModuleName = undefined ;
53+ }
54+
5055 public startRecordingFilesWithChangedResolutions ( ) {
5156 this . filesWithChangedSetOfUnresolvedImports = [ ] ;
5257 }
@@ -238,4 +243,4 @@ namespace ts.server {
238243 this . compilationSettings = opt ;
239244 }
240245 }
241- }
246+ }
Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ namespace ts.server {
116116
117117 public languageServiceEnabled = true ;
118118
119- protected readonly lsHost : LSHost ;
119+ protected lsHost : LSHost ;
120120
121121 builder : Builder ;
122122 /**
@@ -297,9 +297,15 @@ namespace ts.server {
297297 this . rootFiles = undefined ;
298298 this . rootFilesMap = undefined ;
299299 this . program = undefined ;
300+ this . builder = undefined ;
301+ this . cachedUnresolvedImportsPerFile = undefined ;
302+ this . projectErrors = undefined ;
303+ this . lsHost . dispose ( ) ;
304+ this . lsHost = undefined ;
300305
301306 // signal language service to release source files acquired from document registry
302307 this . languageService . dispose ( ) ;
308+ this . languageService = undefined ;
303309 }
304310
305311 getCompilerOptions ( ) {
@@ -1043,6 +1049,7 @@ namespace ts.server {
10431049
10441050 if ( this . projectFileWatcher ) {
10451051 this . projectFileWatcher . close ( ) ;
1052+ this . projectFileWatcher = undefined ;
10461053 }
10471054
10481055 if ( this . typeRootsWatchers ) {
@@ -1132,4 +1139,4 @@ namespace ts.server {
11321139 this . typeAcquisition = newTypeAcquisition ;
11331140 }
11341141 }
1135- }
1142+ }
Original file line number Diff line number Diff line change @@ -1311,7 +1311,9 @@ namespace ts {
13111311 if ( program ) {
13121312 forEach ( program . getSourceFiles ( ) , f =>
13131313 documentRegistry . releaseDocument ( f . fileName , program . getCompilerOptions ( ) ) ) ;
1314+ program = undefined ;
13141315 }
1316+ host = undefined ;
13151317 }
13161318
13171319 /// Diagnostics
You can’t perform that action at this time.
0 commit comments