@@ -165,21 +165,54 @@ func (c *configFileRegistryBuilder) updateRootFilesWatch(fileName string, entry
165
165
return
166
166
}
167
167
168
- wildcardGlobs := entry .commandLine .WildcardDirectories ()
169
- rootFileGlobs := make ([]string , 0 , len (wildcardGlobs )+ 1 + len (entry .commandLine .ExtendedSourceFiles ()))
170
- rootFileGlobs = append (rootFileGlobs , fileName )
171
- for _ , extendedConfig := range entry .commandLine .ExtendedSourceFiles () {
172
- rootFileGlobs = append (rootFileGlobs , extendedConfig )
168
+ var globs []string
169
+ var externalFiles []string
170
+ var includeWorkspace bool
171
+ var includeTsconfigDir bool
172
+ canWatchWorkspace := canWatchDirectoryOrFile (tspath .GetPathComponents (c .sessionOptions .CurrentDirectory , "" ))
173
+ tsconfigDir := tspath .GetDirectoryPath (fileName )
174
+ canWatchTsconfigDir := canWatchDirectoryOrFile (tspath .GetPathComponents (tsconfigDir , "" ))
175
+ wildcardDirectories := entry .commandLine .WildcardDirectories ()
176
+ comparePathsOptions := tspath.ComparePathsOptions {
177
+ CurrentDirectory : c .sessionOptions .CurrentDirectory ,
178
+ UseCaseSensitiveFileNames : c .FS ().UseCaseSensitiveFileNames (),
173
179
}
174
- for dir , recursive := range wildcardGlobs {
175
- rootFileGlobs = append (rootFileGlobs , fmt .Sprintf ("%s/%s" , tspath .NormalizePath (dir ), core .IfElse (recursive , recursiveFileGlobPattern , fileGlobPattern )))
180
+ for dir := range wildcardDirectories {
181
+ if canWatchWorkspace && tspath .ContainsPath (c .sessionOptions .CurrentDirectory , dir , comparePathsOptions ) {
182
+ includeWorkspace = true
183
+ } else if canWatchTsconfigDir && tspath .ContainsPath (tsconfigDir , dir , comparePathsOptions ) {
184
+ includeTsconfigDir = true
185
+ } else {
186
+ externalFiles = append (externalFiles , dir )
187
+ }
176
188
}
177
189
for _ , fileName := range entry .commandLine .LiteralFileNames () {
178
- rootFileGlobs = append (rootFileGlobs , fileName )
190
+ if canWatchWorkspace && tspath .ContainsPath (c .sessionOptions .CurrentDirectory , fileName , comparePathsOptions ) {
191
+ includeWorkspace = true
192
+ } else if canWatchTsconfigDir && tspath .ContainsPath (tsconfigDir , fileName , comparePathsOptions ) {
193
+ includeTsconfigDir = true
194
+ } else {
195
+ externalFiles = append (externalFiles , fileName )
196
+ }
197
+ }
198
+
199
+ if includeWorkspace {
200
+ globs = append (globs , fmt .Sprintf ("%s/%s" , c .sessionOptions .CurrentDirectory , recursiveFileGlobPattern ))
201
+ }
202
+ if includeTsconfigDir {
203
+ globs = append (globs , fmt .Sprintf ("%s/%s" , tsconfigDir , recursiveFileGlobPattern ))
204
+ }
205
+ for _ , fileName := range entry .commandLine .ExtendedSourceFiles () {
206
+ globs = append (globs , fileName )
207
+ }
208
+ if len (externalFiles ) > 0 {
209
+ for _ , parent := range tspath .GetCommonParents (externalFiles , minWatchLocationDepth , comparePathsOptions ) {
210
+ globs = append (globs , fmt .Sprintf ("%s/%s" , parent , recursiveFileGlobPattern ))
211
+ }
179
212
}
180
213
181
- slices .Sort (rootFileGlobs )
182
- entry .rootFilesWatch = entry .rootFilesWatch .Clone (rootFileGlobs )
214
+ slices .Sort (globs )
215
+ entry .rootFilesWatch = entry .rootFilesWatch .Clone (globs )
183
216
}
184
217
185
218
// acquireConfigForProject loads a config file entry from the cache, or parses it if not already
0 commit comments