Skip to content

Commit 9369c83

Browse files
committed
Use GetCommonParents instead of node_modules strategy
1 parent a0af908 commit 9369c83

File tree

7 files changed

+157
-243
lines changed

7 files changed

+157
-243
lines changed

internal/project/configfileregistry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type configFileEntry struct {
4141
// when this is set, no other fields will be used.
4242
retainingConfigs map[tspath.Path]struct{}
4343
// rootFilesWatch is a watch for the root files of this config file.
44-
rootFilesWatch *WatchedFiles[[]string]
44+
rootFilesWatch *WatchedFiles[patternsAndIgnored]
4545
}
4646

4747
func newConfigFileEntry(fileName string) *configFileEntry {

internal/project/configfileregistrybuilder.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func (c *configFileRegistryBuilder) updateRootFilesWatch(fileName string, entry
165165
return
166166
}
167167

168+
var ignored map[string]struct{}
168169
var globs []string
169170
var externalDirectories []string
170171
var includeWorkspace bool
@@ -197,10 +198,10 @@ func (c *configFileRegistryBuilder) updateRootFilesWatch(fileName string, entry
197198
}
198199

199200
if includeWorkspace {
200-
globs = append(globs, fmt.Sprintf("%s/%s", c.sessionOptions.CurrentDirectory, recursiveFileGlobPattern))
201+
globs = append(globs, getRecursiveGlobPattern(c.sessionOptions.CurrentDirectory))
201202
}
202203
if includeTsconfigDir {
203-
globs = append(globs, fmt.Sprintf("%s/%s", tsconfigDir, recursiveFileGlobPattern))
204+
globs = append(globs, getRecursiveGlobPattern(tsconfigDir))
204205
}
205206
for _, fileName := range entry.commandLine.ExtendedSourceFiles() {
206207
if includeWorkspace && tspath.ContainsPath(c.sessionOptions.CurrentDirectory, fileName, comparePathsOptions) {
@@ -209,13 +210,18 @@ func (c *configFileRegistryBuilder) updateRootFilesWatch(fileName string, entry
209210
globs = append(globs, fileName)
210211
}
211212
if len(externalDirectories) > 0 {
212-
for _, parent := range tspath.GetCommonParents(externalDirectories, minWatchLocationDepth, comparePathsOptions) {
213-
globs = append(globs, fmt.Sprintf("%s/%s", parent, recursiveFileGlobPattern))
213+
commonParents, ignoredExternalDirs := tspath.GetCommonParents(externalDirectories, minWatchLocationDepth, getPathComponentsForWatching, comparePathsOptions)
214+
for _, parent := range commonParents {
215+
globs = append(globs, getRecursiveGlobPattern(parent))
214216
}
217+
ignored = ignoredExternalDirs
215218
}
216219

217220
slices.Sort(globs)
218-
entry.rootFilesWatch = entry.rootFilesWatch.Clone(globs)
221+
entry.rootFilesWatch = entry.rootFilesWatch.Clone(patternsAndIgnored{
222+
patterns: globs,
223+
ignored: ignored,
224+
})
219225
}
220226

221227
// acquireConfigForProject loads a config file entry from the cache, or parses it if not already

internal/project/project.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ type Project struct {
7272
// The ID of the snapshot that created the program stored in this project.
7373
ProgramLastUpdate uint64
7474

75-
programFilesWatch *WatchedFiles[[]string]
75+
programFilesWatch *WatchedFiles[patternsAndIgnored]
7676
failedLookupsWatch *WatchedFiles[map[tspath.Path]string]
7777
affectingLocationsWatch *WatchedFiles[map[tspath.Path]string]
78-
typingsWatch *WatchedFiles[map[tspath.Path]string]
78+
typingsWatch *WatchedFiles[patternsAndIgnored]
7979

8080
checkerPool *checkerPool
8181

@@ -168,7 +168,7 @@ func NewProject(
168168
project.typingsWatch = NewWatchedFiles(
169169
"typings installer files",
170170
lsproto.WatchKindCreate|lsproto.WatchKindChange|lsproto.WatchKindDelete,
171-
globMapperForTypingsInstaller,
171+
core.Identity,
172172
)
173173
}
174174
}
@@ -331,7 +331,7 @@ func (p *Project) CreateProgram() CreateProgramResult {
331331
}
332332
}
333333

334-
func (p *Project) CloneWatchers(workspaceDir string) (programFilesWatch *WatchedFiles[[]string], failedLookupsWatch *WatchedFiles[map[tspath.Path]string], affectingLocationsWatch *WatchedFiles[map[tspath.Path]string]) {
334+
func (p *Project) CloneWatchers(workspaceDir string) (programFilesWatch *WatchedFiles[patternsAndIgnored], failedLookupsWatch *WatchedFiles[map[tspath.Path]string], affectingLocationsWatch *WatchedFiles[map[tspath.Path]string]) {
335335
failedLookups := make(map[tspath.Path]string)
336336
affectingLocations := make(map[tspath.Path]string)
337337
programFiles := getNonRootFileGlobs(workspaceDir, p.Program.GetSourceFiles(), p.CommandLine.FileNamesByPath(), tspath.ComparePathsOptions{

internal/project/session.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,14 @@ func updateWatch[T any](ctx context.Context, session *Session, logger logging.Lo
449449
logger.Log("")
450450
}
451451
}
452+
if len(newWatcher.ignored) > 0 {
453+
logger.Logf("%d paths ineligible for watching", len(newWatcher.ignored))
454+
if logger.IsVerbose() {
455+
for path := range newWatcher.ignored {
456+
logger.Log("\t" + path)
457+
}
458+
}
459+
}
452460
}
453461
}
454462
if oldWatcher != nil {

0 commit comments

Comments
 (0)