ttsc 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/go.mod +1 -1
  2. package/internal/lspserver/lsp_launcher_reload_directory_fingerprint_parity_windows_test.go +94 -0
  3. package/internal/lspserver/lsp_project_input_glob_path_other.go +16 -0
  4. package/internal/lspserver/lsp_project_input_glob_path_windows.go +36 -0
  5. package/internal/lspserver/lsp_project_input_path_key_other.go +17 -0
  6. package/internal/lspserver/lsp_project_input_path_key_windows.go +228 -0
  7. package/internal/lspserver/lsp_project_input_path_key_windows_test.go +460 -0
  8. package/internal/lspserver/lsp_project_inputs.go +117 -49
  9. package/internal/lspserver/lsp_reload_directories_separate_glob_territory_test.go +181 -0
  10. package/lib/flags/schema.js +1 -1
  11. package/lib/flags/schema.js.map +1 -1
  12. package/lib/internal/projectInputPathIdentity.d.ts +13 -5
  13. package/lib/internal/projectInputPathIdentity.js +95 -41
  14. package/lib/internal/projectInputPathIdentity.js.map +1 -1
  15. package/lib/internal/windowsDirectoryCaseSensitivity.d.ts +10 -0
  16. package/lib/internal/windowsDirectoryCaseSensitivity.js +34 -0
  17. package/lib/internal/windowsDirectoryCaseSensitivity.js.map +1 -0
  18. package/lib/launcher/internal/runTtsc.js +5 -0
  19. package/lib/launcher/internal/runTtsc.js.map +1 -1
  20. package/lib/launcher/internal/runTtscserver.js +59 -8
  21. package/lib/launcher/internal/runTtscserver.js.map +1 -1
  22. package/lib/launcher/internal/runTtsx.js +61 -7
  23. package/lib/launcher/internal/runTtsx.js.map +1 -1
  24. package/lib/launcher/internal/runtimeHooks.d.ts +6 -5
  25. package/lib/launcher/internal/runtimeHooks.js +7 -15
  26. package/lib/launcher/internal/runtimeHooks.js.map +1 -1
  27. package/lib/launcher/internal/watchTopology.d.ts +82 -8
  28. package/lib/launcher/internal/watchTopology.js +535 -187
  29. package/lib/launcher/internal/watchTopology.js.map +1 -1
  30. package/lib/plugin/internal/descriptorProcessFailure.d.ts +32 -0
  31. package/lib/plugin/internal/descriptorProcessFailure.js +73 -0
  32. package/lib/plugin/internal/descriptorProcessFailure.js.map +1 -0
  33. package/lib/plugin/internal/loadProjectPlugins.js +29 -8
  34. package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
  35. package/package.json +12 -8
  36. package/src/flags/schema.ts +2 -1
  37. package/src/internal/projectInputPathIdentity.ts +150 -46
  38. package/src/internal/windowsDirectoryCaseSensitivity.ts +33 -0
  39. package/src/launcher/internal/runTtsc.ts +7 -0
  40. package/src/launcher/internal/runTtscserver.ts +81 -11
  41. package/src/launcher/internal/runTtsx.ts +87 -10
  42. package/src/launcher/internal/runtimeHooks.ts +16 -16
  43. package/src/launcher/internal/watchTopology.ts +679 -208
  44. package/src/plugin/internal/descriptorProcessFailure.ts +100 -0
  45. package/src/plugin/internal/loadProjectPlugins.ts +41 -8
  46. package/tools/shim_audit/baseline.json +0 -9
package/go.mod CHANGED
@@ -41,6 +41,7 @@ require (
41
41
  github.com/microsoft/typescript-go/shim/vfs v0.0.0
42
42
  github.com/microsoft/typescript-go/shim/vfs/cachedvfs v0.0.0
43
43
  github.com/microsoft/typescript-go/shim/vfs/osvfs v0.0.0
44
+ golang.org/x/sys v0.43.0
44
45
  )
45
46
 
46
47
  require (
@@ -49,6 +50,5 @@ require (
49
50
  github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157 // indirect
50
51
  github.com/zeebo/xxh3 v1.1.0 // indirect
51
52
  golang.org/x/sync v0.20.0 // indirect
52
- golang.org/x/sys v0.43.0 // indirect
53
53
  golang.org/x/text v0.36.0 // indirect
54
54
  )
@@ -0,0 +1,94 @@
1
+ //go:build windows
2
+
3
+ package lspserver
4
+
5
+ import (
6
+ "os"
7
+ "os/exec"
8
+ "path/filepath"
9
+ "strings"
10
+ "testing"
11
+ )
12
+
13
+ // TestLauncherReloadDirectoryFingerprintMatchesGo verifies that the JavaScript
14
+ // launcher and Go host serialize the same Windows physical directory identity.
15
+ //
16
+ // The launcher formerly retained a physical drive volume while Go lowercased
17
+ // it, and the two sides also disagreed about case folding for a missing suffix.
18
+ // A stable launcher snapshot was therefore rejected as stale during native
19
+ // watcher registration.
20
+ //
21
+ // 1. Ask the built JavaScript launcher to fingerprint one existing directory
22
+ // and one missing descendant under an ordinary case-insensitive parent.
23
+ // 2. Pass each launcher-produced digest through the real Go snapshot
24
+ // normalization path.
25
+ // 3. Prove the Go currentness validator accepts both unchanged directories.
26
+ func TestLauncherReloadDirectoryFingerprintMatchesGo(t *testing.T) {
27
+ root := t.TempDir()
28
+ existing := filepath.Join(root, "ExistingDirectory")
29
+ if err := os.Mkdir(existing, 0o755); err != nil {
30
+ t.Fatal(err)
31
+ }
32
+ for _, directory := range []string{
33
+ existing,
34
+ filepath.Join(root, "MissingDirectory"),
35
+ } {
36
+ digest := launcherReloadDirectoryDigest(t, root, directory)
37
+ snapshot, err := normalizeLSPProjectInputSnapshot(
38
+ LSPProjectInputSnapshot{
39
+ Root: root,
40
+ ReloadDirectories: []string{directory},
41
+ ReloadDirectoryDigests: map[string]string{
42
+ directory: digest,
43
+ },
44
+ },
45
+ root,
46
+ )
47
+ if err != nil {
48
+ t.Fatalf("normalize launcher fingerprint for %q: %v", directory, err)
49
+ }
50
+ if !projectInputReloadFingerprintsAreCurrent(snapshot) {
51
+ t.Fatalf("launcher fingerprint for %q began stale in Go", directory)
52
+ }
53
+ }
54
+ }
55
+
56
+ func launcherReloadDirectoryDigest(
57
+ t *testing.T,
58
+ root string,
59
+ directory string,
60
+ ) string {
61
+ t.Helper()
62
+ module, err := filepath.Abs(
63
+ filepath.Join("..", "..", "lib", "launcher", "internal", "runTtscserver.js"),
64
+ )
65
+ if err != nil {
66
+ t.Fatal(err)
67
+ }
68
+ script := `
69
+ import { pathToFileURL } from "node:url";
70
+ const launcher = await import(pathToFileURL(process.argv[1]).href);
71
+ const location = process.argv[2];
72
+ const snapshot = launcher.fingerprintInitialLSPProjectInputSnapshot({
73
+ files: [],
74
+ globs: [],
75
+ reloadDirectories: [location],
76
+ root: process.argv[3],
77
+ });
78
+ process.stdout.write(snapshot.reloadDirectoryDigests[location]);
79
+ `
80
+ command := exec.Command(
81
+ "node",
82
+ "--input-type=module",
83
+ "--eval",
84
+ script,
85
+ module,
86
+ directory,
87
+ root,
88
+ )
89
+ output, err := command.CombinedOutput()
90
+ if err != nil {
91
+ t.Fatalf("launcher fingerprint for %q: %v\n%s", directory, err, output)
92
+ }
93
+ return strings.TrimSpace(string(output))
94
+ }
@@ -0,0 +1,16 @@
1
+ //go:build !windows
2
+
3
+ package lspserver
4
+
5
+ import "strings"
6
+
7
+ func projectInputGlobMatchesCandidate(
8
+ pattern string,
9
+ candidate string,
10
+ ) bool {
11
+ return matchProjectInputGlob(
12
+ strings.Split(projectInputPathKey(realProjectInputPath(pattern)), "/"),
13
+ strings.Split(projectInputPathKey(realProjectInputPath(candidate)), "/"),
14
+ nil,
15
+ )
16
+ }
@@ -0,0 +1,36 @@
1
+ //go:build windows
2
+
3
+ package lspserver
4
+
5
+ import (
6
+ "path/filepath"
7
+ "strings"
8
+ )
9
+
10
+ func projectInputGlobMatchesCandidate(
11
+ pattern string,
12
+ candidate string,
13
+ ) bool {
14
+ resolvedPattern := resolveWindowsProjectInputPath(pattern)
15
+ resolvedCandidate := resolveWindowsProjectInputPath(candidate)
16
+ if !resolvedPattern.found || !resolvedCandidate.found {
17
+ return false
18
+ }
19
+ patternVolume := strings.ToLower(
20
+ filepath.ToSlash(filepath.VolumeName(resolvedPattern.physical)),
21
+ )
22
+ candidateVolume := strings.ToLower(
23
+ filepath.ToSlash(filepath.VolumeName(resolvedCandidate.physical)),
24
+ )
25
+ if patternVolume != candidateVolume {
26
+ return false
27
+ }
28
+ patternSegments, _ := windowsProjectInputSegments(resolvedPattern)
29
+ candidateSegments, candidateSensitivities :=
30
+ windowsProjectInputSegments(resolvedCandidate)
31
+ return matchProjectInputGlob(
32
+ patternSegments,
33
+ candidateSegments,
34
+ candidateSensitivities,
35
+ )
36
+ }
@@ -0,0 +1,17 @@
1
+ //go:build !windows
2
+
3
+ package lspserver
4
+
5
+ import "path/filepath"
6
+
7
+ func physicalProjectInputPath(location string) (string, error) {
8
+ return filepath.EvalSymlinks(location)
9
+ }
10
+
11
+ func projectInputPhysicalPathKey(location string) string {
12
+ return filepath.ToSlash(realProjectInputPath(location))
13
+ }
14
+
15
+ func projectInputPathKey(location string) string {
16
+ return filepath.ToSlash(filepath.Clean(filepath.FromSlash(location)))
17
+ }
@@ -0,0 +1,228 @@
1
+ //go:build windows
2
+
3
+ package lspserver
4
+
5
+ import (
6
+ "path/filepath"
7
+ "strings"
8
+ "unsafe"
9
+
10
+ "golang.org/x/sys/windows"
11
+ )
12
+
13
+ type windowsProjectInputPath struct {
14
+ found bool
15
+ missing []string
16
+ physical string
17
+ }
18
+
19
+ // projectInputPathKey resolves existing spelling through the filesystem and
20
+ // applies case folding to each segment according to the directory that owns
21
+ // that name. Windows case semantics are per directory, not per volume or OS.
22
+ func projectInputPathKey(location string) string {
23
+ normalized := filepath.Clean(projectInputFilesystemPath(location))
24
+ if !filepath.IsAbs(normalized) {
25
+ return strings.ToLower(filepath.ToSlash(normalized))
26
+ }
27
+ volume := filepath.VolumeName(normalized)
28
+ segments := splitWindowsProjectInputSegments(
29
+ strings.TrimPrefix(normalized, volume),
30
+ )
31
+ current := windowsProjectInputVolumeRoot(volume)
32
+ sensitive := false
33
+ for index, segment := range segments {
34
+ if currentSensitivity, ok :=
35
+ tryQueryProjectInputDirectoryCaseSensitivity(current); ok {
36
+ sensitive = currentSensitivity
37
+ }
38
+ if !sensitive {
39
+ segments[index] = strings.ToLower(segments[index])
40
+ }
41
+ current = filepath.Join(current, segment)
42
+ }
43
+ return windowsProjectInputKey(normalized, segments)
44
+ }
45
+
46
+ func resolveWindowsProjectInputPath(location string) windowsProjectInputPath {
47
+ normalized := filepath.Clean(projectInputFilesystemPath(location))
48
+ if !filepath.IsAbs(normalized) {
49
+ return windowsProjectInputPath{physical: normalized}
50
+ }
51
+ probe := normalized
52
+ missing := []string{}
53
+ for {
54
+ physical, err := physicalProjectInputPath(probe)
55
+ if err == nil {
56
+ return windowsProjectInputPath{
57
+ found: true,
58
+ missing: reverseWindowsProjectInputSegments(missing),
59
+ physical: filepath.Clean(physical),
60
+ }
61
+ }
62
+ parent := filepath.Dir(probe)
63
+ if parent == probe {
64
+ return windowsProjectInputPath{physical: normalized}
65
+ }
66
+ missing = append(missing, filepath.Base(probe))
67
+ probe = parent
68
+ }
69
+ }
70
+
71
+ func physicalProjectInputPath(location string) (string, error) {
72
+ pointer, err := windows.UTF16PtrFromString(location)
73
+ if err != nil {
74
+ return "", err
75
+ }
76
+ handle, err := windows.CreateFile(
77
+ pointer,
78
+ windows.FILE_READ_ATTRIBUTES,
79
+ windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE|windows.FILE_SHARE_DELETE,
80
+ nil,
81
+ windows.OPEN_EXISTING,
82
+ windows.FILE_FLAG_BACKUP_SEMANTICS,
83
+ 0,
84
+ )
85
+ if err != nil {
86
+ return "", err
87
+ }
88
+ defer windows.CloseHandle(handle)
89
+
90
+ buffer := make([]uint16, windows.MAX_PATH)
91
+ for {
92
+ length, err := windows.GetFinalPathNameByHandle(
93
+ handle,
94
+ &buffer[0],
95
+ uint32(len(buffer)),
96
+ 0,
97
+ )
98
+ if err != nil {
99
+ return "", err
100
+ }
101
+ if length < uint32(len(buffer)) {
102
+ return filepath.Clean(
103
+ projectInputFilesystemPath(
104
+ windows.UTF16ToString(buffer[:length]),
105
+ ),
106
+ ), nil
107
+ }
108
+ buffer = make([]uint16, length+1)
109
+ }
110
+ }
111
+
112
+ func projectInputPhysicalPathKey(location string) string {
113
+ resolved := resolveWindowsProjectInputPath(location)
114
+ volume := filepath.VolumeName(resolved.physical)
115
+ segments := splitWindowsProjectInputSegments(
116
+ strings.TrimPrefix(resolved.physical, volume),
117
+ )
118
+ if len(resolved.missing) != 0 {
119
+ missing := append([]string{}, resolved.missing...)
120
+ if !queryProjectInputDirectoryCaseSensitivity(resolved.physical) {
121
+ for index := range missing {
122
+ missing[index] = strings.ToLower(missing[index])
123
+ }
124
+ }
125
+ segments = append(segments, missing...)
126
+ }
127
+ prefix := filepath.ToSlash(volume)
128
+ if len(segments) == 0 {
129
+ return prefix + "/"
130
+ }
131
+ return prefix + "/" + strings.Join(segments, "/")
132
+ }
133
+
134
+ func windowsProjectInputSegments(
135
+ resolved windowsProjectInputPath,
136
+ ) ([]string, []bool) {
137
+ volume := filepath.VolumeName(resolved.physical)
138
+ existing := splitWindowsProjectInputSegments(
139
+ strings.TrimPrefix(resolved.physical, volume),
140
+ )
141
+ segments := append(append([]string{}, existing...), resolved.missing...)
142
+ sensitivities := make([]bool, 0, len(segments))
143
+ current := windowsProjectInputVolumeRoot(volume)
144
+ for _, segment := range existing {
145
+ sensitivities = append(
146
+ sensitivities,
147
+ queryProjectInputDirectoryCaseSensitivity(current),
148
+ )
149
+ current = filepath.Join(current, segment)
150
+ }
151
+ if len(resolved.missing) != 0 {
152
+ missingSensitivity := queryProjectInputDirectoryCaseSensitivity(
153
+ resolved.physical,
154
+ )
155
+ for range resolved.missing {
156
+ sensitivities = append(sensitivities, missingSensitivity)
157
+ }
158
+ }
159
+ return segments, sensitivities
160
+ }
161
+
162
+ func windowsProjectInputKey(location string, segments []string) string {
163
+ volume := filepath.VolumeName(location)
164
+ prefix := strings.ToLower(filepath.ToSlash(volume))
165
+ if len(segments) == 0 {
166
+ return prefix + "/"
167
+ }
168
+ return prefix + "/" + strings.Join(segments, "/")
169
+ }
170
+
171
+ func windowsProjectInputVolumeRoot(volume string) string {
172
+ if strings.HasSuffix(volume, `\`) || strings.HasSuffix(volume, "/") {
173
+ return volume
174
+ }
175
+ return volume + `\`
176
+ }
177
+
178
+ func splitWindowsProjectInputSegments(location string) []string {
179
+ return strings.FieldsFunc(location, func(character rune) bool {
180
+ return character == '/' || character == '\\'
181
+ })
182
+ }
183
+
184
+ func reverseWindowsProjectInputSegments(segments []string) []string {
185
+ reversed := make([]string, len(segments))
186
+ for index := range segments {
187
+ reversed[len(segments)-index-1] = segments[index]
188
+ }
189
+ return reversed
190
+ }
191
+
192
+ func queryProjectInputDirectoryCaseSensitivity(directory string) bool {
193
+ sensitive, _ := tryQueryProjectInputDirectoryCaseSensitivity(directory)
194
+ return sensitive
195
+ }
196
+
197
+ func tryQueryProjectInputDirectoryCaseSensitivity(
198
+ directory string,
199
+ ) (bool, bool) {
200
+ pointer, err := windows.UTF16PtrFromString(directory)
201
+ if err != nil {
202
+ return false, false
203
+ }
204
+ handle, err := windows.CreateFile(
205
+ pointer,
206
+ windows.FILE_READ_ATTRIBUTES,
207
+ windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE|windows.FILE_SHARE_DELETE,
208
+ nil,
209
+ windows.OPEN_EXISTING,
210
+ windows.FILE_FLAG_BACKUP_SEMANTICS,
211
+ 0,
212
+ )
213
+ if err != nil {
214
+ return false, false
215
+ }
216
+ defer windows.CloseHandle(handle)
217
+
218
+ var flags uint32
219
+ if err := windows.GetFileInformationByHandleEx(
220
+ handle,
221
+ windows.FileCaseSensitiveInfo,
222
+ (*byte)(unsafe.Pointer(&flags)),
223
+ uint32(unsafe.Sizeof(flags)),
224
+ ); err != nil {
225
+ return false, false
226
+ }
227
+ return flags&windows.FILE_CS_FLAG_CASE_SENSITIVE_DIR != 0, true
228
+ }