Skip to content

Commit 2c05e61

Browse files
committed
Remove checks to see if locations are watchable
1 parent 9369c83 commit 2c05e61

File tree

4 files changed

+25
-88
lines changed

4 files changed

+25
-88
lines changed

internal/project/configfileregistrybuilder.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,25 @@ func (c *configFileRegistryBuilder) updateRootFilesWatch(fileName string, entry
170170
var externalDirectories []string
171171
var includeWorkspace bool
172172
var includeTsconfigDir bool
173-
canWatchWorkspace := canWatchDirectoryOrFile(tspath.GetPathComponents(c.sessionOptions.CurrentDirectory, ""))
174173
tsconfigDir := tspath.GetDirectoryPath(fileName)
175-
canWatchTsconfigDir := canWatchDirectoryOrFile(tspath.GetPathComponents(tsconfigDir, ""))
176174
wildcardDirectories := entry.commandLine.WildcardDirectories()
177175
comparePathsOptions := tspath.ComparePathsOptions{
178176
CurrentDirectory: c.sessionOptions.CurrentDirectory,
179177
UseCaseSensitiveFileNames: c.FS().UseCaseSensitiveFileNames(),
180178
}
181179
for dir := range wildcardDirectories {
182-
if canWatchWorkspace && tspath.ContainsPath(c.sessionOptions.CurrentDirectory, dir, comparePathsOptions) {
180+
if tspath.ContainsPath(c.sessionOptions.CurrentDirectory, dir, comparePathsOptions) {
183181
includeWorkspace = true
184-
} else if canWatchTsconfigDir && tspath.ContainsPath(tsconfigDir, dir, comparePathsOptions) {
182+
} else if tspath.ContainsPath(tsconfigDir, dir, comparePathsOptions) {
185183
includeTsconfigDir = true
186184
} else {
187185
externalDirectories = append(externalDirectories, dir)
188186
}
189187
}
190188
for _, fileName := range entry.commandLine.LiteralFileNames() {
191-
if canWatchWorkspace && tspath.ContainsPath(c.sessionOptions.CurrentDirectory, fileName, comparePathsOptions) {
189+
if tspath.ContainsPath(c.sessionOptions.CurrentDirectory, fileName, comparePathsOptions) {
192190
includeWorkspace = true
193-
} else if canWatchTsconfigDir && tspath.ContainsPath(tsconfigDir, fileName, comparePathsOptions) {
191+
} else if tspath.ContainsPath(tsconfigDir, fileName, comparePathsOptions) {
194192
includeTsconfigDir = true
195193
} else {
196194
externalDirectories = append(externalDirectories, tspath.GetDirectoryPath(fileName))
@@ -210,7 +208,7 @@ func (c *configFileRegistryBuilder) updateRootFilesWatch(fileName string, entry
210208
globs = append(globs, fileName)
211209
}
212210
if len(externalDirectories) > 0 {
213-
commonParents, ignoredExternalDirs := tspath.GetCommonParents(externalDirectories, minWatchLocationDepth, getPathComponentsForWatching, comparePathsOptions)
211+
commonParents, ignoredExternalDirs := tspath.GetCommonParents(externalDirectories, minWatchLocationDepth, comparePathsOptions)
214212
for _, parent := range commonParents {
215213
globs = append(globs, getRecursiveGlobPattern(parent))
216214
}

internal/project/watch.go

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"maps"
66
"slices"
7-
"strings"
87
"sync"
98
"sync/atomic"
109

@@ -141,10 +140,8 @@ func (w *WatchedFiles[T]) Clone(input T) *WatchedFiles[T] {
141140
}
142141

143142
func createResolutionLookupGlobMapper(workspaceDirectory string, currentDirectory string, useCaseSensitiveFileNames bool) func(data map[tspath.Path]string) patternsAndIgnored {
144-
isWorkspaceWatchable := canWatchDirectoryOrFile(tspath.GetPathComponents(workspaceDirectory, ""))
145143
rootPath := tspath.ToPath(currentDirectory, "", useCaseSensitiveFileNames)
146144
rootPathComponents := tspath.GetPathComponents(string(rootPath), "")
147-
isRootWatchable := canWatchDirectoryOrFile(rootPathComponents)
148145
comparePathsOptions := tspath.ComparePathsOptions{
149146
CurrentDirectory: currentDirectory,
150147
UseCaseSensitiveFileNames: useCaseSensitiveFileNames,
@@ -164,10 +161,10 @@ func createResolutionLookupGlobMapper(workspaceDirectory string, currentDirector
164161
continue
165162
}
166163

167-
if isWorkspaceWatchable && tspath.ContainsPath(workspaceDirectory, fileName, comparePathsOptions) {
164+
if tspath.ContainsPath(workspaceDirectory, fileName, comparePathsOptions) {
168165
includeWorkspace = true
169166
continue
170-
} else if isRootWatchable && tspath.ContainsPath(rootPathComponents[0], fileName, comparePathsOptions) {
167+
} else if tspath.ContainsPath(rootPathComponents[0], fileName, comparePathsOptions) {
171168
includeRoot = true
172169
continue
173170
} else {
@@ -186,7 +183,7 @@ func createResolutionLookupGlobMapper(workspaceDirectory string, currentDirector
186183
globs = append(globs, getRecursiveGlobPattern(currentDirectory))
187184
}
188185
if len(externalDirectories) > 0 {
189-
externalDirectoryParents, ignoredExternalDirs := tspath.GetCommonParents(slices.Collect(maps.Values(externalDirectories)), minWatchLocationDepth, getPathComponentsForWatching, comparePathsOptions)
186+
externalDirectoryParents, ignoredExternalDirs := tspath.GetCommonParents(slices.Collect(maps.Values(externalDirectories)), minWatchLocationDepth, comparePathsOptions)
190187
slices.Sort(externalDirectoryParents)
191188
ignored = ignoredExternalDirs
192189
for _, dir := range externalDirectoryParents {
@@ -201,13 +198,6 @@ func createResolutionLookupGlobMapper(workspaceDirectory string, currentDirector
201198
}
202199
}
203200

204-
func getPathComponentsForWatching(path string, currentDirectory string) []string {
205-
components := tspath.GetPathComponents(path, currentDirectory)
206-
rootLength := perceivedOsRootLengthForWatching(components)
207-
newRoot := tspath.CombinePaths(components[0], components[1:rootLength]...)
208-
return append([]string{newRoot}, components[rootLength:]...)
209-
}
210-
211201
func getTypingsLocationsGlobs(
212202
typingsFiles []string,
213203
typingsLocation string,
@@ -217,7 +207,6 @@ func getTypingsLocationsGlobs(
217207
) patternsAndIgnored {
218208
var includeTypingsLocation, includeWorkspace bool
219209
externalDirectories := make(map[tspath.Path]string)
220-
isWorkspaceWatchable := canWatchDirectoryOrFile(tspath.GetPathComponents(workspaceDirectory, ""))
221210
globs := make(map[tspath.Path]string)
222211
comparePathsOptions := tspath.ComparePathsOptions{
223212
CurrentDirectory: currentDirectory,
@@ -226,14 +215,14 @@ func getTypingsLocationsGlobs(
226215
for _, file := range typingsFiles {
227216
if tspath.ContainsPath(typingsLocation, file, comparePathsOptions) {
228217
includeTypingsLocation = true
229-
} else if !isWorkspaceWatchable || !tspath.ContainsPath(workspaceDirectory, file, comparePathsOptions) {
218+
} else if !tspath.ContainsPath(workspaceDirectory, file, comparePathsOptions) {
230219
directory := tspath.GetDirectoryPath(file)
231220
externalDirectories[tspath.ToPath(directory, currentDirectory, useCaseSensitiveFileNames)] = directory
232221
} else {
233222
includeWorkspace = true
234223
}
235224
}
236-
externalDirectoryParents, ignored := tspath.GetCommonParents(slices.Collect(maps.Values(externalDirectories)), minWatchLocationDepth, getPathComponentsForWatching, comparePathsOptions)
225+
externalDirectoryParents, ignored := tspath.GetCommonParents(slices.Collect(maps.Values(externalDirectories)), minWatchLocationDepth, comparePathsOptions)
237226
slices.Sort(externalDirectoryParents)
238227
if includeWorkspace {
239228
globs[tspath.ToPath(workspaceDirectory, currentDirectory, useCaseSensitiveFileNames)] = getRecursiveGlobPattern(workspaceDirectory)
@@ -250,54 +239,6 @@ func getTypingsLocationsGlobs(
250239
}
251240
}
252241

253-
func perceivedOsRootLengthForWatching(pathComponents []string) int {
254-
length := len(pathComponents)
255-
// Ignore "/", "c:/"
256-
if length <= 1 {
257-
return 1
258-
}
259-
indexAfterOsRoot := 1
260-
firstComponent := pathComponents[0]
261-
isDosStyle := len(firstComponent) >= 2 && tspath.IsVolumeCharacter(firstComponent[0]) && firstComponent[1] == ':'
262-
if firstComponent != "/" && !isDosStyle && isDosStyleNextPart(pathComponents[1]) {
263-
// ignore "//vda1cs4850/c$/folderAtRoot"
264-
if length == 2 {
265-
return 2
266-
}
267-
indexAfterOsRoot = 2
268-
isDosStyle = true
269-
}
270-
271-
afterOsRoot := pathComponents[indexAfterOsRoot]
272-
if isDosStyle && !strings.EqualFold(afterOsRoot, "users") {
273-
// Paths like c:/notUsers
274-
return indexAfterOsRoot
275-
}
276-
277-
if strings.EqualFold(afterOsRoot, "workspaces") {
278-
// Paths like: /workspaces as codespaces hoist the repos in /workspaces so we have to exempt these from "2" level from root rule
279-
return indexAfterOsRoot + 1
280-
}
281-
282-
// Paths like: c:/users/username or /home/username
283-
return indexAfterOsRoot + 2
284-
}
285-
286-
func canWatchDirectoryOrFile(pathComponents []string) bool {
287-
length := len(pathComponents)
288-
// Ignore "/", "c:/"
289-
// ignore "/user", "c:/users" or "c:/folderAtRoot"
290-
if length < minWatchLocationDepth {
291-
return false
292-
}
293-
perceivedOsRootLength := perceivedOsRootLengthForWatching(pathComponents)
294-
return (length - perceivedOsRootLength) >= minWatchLocationDepth
295-
}
296-
297-
func isDosStyleNextPart(part string) bool {
298-
return len(part) == 2 && tspath.IsVolumeCharacter(part[0]) && part[1] == '$'
299-
}
300-
301242
func ptrTo[T any](v T) *T {
302243
return &v
303244
}
@@ -334,11 +275,10 @@ func getNonRootFileGlobs(workspaceDir string, sourceFiles []*ast.SourceFile, roo
334275
var globs []string
335276
var includeWorkspace bool
336277
var ignored map[string]struct{}
337-
canWatchWorkspace := canWatchDirectoryOrFile(tspath.GetPathComponents(workspaceDir, ""))
338278
externalDirectories := make([]string, 0, max(0, len(sourceFiles)-len(rootFiles)))
339279
for _, sourceFile := range sourceFiles {
340280
if _, ok := rootFiles[sourceFile.Path()]; !ok {
341-
if canWatchWorkspace && tspath.ContainsPath(workspaceDir, sourceFile.FileName(), comparePathsOptions) {
281+
if tspath.ContainsPath(workspaceDir, sourceFile.FileName(), comparePathsOptions) {
342282
includeWorkspace = true
343283
continue
344284
}
@@ -350,7 +290,7 @@ func getNonRootFileGlobs(workspaceDir string, sourceFiles []*ast.SourceFile, roo
350290
globs = append(globs, getRecursiveGlobPattern(workspaceDir))
351291
}
352292
if len(externalDirectories) > 0 {
353-
commonParents, ignoredDirs := tspath.GetCommonParents(externalDirectories, minWatchLocationDepth, getPathComponentsForWatching, comparePathsOptions)
293+
commonParents, ignoredDirs := tspath.GetCommonParents(externalDirectories, minWatchLocationDepth, comparePathsOptions)
354294
globs = append(globs, core.Map(commonParents, func(dir string) string {
355295
return getRecursiveGlobPattern(dir)
356296
})...)

internal/tspath/path.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,6 @@ func SplitVolumePath(path string) (volume string, rest string, ok bool) {
10361036
func GetCommonParents(
10371037
paths []string,
10381038
minComponents int,
1039-
getPathComponents func(path string, currentDirectory string) []string,
10401039
options ComparePathsOptions,
10411040
) (parents []string, ignored map[string]struct{}) {
10421041
if minComponents < 1 {
@@ -1046,7 +1045,7 @@ func GetCommonParents(
10461045
return nil, nil
10471046
}
10481047
if len(paths) == 1 {
1049-
if len(reducePathComponents(getPathComponents(paths[0], options.CurrentDirectory))) < minComponents {
1048+
if len(reducePathComponents(GetPathComponents(paths[0], options.CurrentDirectory))) < minComponents {
10501049
return nil, map[string]struct{}{paths[0]: {}}
10511050
}
10521051
return paths, nil
@@ -1055,7 +1054,7 @@ func GetCommonParents(
10551054
ignored = make(map[string]struct{})
10561055
pathComponents := make([][]string, 0, len(paths))
10571056
for _, path := range paths {
1058-
components := reducePathComponents(getPathComponents(path, options.CurrentDirectory))
1057+
components := reducePathComponents(GetPathComponents(path, options.CurrentDirectory))
10591058
if len(components) < minComponents {
10601059
ignored[path] = struct{}{}
10611060
} else {

internal/tspath/path_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -713,15 +713,15 @@ func TestGetCommonParents(t *testing.T) {
713713
t.Run("empty input", func(t *testing.T) {
714714
t.Parallel()
715715
var paths []string
716-
got, ignored := GetCommonParents(paths, 1, GetPathComponents, opts)
716+
got, ignored := GetCommonParents(paths, 1, opts)
717717
assert.Equal(t, len(ignored), 0)
718718
assert.DeepEqual(t, got, ([]string)(nil))
719719
})
720720

721721
t.Run("single path returns itself", func(t *testing.T) {
722722
t.Parallel()
723723
paths := []string{"/a/b/c/d"}
724-
got, ignored := GetCommonParents(paths, 1, GetPathComponents, opts)
724+
got, ignored := GetCommonParents(paths, 1, opts)
725725
assert.Equal(t, len(ignored), 0)
726726
expected := []string{paths[0]}
727727
assert.DeepEqual(t, got, expected)
@@ -730,7 +730,7 @@ func TestGetCommonParents(t *testing.T) {
730730
t.Run("paths shorter than minComponents are ignored", func(t *testing.T) {
731731
t.Parallel()
732732
paths := []string{"/a/b/c/d", "/a/b/c/e", "/a/b/f/g", "/x/y"}
733-
got, ignored := GetCommonParents(paths, 4, GetPathComponents, opts)
733+
got, ignored := GetCommonParents(paths, 4, opts)
734734
assert.DeepEqual(t, ignored, []string{"/x/y"})
735735
expected := []string{"/a/b/c", "/a/b/f/g"}
736736
assert.DeepEqual(t, got, expected)
@@ -739,7 +739,7 @@ func TestGetCommonParents(t *testing.T) {
739739
t.Run("three paths share /a/b", func(t *testing.T) {
740740
t.Parallel()
741741
paths := []string{"/a/b/c/d", "/a/b/c/e", "/a/b/f/g"}
742-
got, ignored := GetCommonParents(paths, 1, GetPathComponents, opts)
742+
got, ignored := GetCommonParents(paths, 1, opts)
743743
assert.Equal(t, len(ignored), 0)
744744
expected := []string{"/a/b"}
745745
assert.DeepEqual(t, got, expected)
@@ -748,7 +748,7 @@ func TestGetCommonParents(t *testing.T) {
748748
t.Run("mixed with short path collapses to root when minComponents=1", func(t *testing.T) {
749749
t.Parallel()
750750
paths := []string{"/a/b/c/d", "/a/b/c/e", "/a/b/f/g", "/x/y/z"}
751-
got, ignored := GetCommonParents(paths, 1, GetPathComponents, opts)
751+
got, ignored := GetCommonParents(paths, 1, opts)
752752
assert.Equal(t, len(ignored), 0)
753753
expected := []string{"/"}
754754
assert.DeepEqual(t, got, expected)
@@ -757,7 +757,7 @@ func TestGetCommonParents(t *testing.T) {
757757
t.Run("mixed with short path preserves both when minComponents=3", func(t *testing.T) {
758758
t.Parallel()
759759
paths := []string{"/a/b/c/d", "/a/b/c/e", "/a/b/f/g", "/x/y/z"}
760-
got, ignored := GetCommonParents(paths, 3, GetPathComponents, opts)
760+
got, ignored := GetCommonParents(paths, 3, opts)
761761
assert.Equal(t, len(ignored), 0)
762762
expected := []string{"/a/b", "/x/y/z"}
763763
assert.DeepEqual(t, got, expected)
@@ -766,7 +766,7 @@ func TestGetCommonParents(t *testing.T) {
766766
t.Run("different volumes are returned individually", func(t *testing.T) {
767767
t.Parallel()
768768
paths := []string{"c:/a/b/c/d", "d:/a/b/c/d"}
769-
got, ignored := GetCommonParents(paths, 1, GetPathComponents, opts)
769+
got, ignored := GetCommonParents(paths, 1, opts)
770770
assert.Equal(t, len(ignored), 0)
771771
expected := []string{paths[0], paths[1]}
772772
assert.DeepEqual(t, got, expected)
@@ -775,7 +775,7 @@ func TestGetCommonParents(t *testing.T) {
775775
t.Run("duplicate paths deduplicate result", func(t *testing.T) {
776776
t.Parallel()
777777
paths := []string{"/a/b/c/d", "/a/b/c/d"}
778-
got, ignored := GetCommonParents(paths, 1, GetPathComponents, opts)
778+
got, ignored := GetCommonParents(paths, 1, opts)
779779
assert.Equal(t, len(ignored), 0)
780780
expected := []string{paths[0]}
781781
assert.DeepEqual(t, got, expected)
@@ -784,7 +784,7 @@ func TestGetCommonParents(t *testing.T) {
784784
t.Run("paths with few components are returned as-is when minComponents met", func(t *testing.T) {
785785
t.Parallel()
786786
paths := []string{"/a/b/c/d", "/x/y"}
787-
got, ignored := GetCommonParents(paths, 2, GetPathComponents, opts)
787+
got, ignored := GetCommonParents(paths, 2, opts)
788788
assert.Equal(t, len(ignored), 0)
789789
expected := []string{"/a/b/c/d", "/x/y"}
790790
assert.DeepEqual(t, got, expected)
@@ -793,7 +793,7 @@ func TestGetCommonParents(t *testing.T) {
793793
t.Run("minComponents=2", func(t *testing.T) {
794794
t.Parallel()
795795
paths := []string{"/a/b/c/d", "/a/z/c/e", "/a/aaa/f/g", "/x/y/z"}
796-
got, ignored := GetCommonParents(paths, 2, GetPathComponents, opts)
796+
got, ignored := GetCommonParents(paths, 2, opts)
797797
assert.Equal(t, len(ignored), 0)
798798
expected := []string{"/a", "/x/y/z"}
799799
assert.DeepEqual(t, got, expected)
@@ -802,7 +802,7 @@ func TestGetCommonParents(t *testing.T) {
802802
t.Run("trailing separators are handled", func(t *testing.T) {
803803
t.Parallel()
804804
paths := []string{"/a/b/", "/a/b/c"}
805-
got, ignored := GetCommonParents(paths, 1, GetPathComponents, opts)
805+
got, ignored := GetCommonParents(paths, 1, opts)
806806
assert.Equal(t, len(ignored), 0)
807807
expected := []string{"/a/b"}
808808
assert.DeepEqual(t, got, expected)

0 commit comments

Comments
 (0)