@@ -17,6 +17,7 @@ type ConfigFileEntry struct {
17
17
mu sync.Mutex
18
18
commandLine * tsoptions.ParsedCommandLine
19
19
projects collections.Set [* Project ]
20
+ infos collections.Set [* ScriptInfo ]
20
21
pendingReload PendingReload
21
22
rootFilesWatch * watchedFiles [[]string ]
22
23
}
@@ -28,6 +29,7 @@ type ExtendedConfigFileEntry struct {
28
29
29
30
type ConfigFileRegistry struct {
30
31
Host ProjectHost
32
+ defaultProjectFinder * defaultProjectFinder
31
33
ConfigFiles collections.SyncMap [tspath.Path , * ConfigFileEntry ]
32
34
ExtendedConfigCache collections.SyncMap [tspath.Path , * tsoptions.ExtendedConfigCacheEntry ]
33
35
ExtendedConfigsUsedBy collections.SyncMap [tspath.Path , * ExtendedConfigFileEntry ]
@@ -60,26 +62,17 @@ func (c *configFileWatchHost) Log(message string) {
60
62
c .host .Log (message )
61
63
}
62
64
63
- func (c * ConfigFileRegistry ) ReleaseConfig (path tspath.Path , project * Project ) {
65
+ func (c * ConfigFileRegistry ) releaseConfig (path tspath.Path , project * Project ) {
64
66
entry , ok := c .ConfigFiles .Load (path )
65
67
if ! ok {
66
68
return
67
69
}
68
70
entry .mu .Lock ()
69
71
defer entry .mu .Unlock ()
70
72
entry .projects .Delete (project )
71
- if entry .projects .Len () == 0 {
72
- c .ConfigFiles .Delete (path )
73
- commandLine := entry .commandLine
74
- entry .commandLine = nil
75
- c .updateExtendedConfigsUsedBy (path , entry , commandLine )
76
- if entry .rootFilesWatch != nil {
77
- entry .rootFilesWatch .update (context .Background (), nil )
78
- }
79
- }
80
73
}
81
74
82
- func (c * ConfigFileRegistry ) AcquireConfig (fileName string , path tspath.Path , project * Project ) * tsoptions.ParsedCommandLine {
75
+ func (c * ConfigFileRegistry ) acquireConfig (fileName string , path tspath.Path , project * Project , info * ScriptInfo ) * tsoptions.ParsedCommandLine {
83
76
entry , ok := c .ConfigFiles .Load (path )
84
77
if ! ok {
85
78
// Create parsed command line
@@ -97,7 +90,11 @@ func (c *ConfigFileRegistry) AcquireConfig(fileName string, path tspath.Path, pr
97
90
}
98
91
entry .mu .Lock ()
99
92
defer entry .mu .Unlock ()
100
- entry .projects .Add (project )
93
+ if project != nil {
94
+ entry .projects .Add (project )
95
+ } else if info != nil {
96
+ entry .infos .Add (info )
97
+ }
101
98
if entry .pendingReload == PendingReloadNone {
102
99
return entry .commandLine
103
100
}
@@ -114,6 +111,23 @@ func (c *ConfigFileRegistry) AcquireConfig(fileName string, path tspath.Path, pr
114
111
return entry .commandLine
115
112
}
116
113
114
+ func (c * ConfigFileRegistry ) getConfig (path tspath.Path ) * tsoptions.ParsedCommandLine {
115
+ entry , ok := c .ConfigFiles .Load (path )
116
+ if ok {
117
+ return entry .commandLine
118
+ }
119
+ return nil
120
+ }
121
+
122
+ func (c * ConfigFileRegistry ) releaseConfigsForInfo (info * ScriptInfo ) {
123
+ c .ConfigFiles .Range (func (path tspath.Path , entry * ConfigFileEntry ) bool {
124
+ entry .mu .Lock ()
125
+ entry .infos .Delete (info )
126
+ entry .mu .Unlock ()
127
+ return true
128
+ })
129
+ }
130
+
117
131
func (c * ConfigFileRegistry ) updateRootFilesWatch (fileName string , entry * ConfigFileEntry ) {
118
132
if entry .rootFilesWatch == nil {
119
133
return
@@ -187,6 +201,10 @@ func (c *ConfigFileRegistry) onConfigChange(path tspath.Path, changeKind lsproto
187
201
entry .mu .Lock ()
188
202
defer entry .mu .Unlock ()
189
203
if entry .SetPendingReload (PendingReloadFull ) {
204
+ for info := range entry .infos .Keys () {
205
+ delete (c .defaultProjectFinder .configFileForOpenFiles , info .Path ())
206
+ delete (c .defaultProjectFinder .configFilesAncestorForOpenFiles , info .Path ())
207
+ }
190
208
for project := range entry .projects .Keys () {
191
209
if project .configFilePath == path {
192
210
switch changeKind {
@@ -202,6 +220,7 @@ func (c *ConfigFileRegistry) onConfigChange(path tspath.Path, changeKind lsproto
202
220
project .markAsDirty ()
203
221
}
204
222
}
223
+ return true
205
224
}
206
225
return false
207
226
}
@@ -224,3 +243,19 @@ func (c *ConfigFileRegistry) tryInvokeWildCardDirectories(fileName string, path
224
243
entry .mu .Unlock ()
225
244
}
226
245
}
246
+
247
+ func (c * ConfigFileRegistry ) cleanup (toRemoveConfigs map [tspath.Path ]* ConfigFileEntry ) {
248
+ for path , entry := range toRemoveConfigs {
249
+ entry .mu .Lock ()
250
+ if entry .projects .Len () == 0 && entry .infos .Len () == 0 {
251
+ c .ConfigFiles .Delete (path )
252
+ commandLine := entry .commandLine
253
+ entry .commandLine = nil
254
+ c .updateExtendedConfigsUsedBy (path , entry , commandLine )
255
+ if entry .rootFilesWatch != nil {
256
+ entry .rootFilesWatch .update (context .Background (), nil )
257
+ }
258
+ }
259
+ entry .mu .Unlock ()
260
+ }
261
+ }
0 commit comments