Skip to content

Commit 222917e

Browse files
authored
Ensure globs are always sorted (#1027)
1 parent 0f77c42 commit 222917e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

internal/project/service_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,19 +543,19 @@ func TestService(t *testing.T) {
543543
{
544544
Kind: ptrTo(lsproto.WatchKindCreate | lsproto.WatchKindChange | lsproto.WatchKindDelete),
545545
GlobPattern: lsproto.GlobPattern{
546-
Pattern: ptrTo("/home/projects/TS/p1/tsconfig.json"),
546+
Pattern: ptrTo("/home/projects/TS/p1/src/index.ts"),
547547
},
548548
},
549549
{
550550
Kind: ptrTo(lsproto.WatchKindCreate | lsproto.WatchKindChange | lsproto.WatchKindDelete),
551551
GlobPattern: lsproto.GlobPattern{
552-
Pattern: ptrTo("/home/projects/TS/p1/src/index.ts"),
552+
Pattern: ptrTo("/home/projects/TS/p1/src/y.ts"),
553553
},
554554
},
555555
{
556556
Kind: ptrTo(lsproto.WatchKindCreate | lsproto.WatchKindChange | lsproto.WatchKindDelete),
557557
GlobPattern: lsproto.GlobPattern{
558-
Pattern: ptrTo("/home/projects/TS/p1/src/y.ts"),
558+
Pattern: ptrTo("/home/projects/TS/p1/tsconfig.json"),
559559
},
560560
},
561561
})

internal/project/watch.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func (w *watchedFiles[T]) update(ctx context.Context, newData T) {
5353

5454
func (w *watchedFiles[T]) updateWorker(ctx context.Context, newData T) (updated bool, err error) {
5555
newGlobs := w.getGlobs(newData)
56+
newGlobs = slices.Clone(newGlobs)
57+
slices.Sort(newGlobs)
58+
5659
w.data = newData
5760
if slices.Equal(w.globs, newGlobs) {
5861
return false, nil
@@ -88,7 +91,7 @@ func (w *watchedFiles[T]) updateWorker(ctx context.Context, newData T) (updated
8891
}
8992

9093
func globMapperForTypingsInstaller(data map[tspath.Path]string) []string {
91-
return slices.Sorted(maps.Values(data))
94+
return slices.AppendSeq(make([]string, 0, len(data)), maps.Values(data))
9295
}
9396

9497
func createResolutionLookupGlobMapper(host ProjectHost) func(data map[tspath.Path]string) []string {
@@ -136,7 +139,6 @@ func createResolutionLookupGlobMapper(host ProjectHost) func(data map[tspath.Pat
136139
globs = append(globs, dir+"/"+fileGlobPattern)
137140
}
138141
}
139-
slices.Sort(globs)
140142

141143
timeTaken := time.Since(start)
142144
host.Log(fmt.Sprintf("createGlobMapper took %s to create %d globs for %d failed lookups", timeTaken, len(globs), len(data)))

0 commit comments

Comments
 (0)