Skip to content

Commit 89593d5

Browse files
authored
Deduplicate watched file events, avoid MatchesFileName (#1308)
1 parent 05c0e2b commit 89593d5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

internal/project/configfileregistry.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ func (c *ConfigFileRegistry) tryInvokeWildCardDirectories(fileName string, path
239239
configFiles := c.ConfigFiles.ToMap()
240240
for configPath, entry := range configFiles {
241241
entry.mu.Lock()
242-
hasSet := entry.commandLine != nil && entry.commandLine.MatchesFileName(fileName) && entry.SetPendingReload(PendingReloadFileNames)
242+
hasSet := false
243+
if entry.commandLine != nil && entry.pendingReload == PendingReloadNone && entry.commandLine.MatchesFileName(fileName) {
244+
hasSet = entry.SetPendingReload(PendingReloadFileNames)
245+
}
243246
var projects map[*Project]struct{}
244247
if hasSet {
245248
projects = maps.Clone(entry.projects.Keys())

internal/project/service.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"sync"
1111

12+
"github.com/microsoft/typescript-go/internal/collections"
1213
"github.com/microsoft/typescript-go/internal/core"
1314
"github.com/microsoft/typescript-go/internal/ls"
1415
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
@@ -296,9 +297,15 @@ func (s *Service) Close() {
296297
}
297298

298299
func (s *Service) OnWatchedFilesChanged(ctx context.Context, changes []*lsproto.FileEvent) error {
300+
seen := collections.NewSetWithSizeHint[lsproto.FileEvent](len(changes))
301+
299302
s.projectsMu.RLock()
300303
defer s.projectsMu.RUnlock()
301304
for _, change := range changes {
305+
if !seen.AddIfAbsent(*change) {
306+
continue
307+
}
308+
302309
fileName := ls.DocumentURIToFileName(change.Uri)
303310
path := s.toPath(fileName)
304311
if err, ok := s.configFileRegistry.onWatchedFilesChanged(path, change.Type); ok {

0 commit comments

Comments
 (0)