@@ -54,6 +54,7 @@ type WatchedFiles[T any] struct {
5454 watchKind lsproto.WatchKind
5555 computeGlobPatterns func (input T ) patternsAndIgnored
5656
57+ mu sync.RWMutex
5758 input T
5859 computeWatchersOnce sync.Once
5960 watchers []* lsproto.FileSystemWatcher
@@ -70,8 +71,10 @@ func NewWatchedFiles[T any](name string, watchKind lsproto.WatchKind, computeGlo
7071 }
7172}
7273
73- func (w * WatchedFiles [T ]) Watchers () (WatcherID , []* lsproto.FileSystemWatcher ) {
74+ func (w * WatchedFiles [T ]) Watchers () (WatcherID , []* lsproto.FileSystemWatcher , map [ string ] struct {} ) {
7475 w .computeWatchersOnce .Do (func () {
76+ w .mu .Lock ()
77+ defer w .mu .Unlock ()
7578 result := w .computeGlobPatterns (w .input )
7679 globs := result .patterns
7780 ignored := result .ignored
@@ -91,7 +94,10 @@ func (w *WatchedFiles[T]) Watchers() (WatcherID, []*lsproto.FileSystemWatcher) {
9194 w .id = watcherID .Add (1 )
9295 }
9396 })
94- return WatcherID (fmt .Sprintf ("%s watcher %d" , w .name , w .id )), w .watchers
97+
98+ w .mu .RLock ()
99+ defer w .mu .RUnlock ()
100+ return WatcherID (fmt .Sprintf ("%s watcher %d" , w .name , w .id )), w .watchers , w .ignored
95101}
96102
97103func (w * WatchedFiles [T ]) ID () WatcherID {
@@ -111,6 +117,8 @@ func (w *WatchedFiles[T]) WatchKind() lsproto.WatchKind {
111117}
112118
113119func (w * WatchedFiles [T ]) Clone (input T ) * WatchedFiles [T ] {
120+ w .mu .RLock ()
121+ defer w .mu .RUnlock ()
114122 return & WatchedFiles [T ]{
115123 name : w .name ,
116124 watchKind : w .watchKind ,
0 commit comments