ttsc 0.19.2 → 0.20.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 (178) hide show
  1. package/README.md +7 -5
  2. package/cmd/graphdump/main.go +2 -4
  3. package/cmd/ttsc/filter.go +12 -4
  4. package/cmd/ttsc/filter_resolves_flag_names_case_insensitively_test.go +53 -0
  5. package/cmd/ttsc/flags_gen.go +3 -3
  6. package/cmd/ttscgraph/dump.go +5 -7
  7. package/cmd/ttscgraph/run_dump_emits_only_checker_verified_member_relations_test.go +118 -0
  8. package/cmd/ttscgraph/serve.go +58 -308
  9. package/cmd/ttscgraph/serve_session_keeps_base_url_fallback_unchanged_test.go +49 -0
  10. package/cmd/ttscgraph/serve_session_keeps_esm_directory_candidate_unchanged_test.go +61 -0
  11. package/cmd/ttscgraph/serve_session_keeps_exports_blocked_file_candidates_unchanged_test.go +64 -0
  12. package/cmd/ttscgraph/serve_session_keeps_inactive_conditional_export_unchanged_test.go +66 -0
  13. package/cmd/ttscgraph/serve_session_keeps_lower_priority_module_candidate_unchanged_test.go +67 -0
  14. package/cmd/ttscgraph/serve_session_keeps_lower_priority_paths_pattern_unchanged_test.go +58 -0
  15. package/cmd/ttscgraph/serve_session_keeps_nonlongest_root_dirs_candidate_unchanged_test.go +54 -0
  16. package/cmd/ttscgraph/serve_session_reloads_commonjs_package_entry_for_esm_test.go +50 -0
  17. package/cmd/ttscgraph/serve_session_reloads_module_suffix_candidate_test.go +41 -0
  18. package/cmd/ttscgraph/serve_session_reloads_superseding_module_candidates_test.go +216 -0
  19. package/cmd/ttscgraph/serve_session_retries_failed_dump_test.go +103 -0
  20. package/driver/graph.go +12 -6
  21. package/driver/lsp.go +30 -0
  22. package/driver/program.go +37 -1
  23. package/driver/resolution_candidates.go +819 -0
  24. package/driver/windowsjunction/windowsjunction.go +40 -0
  25. package/go.mod +2 -0
  26. package/internal/graph/build.go +45 -11
  27. package/internal/graph/dump.go +312 -108
  28. package/internal/graph/dump_checkout_paths_are_stable_test.go +210 -0
  29. package/internal/graph/dump_diagnostics_ride_the_generation_that_built_it_test.go +9 -3
  30. package/internal/graph/dump_paths.go +172 -0
  31. package/internal/graph/dump_paths_are_portable_and_injective_test.go +93 -0
  32. package/internal/graph/dump_schema_version_matches_the_typescript_client_test.go +1 -1
  33. package/internal/graph/dump_uses_ecma_line_terminators_test.go +87 -0
  34. package/internal/graph/duplicate_variable_object_members_keep_first_declaration_test.go +61 -0
  35. package/internal/graph/edges.go +220 -5
  36. package/internal/graph/enum_members_carry_their_names_on_the_enum_node_test.go +131 -0
  37. package/internal/graph/graph.go +177 -5
  38. package/internal/graph/line_model.go +122 -0
  39. package/internal/graph/literals.go +175 -0
  40. package/internal/graph/literals_are_absent_when_the_type_admits_more_than_it_can_name_test.go +74 -0
  41. package/internal/graph/literals_cover_enum_members_the_graph_has_no_nodes_for_test.go +79 -0
  42. package/internal/graph/literals_do_not_depend_on_declaration_line_wrapping_test.go +84 -0
  43. package/internal/graph/literals_render_every_value_in_typescript_source_form_test.go +77 -0
  44. package/internal/graph/literals_resolve_through_alias_indirection_test.go +64 -0
  45. package/internal/graph/member_relation_edges_follow_checker_validity_test.go +85 -0
  46. package/internal/graph/member_relation_edges_preserve_checker_boundaries_test.go +191 -0
  47. package/internal/graph/member_relation_edges_reject_checker_invalid_pairs_test.go +119 -0
  48. package/internal/graph/node_ids_preserve_hash_bearing_components_test.go +41 -0
  49. package/internal/graph/node_modifiers_emit_union_strings_test.go +4 -1
  50. package/internal/graph/object_literal_members_ride_on_the_snapshot_test.go +192 -0
  51. package/internal/graph/object_member_signatures_preserve_literal_whitespace_test.go +67 -0
  52. package/internal/graph/object_members.go +229 -0
  53. package/internal/graph/provenance.go +88 -30
  54. package/internal/graph/source_texts_cover_every_resident_program_source_test.go +73 -0
  55. package/internal/graphsymbols/position_helpers_follow_ecma_line_terminators_test.go +66 -0
  56. package/internal/graphsymbols/provider.go +26 -91
  57. package/internal/lspserver/lsp_clean_didopen_refreshes_compiler_state_test.go +144 -0
  58. package/internal/lspserver/lsp_completion.go +109 -0
  59. package/internal/lspserver/lsp_completion_gate_never_refuses_a_matching_line_test.go +50 -0
  60. package/internal/lspserver/lsp_completion_hints_longest_trigger_wins_test.go +149 -0
  61. package/internal/lspserver/lsp_completion_hints_nearest_trigger_wins_test.go +37 -0
  62. package/internal/lspserver/lsp_completion_merges_into_upstream_response_test.go +149 -0
  63. package/internal/lspserver/lsp_completion_nearest_hint_replaces_nearest_filter_test.go +43 -0
  64. package/internal/lspserver/lsp_completion_preserves_completion_list_extensions_test.go +99 -0
  65. package/internal/lspserver/lsp_completion_refuses_hints_inside_a_string_literal_test.go +69 -0
  66. package/internal/lspserver/lsp_completion_replaces_full_filter_in_rank_order_test.go +85 -0
  67. package/internal/lspserver/lsp_completion_request.go +455 -0
  68. package/internal/lspserver/lsp_completion_scope.go +530 -0
  69. package/internal/lspserver/lsp_completion_scope_bench_test.go +41 -0
  70. package/internal/lspserver/lsp_completion_scope_classifies_regex_statement_and_operator_boundaries_test.go +39 -0
  71. package/internal/lspserver/lsp_completion_scope_ignores_jsdoc_bytes_in_literals_test.go +108 -0
  72. package/internal/lspserver/lsp_completion_scope_refuses_regex_hints_test.go +52 -0
  73. package/internal/lspserver/lsp_completion_trigger_uses_last_rune_test.go +24 -0
  74. package/internal/lspserver/lsp_deleted_watched_file_withdraws_plugin_diagnostics_test.go +110 -0
  75. package/internal/lspserver/lsp_didsave_keeps_the_incremental_changed_uri_path_test.go +78 -0
  76. package/internal/lspserver/lsp_hints_absence_is_not_an_error_test.go +46 -0
  77. package/internal/lspserver/lsp_hints_refresh_coalesces_concurrent_requests_test.go +82 -0
  78. package/internal/lspserver/lsp_hints_refresh_ignores_a_superseded_generation_test.go +40 -0
  79. package/internal/lspserver/lsp_hints_refresh_keeps_each_producer_isolated_test.go +64 -0
  80. package/internal/lspserver/lsp_hints_refresh_replaces_the_session_snapshot_test.go +66 -0
  81. package/internal/lspserver/lsp_hints_refresh_scheduled_by_editor_events_test.go +90 -0
  82. package/internal/lspserver/lsp_hints_refresh_serves_completion_while_running_test.go +91 -0
  83. package/internal/lspserver/lsp_index_byte_from_bounds_its_search_start_test.go +38 -0
  84. package/internal/lspserver/lsp_initialize_constrains_position_encoding_to_utf16_test.go +205 -0
  85. package/internal/lspserver/lsp_late_completion_trigger_is_reported_once_test.go +105 -0
  86. package/internal/lspserver/lsp_native_completion_hints_decode_flat_lint_wire_test.go +66 -0
  87. package/internal/lspserver/lsp_native_completion_hints_grouped_compatibility_boundary_test.go +60 -0
  88. package/internal/lspserver/lsp_native_plugin_source.go +315 -2
  89. package/internal/lspserver/lsp_native_resident.go +304 -0
  90. package/internal/lspserver/lsp_plugin.go +85 -8
  91. package/internal/lspserver/lsp_plugin_completion_resolve_stays_local_test.go +82 -0
  92. package/internal/lspserver/lsp_position_conversions_span_astral_and_combining_runes_test.go +119 -0
  93. package/internal/lspserver/lsp_proxy.go +601 -9
  94. package/internal/lspserver/lsp_refresh.go +70 -0
  95. package/internal/lspserver/lsp_resident_falls_back_when_serve_unsupported_test.go +43 -0
  96. package/internal/lspserver/lsp_resident_maps_verb_args_test.go +34 -0
  97. package/internal/lspserver/lsp_server.go +13 -1
  98. package/internal/lspserver/lsp_watched_file_changes_reach_compiler_caches_test.go +172 -0
  99. package/lib/TtscCompiler.d.ts +3 -1
  100. package/lib/TtscCompiler.js +5 -1
  101. package/lib/TtscCompiler.js.map +1 -1
  102. package/lib/TtscService.d.ts +13 -3
  103. package/lib/TtscService.js +6 -6
  104. package/lib/TtscService.js.map +1 -1
  105. package/lib/compiler/internal/project/readConfigJson.d.ts +30 -0
  106. package/lib/compiler/internal/project/readConfigJson.js +208 -0
  107. package/lib/compiler/internal/project/readConfigJson.js.map +1 -0
  108. package/lib/compiler/internal/project/readProjectConfig.js +53 -149
  109. package/lib/compiler/internal/project/readProjectConfig.js.map +1 -1
  110. package/lib/compiler/internal/residentTransformProcess.d.ts +15 -2
  111. package/lib/compiler/internal/residentTransformProcess.js +159 -39
  112. package/lib/compiler/internal/residentTransformProcess.js.map +1 -1
  113. package/lib/compiler/internal/runBuild.d.ts +6 -0
  114. package/lib/compiler/internal/runBuild.js +143 -44
  115. package/lib/compiler/internal/runBuild.js.map +1 -1
  116. package/lib/compiler/internal/startResidentTransform.d.ts +5 -1
  117. package/lib/compiler/internal/startResidentTransform.js +3 -1
  118. package/lib/compiler/internal/startResidentTransform.js.map +1 -1
  119. package/lib/compiler/internal/transformProjectInMemory.js +12 -2
  120. package/lib/compiler/internal/transformProjectInMemory.js.map +1 -1
  121. package/lib/flags/parser.d.ts +19 -0
  122. package/lib/flags/parser.js +78 -36
  123. package/lib/flags/parser.js.map +1 -1
  124. package/lib/flags/schema.d.ts +49 -11
  125. package/lib/flags/schema.js +94 -22
  126. package/lib/flags/schema.js.map +1 -1
  127. package/lib/internal/assertSafeExplicitCacheDirectory.d.ts +5 -0
  128. package/lib/internal/assertSafeExplicitCacheDirectory.js +26 -0
  129. package/lib/internal/assertSafeExplicitCacheDirectory.js.map +1 -0
  130. package/lib/launcher/internal/runTtsc.js +107 -69
  131. package/lib/launcher/internal/runTtsc.js.map +1 -1
  132. package/lib/launcher/internal/runTtsx.js +28 -41
  133. package/lib/launcher/internal/runTtsx.js.map +1 -1
  134. package/lib/launcher/internal/runtimeHooks.d.ts +15 -0
  135. package/lib/launcher/internal/runtimeHooks.js +18 -1
  136. package/lib/launcher/internal/runtimeHooks.js.map +1 -1
  137. package/lib/launcher/internal/watchTopology.d.ts +43 -0
  138. package/lib/launcher/internal/watchTopology.js +360 -0
  139. package/lib/launcher/internal/watchTopology.js.map +1 -0
  140. package/lib/plugin/internal/buildSourcePlugin.d.ts +14 -3
  141. package/lib/plugin/internal/buildSourcePlugin.js +247 -61
  142. package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
  143. package/lib/plugin/internal/loadProjectPlugins.js +63 -2
  144. package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
  145. package/lib/structures/ITtscCompilerTransformation.d.ts +16 -0
  146. package/lib/structures/internal/ITtscParsedProjectConfig.d.ts +2 -0
  147. package/package.json +8 -8
  148. package/shim/ast/shim.go +48 -3
  149. package/shim/astnav/go.mod +14 -0
  150. package/shim/astnav/go.sum +20 -0
  151. package/shim/astnav/shim.go +15 -0
  152. package/shim/checker/shim.go +113 -0
  153. package/shim/core/shim.go +47 -0
  154. package/shim/diagnosticwriter/lint.go +50 -0
  155. package/src/TtscCompiler.ts +5 -1
  156. package/src/TtscService.ts +37 -10
  157. package/src/compiler/internal/project/readConfigJson.ts +209 -0
  158. package/src/compiler/internal/project/readProjectConfig.ts +62 -158
  159. package/src/compiler/internal/residentTransformProcess.ts +197 -39
  160. package/src/compiler/internal/runBuild.ts +169 -47
  161. package/src/compiler/internal/startResidentTransform.ts +12 -1
  162. package/src/compiler/internal/transformProjectInMemory.ts +12 -1
  163. package/src/flags/parser.ts +113 -42
  164. package/src/flags/schema.ts +113 -31
  165. package/src/internal/assertSafeExplicitCacheDirectory.ts +29 -0
  166. package/src/launcher/internal/runTtsc.ts +117 -68
  167. package/src/launcher/internal/runTtsx.ts +29 -44
  168. package/src/launcher/internal/runtimeHooks.ts +30 -2
  169. package/src/launcher/internal/watchTopology.ts +466 -0
  170. package/src/plugin/internal/buildSourcePlugin.ts +326 -64
  171. package/src/plugin/internal/loadProjectPlugins.ts +80 -2
  172. package/src/structures/ITtscCompilerTransformation.ts +17 -0
  173. package/src/structures/internal/ITtscParsedProjectConfig.ts +2 -0
  174. package/tools/shim_audit/baseline.json +0 -3
  175. package/tools/shim_audit/main.go +42 -14
  176. package/tools/shim_audit/shim_dir_coverage_test.go +25 -0
  177. package/utility/flags_gen.go +3 -3
  178. package/utility/host.go +9 -3
package/driver/graph.go CHANGED
@@ -30,14 +30,19 @@ const bundledScheme = "bundled:///"
30
30
  // declaration files, script files, global augmentations, `typeRoots`
31
31
  // entries). A change to any of them can affect every file.
32
32
  // - Configs lists the project tsconfig followed by its `extends` ancestry.
33
+ // - Candidates maps each importing file to the resolution probes that precede
34
+ // its selected module target. They are a separate class from resolved
35
+ // edges: a probe's file appearing or changing can change an unchanged
36
+ // import's meaning.
33
37
  //
34
38
  // Keys and values use the same convention as the envelope's `typescript`
35
39
  // map: project-relative slash paths, falling back to slash-normalized
36
40
  // absolute paths outside the project root (see TransformOutputKey).
37
41
  type TransformGraph struct {
38
- Edges map[string][]string `json:"edges"`
39
- Globals []string `json:"globals"`
40
- Configs []string `json:"configs"`
42
+ Edges map[string][]string `json:"edges"`
43
+ Globals []string `json:"globals"`
44
+ Configs []string `json:"configs"`
45
+ Candidates map[string][]string `json:"candidates,omitempty"`
41
46
  }
42
47
 
43
48
  // NewTransformGraph computes the reference graph of a loaded program, keyed
@@ -50,9 +55,10 @@ func NewTransformGraph(prog *Program, cwd string) *TransformGraph {
50
55
  return nil
51
56
  }
52
57
  graph := &TransformGraph{
53
- Edges: map[string][]string{},
54
- Globals: []string{},
55
- Configs: []string{},
58
+ Edges: map[string][]string{},
59
+ Globals: []string{},
60
+ Configs: []string{},
61
+ Candidates: SupersedingModuleCandidates(prog, cwd),
56
62
  }
57
63
  for _, file := range prog.TSProgram.SourceFiles() {
58
64
  fileName := file.FileName()
package/driver/lsp.go CHANGED
@@ -55,6 +55,12 @@ type LSPProjectDiagnostics = lspserver.LSPProjectDiagnostics
55
55
  // LSPDiagnosticsResult separates document and project plugin diagnostics.
56
56
  type LSPDiagnosticsResult = lspserver.LSPDiagnosticsResult
57
57
 
58
+ // LSPCompletionHint is the driver-level alias for lspserver.LSPCompletionHint.
59
+ type LSPCompletionHint = lspserver.LSPCompletionHint
60
+
61
+ // LSPCompletionItem is the driver-level alias for lspserver.LSPCompletionItem.
62
+ type LSPCompletionItem = lspserver.LSPCompletionItem
63
+
58
64
  // LSPSymbolKind is the driver-level alias for lspserver.LSPSymbolKind.
59
65
  type LSPSymbolKind = lspserver.LSPSymbolKind
60
66
 
@@ -74,6 +80,30 @@ type SymbolProvider = lspserver.SymbolProvider
74
80
  // diagnostics, code actions, and workspace commands to the LSP proxy.
75
81
  type PluginSource = lspserver.PluginSource
76
82
 
83
+ // CompletionHintSource is the optional extension a PluginSource implements to
84
+ // contribute editor completion hints to the LSP proxy.
85
+ type CompletionHintSource interface {
86
+ CompletionHints() []LSPCompletionHint
87
+ }
88
+
89
+ // CompletionHintRefresher is the optional extension a CompletionHintSource
90
+ // implements when its corpus can change during a session. The proxy calls it
91
+ // after a saved document, a configuration change, or a watched-file change, and
92
+ // expects the call to return immediately: the source owns the scheduling and the
93
+ // staleness rules, and completion keeps reading the previous corpus until the
94
+ // new one is stored.
95
+ type CompletionHintRefresher interface {
96
+ RefreshCompletionHints()
97
+ }
98
+
99
+ // CompletionHintObserverSource is the optional extension a CompletionHintSource
100
+ // implements to tell the proxy that a refresh finished. The proxy uses it to
101
+ // detect a completion trigger character that appeared after the initialize
102
+ // response was already sent.
103
+ type CompletionHintObserverSource interface {
104
+ SetCompletionHintsObserver(observer func())
105
+ }
106
+
77
107
  // NullPluginSource is the driver-level alias for lspserver.NullPluginSource.
78
108
  type NullPluginSource = lspserver.NullPluginSource
79
109
 
package/driver/program.go CHANGED
@@ -101,6 +101,9 @@ func (p *Program) SourceFile(filename string) *ast.SourceFile {
101
101
  if p == nil || p.TSProgram == nil {
102
102
  return nil
103
103
  }
104
+ // Discarded on purpose: an accessor returning a source file has no channel
105
+ // for an apply failure, and growing one would ripple through every caller.
106
+ // `Diagnostics` reports it, and the emit path checks the error directly.
104
107
  _ = p.ApplyLinkedPlugins()
105
108
  normalized := filepath.ToSlash(filename)
106
109
  for _, file := range p.TSProgram.SourceFiles() {
@@ -513,6 +516,7 @@ func ApplySourcePreamble(text string, preamble string) string {
513
516
  // SourceFiles exposes the program's user-authored source files (declaration
514
517
  // files filtered out).
515
518
  func (p *Program) SourceFiles() []*ast.SourceFile {
519
+ // Discarded on purpose; see SourceFile. `Diagnostics` carries the failure.
516
520
  _ = p.ApplyLinkedPlugins()
517
521
  return p.sourceFilesRaw()
518
522
  }
@@ -563,6 +567,38 @@ func (p *Program) Diagnostics() []Diagnostic {
563
567
  if p == nil || p.TSProgram == nil {
564
568
  return []Diagnostic{{Message: "driver: nil program"}}
565
569
  }
570
+ // A linked ProgramPlugin that failed to apply is reported here, ahead of the
571
+ // compiler's own findings, because every other consumer of this program is
572
+ // then looking at a tree the plugin did not transform.
573
+ //
574
+ // `SourceFile`, `SourceFiles`, and the graph builder all run the apply and
575
+ // discard its error — they have no channel of their own and are not the place
576
+ // to grow one. The emit path checks it directly and fails the build, so this
577
+ // is the read-only half of the same fact: `ttscgraph` used to describe the
578
+ // untransformed program with nothing to say about it, while `ttsc build` on
579
+ // the same project reported the failure.
580
+ //
581
+ // The cached outcome is read, never forced. Calling `ApplyLinkedPlugins`
582
+ // here would move WHEN the apply happens: diagnostics would then be computed
583
+ // against the mutated tree, whose nodes carry positions that need not map
584
+ // into the original source text, and the diagnostic writer walks that text to
585
+ // render context. It panics on the mismatch.
586
+ //
587
+ // Reading the cache costs nothing and is enough for the consumers this is
588
+ // for: `SourceTexts` and `SourceFiles` run the apply, and both graph entry
589
+ // points call them before asking for diagnostics. A caller that has not
590
+ // applied yet has nothing to report, which is correct — the plugins have not
591
+ // failed, they have not run.
592
+ //
593
+ // `driver: nil program` above is the precedent for a driver-level entry with
594
+ // no file or code.
595
+ var out []Diagnostic
596
+ if p.pluginsApplied && p.pluginsApplyErr != nil {
597
+ out = append(out, Diagnostic{
598
+ Severity: SeverityError,
599
+ Message: "driver: linked plugins failed to apply: " + p.pluginsApplyErr.Error(),
600
+ })
601
+ }
566
602
  ctx := context.Background()
567
603
  raw := shimcompiler.GetDiagnosticsOfAnyProgram(
568
604
  ctx,
@@ -573,7 +609,7 @@ func (p *Program) Diagnostics() []Diagnostic {
573
609
  p.TSProgram.GetSemanticDiagnostics,
574
610
  )
575
611
  raw = filterDiagnostics(raw)
576
- return convertDiagnostics(shimcompiler.SortAndDeduplicateDiagnostics(raw))
612
+ return append(out, convertDiagnostics(shimcompiler.SortAndDeduplicateDiagnostics(raw))...)
577
613
  }
578
614
 
579
615
  // filterDiagnostics removes diagnostics that are false positives in ttsc's