@flyingrobots/graft 0.7.0 → 0.7.1

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 (283) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +0 -1
  3. package/bin/graft.js +26 -26
  4. package/dist/cli/init-client-config.d.ts.map +1 -1
  5. package/dist/cli/init-client-config.js +40 -4
  6. package/dist/cli/init-client-config.js.map +1 -1
  7. package/dist/cli/init-model.js +2 -2
  8. package/dist/cli/init-model.js.map +1 -1
  9. package/dist/cli/json-document.d.ts +1 -0
  10. package/dist/cli/json-document.d.ts.map +1 -1
  11. package/dist/cli/json-document.js +3 -0
  12. package/dist/cli/json-document.js.map +1 -1
  13. package/dist/hooks/posttooluse-read.js +1 -1
  14. package/dist/hooks/posttooluse-read.js.map +1 -1
  15. package/dist/hooks/pretooluse-read.js +1 -1
  16. package/dist/hooks/pretooluse-read.js.map +1 -1
  17. package/dist/mcp/daemon-worker-child-pool.d.ts +2 -0
  18. package/dist/mcp/daemon-worker-child-pool.d.ts.map +1 -1
  19. package/dist/mcp/daemon-worker-child-pool.js +10 -3
  20. package/dist/mcp/daemon-worker-child-pool.js.map +1 -1
  21. package/dist/mcp/daemon-worker-pool.d.ts +1 -1
  22. package/dist/mcp/daemon-worker-pool.d.ts.map +1 -1
  23. package/dist/mcp/daemon-worker-pool.js +1 -1
  24. package/dist/mcp/daemon-worker-pool.js.map +1 -1
  25. package/dist/version.d.ts.map +1 -1
  26. package/dist/version.js +3 -1
  27. package/dist/version.js.map +1 -1
  28. package/docs/SETUP.md +11 -7
  29. package/package.json +9 -4
  30. package/src/adapters/canonical-json.ts +0 -56
  31. package/src/adapters/json-text-decoder.ts +0 -11
  32. package/src/adapters/node-fs.ts +0 -43
  33. package/src/adapters/node-git.ts +0 -47
  34. package/src/adapters/node-paths.ts +0 -35
  35. package/src/adapters/node-process-runner.ts +0 -27
  36. package/src/adapters/repo-paths.ts +0 -63
  37. package/src/adapters/rotating-ndjson-log.ts +0 -66
  38. package/src/api/index.ts +0 -107
  39. package/src/api/repo-local-graft.ts +0 -21
  40. package/src/api/repo-workspace.ts +0 -34
  41. package/src/api/tool-bridge.ts +0 -22
  42. package/src/cli/activity-render.ts +0 -112
  43. package/src/cli/cli-error.ts +0 -192
  44. package/src/cli/command-parser.ts +0 -484
  45. package/src/cli/daemon-status-model.ts +0 -238
  46. package/src/cli/daemon-status-render.ts +0 -102
  47. package/src/cli/daemon-status.ts +0 -100
  48. package/src/cli/entrypoint.ts +0 -18
  49. package/src/cli/git-graft-enhance-model.ts +0 -131
  50. package/src/cli/git-graft-enhance-render.ts +0 -33
  51. package/src/cli/git-graft-enhance.ts +0 -54
  52. package/src/cli/index-cmd.ts +0 -90
  53. package/src/cli/index-model.ts +0 -75
  54. package/src/cli/init-bootstrap.ts +0 -47
  55. package/src/cli/init-client-config.ts +0 -428
  56. package/src/cli/init-model.ts +0 -284
  57. package/src/cli/init-render.ts +0 -54
  58. package/src/cli/init-target-hooks.ts +0 -93
  59. package/src/cli/init.ts +0 -124
  60. package/src/cli/json-document.ts +0 -155
  61. package/src/cli/local-history-dag-model.ts +0 -437
  62. package/src/cli/local-history-dag-render.ts +0 -133
  63. package/src/cli/local-history-dag.ts +0 -103
  64. package/src/cli/main.ts +0 -197
  65. package/src/cli/migrate-local-history.ts +0 -119
  66. package/src/cli/peer-command.ts +0 -60
  67. package/src/contracts/capabilities.ts +0 -540
  68. package/src/contracts/causal-ontology.ts +0 -627
  69. package/src/contracts/causal-surface-next-action.ts +0 -18
  70. package/src/contracts/json-object.ts +0 -18
  71. package/src/contracts/mcp-runtime.ts +0 -16
  72. package/src/contracts/output-schema-cli.ts +0 -103
  73. package/src/contracts/output-schema-fragments.ts +0 -881
  74. package/src/contracts/output-schema-mcp.ts +0 -501
  75. package/src/contracts/output-schema-meta.ts +0 -119
  76. package/src/contracts/output-schemas.ts +0 -1524
  77. package/src/git/diff.ts +0 -161
  78. package/src/git/target-git-hook-bootstrap.ts +0 -56
  79. package/src/guards/stream-boundary.ts +0 -110
  80. package/src/hooks/posttooluse-read.ts +0 -54
  81. package/src/hooks/pretooluse-read.ts +0 -52
  82. package/src/hooks/read-governor.ts +0 -95
  83. package/src/hooks/read-messages.ts +0 -53
  84. package/src/hooks/shared.ts +0 -168
  85. package/src/index.ts +0 -1
  86. package/src/mcp/burden.ts +0 -132
  87. package/src/mcp/cache.ts +0 -7
  88. package/src/mcp/cached-file.ts +0 -1
  89. package/src/mcp/context.ts +0 -150
  90. package/src/mcp/control-plane/authz-storage.ts +0 -129
  91. package/src/mcp/control-plane/session-registry.ts +0 -115
  92. package/src/mcp/control-plane/status-projection.ts +0 -76
  93. package/src/mcp/control-plane/types.ts +0 -144
  94. package/src/mcp/daemon-bootstrap.ts +0 -100
  95. package/src/mcp/daemon-control-plane.ts +0 -310
  96. package/src/mcp/daemon-job-scheduler.ts +0 -279
  97. package/src/mcp/daemon-repos.ts +0 -99
  98. package/src/mcp/daemon-server.ts +0 -172
  99. package/src/mcp/daemon-session-host.ts +0 -234
  100. package/src/mcp/daemon-stdio-bridge.ts +0 -262
  101. package/src/mcp/daemon-worker-child-pool.ts +0 -213
  102. package/src/mcp/daemon-worker-inline-pool.ts +0 -46
  103. package/src/mcp/daemon-worker-pool.ts +0 -7
  104. package/src/mcp/daemon-worker-process.ts +0 -52
  105. package/src/mcp/daemon-worker-types.ts +0 -66
  106. package/src/mcp/metrics.ts +0 -176
  107. package/src/mcp/monitor-health.ts +0 -83
  108. package/src/mcp/monitor-persistence.ts +0 -54
  109. package/src/mcp/monitor-tick-job.ts +0 -153
  110. package/src/mcp/monitor-types.ts +0 -103
  111. package/src/mcp/persisted-local-history-graph.ts +0 -592
  112. package/src/mcp/persisted-local-history-policy.ts +0 -501
  113. package/src/mcp/persisted-local-history-views.ts +0 -250
  114. package/src/mcp/persisted-local-history.ts +0 -1621
  115. package/src/mcp/persistent-monitor-runtime.ts +0 -482
  116. package/src/mcp/policy.ts +0 -75
  117. package/src/mcp/receipt.ts +0 -201
  118. package/src/mcp/repo-concurrency.ts +0 -392
  119. package/src/mcp/repo-overview/filter.ts +0 -44
  120. package/src/mcp/repo-overview/types.ts +0 -63
  121. package/src/mcp/repo-overview/view-projection.ts +0 -90
  122. package/src/mcp/repo-state-git.ts +0 -247
  123. package/src/mcp/repo-state-observation.ts +0 -203
  124. package/src/mcp/repo-state-transition.ts +0 -151
  125. package/src/mcp/repo-state-types.ts +0 -107
  126. package/src/mcp/repo-state.ts +0 -146
  127. package/src/mcp/repo-tool-job.ts +0 -102
  128. package/src/mcp/repo-tool-worker-context.ts +0 -215
  129. package/src/mcp/repo-workspace.ts +0 -21
  130. package/src/mcp/run-capture-config.ts +0 -33
  131. package/src/mcp/runtime-causal-context.ts +0 -72
  132. package/src/mcp/runtime-observability.ts +0 -217
  133. package/src/mcp/runtime-staged-target.ts +0 -161
  134. package/src/mcp/runtime-workspace-overlay.ts +0 -255
  135. package/src/mcp/secret-scrub.ts +0 -89
  136. package/src/mcp/semantic-transition-guidance.ts +0 -60
  137. package/src/mcp/semantic-transition-summary.ts +0 -130
  138. package/src/mcp/server-context.ts +0 -236
  139. package/src/mcp/server-invocation.ts +0 -388
  140. package/src/mcp/server-tool-access.ts +0 -148
  141. package/src/mcp/server.ts +0 -270
  142. package/src/mcp/stdio-server.ts +0 -26
  143. package/src/mcp/stdio.ts +0 -3
  144. package/src/mcp/tool-registry.ts +0 -98
  145. package/src/mcp/tools/activity-view.ts +0 -325
  146. package/src/mcp/tools/budget.ts +0 -23
  147. package/src/mcp/tools/causal-attach.ts +0 -67
  148. package/src/mcp/tools/causal-status.ts +0 -58
  149. package/src/mcp/tools/changed-since.ts +0 -71
  150. package/src/mcp/tools/code-find.ts +0 -192
  151. package/src/mcp/tools/code-refs.ts +0 -470
  152. package/src/mcp/tools/code-show.ts +0 -289
  153. package/src/mcp/tools/daemon-monitors.ts +0 -14
  154. package/src/mcp/tools/daemon-repos.ts +0 -22
  155. package/src/mcp/tools/daemon-sessions.ts +0 -14
  156. package/src/mcp/tools/daemon-status.ts +0 -12
  157. package/src/mcp/tools/diagnostic-models.ts +0 -97
  158. package/src/mcp/tools/doctor.ts +0 -83
  159. package/src/mcp/tools/explain.ts +0 -84
  160. package/src/mcp/tools/export-surface-diff.ts +0 -26
  161. package/src/mcp/tools/file-outline.ts +0 -67
  162. package/src/mcp/tools/git-files.ts +0 -73
  163. package/src/mcp/tools/graft-diff.ts +0 -35
  164. package/src/mcp/tools/graft-edit.ts +0 -276
  165. package/src/mcp/tools/knowledge-map.ts +0 -34
  166. package/src/mcp/tools/map-collector.ts +0 -338
  167. package/src/mcp/tools/map.ts +0 -185
  168. package/src/mcp/tools/monitor-nudge.ts +0 -19
  169. package/src/mcp/tools/monitor-pause.ts +0 -18
  170. package/src/mcp/tools/monitor-resume.ts +0 -18
  171. package/src/mcp/tools/monitor-start.ts +0 -20
  172. package/src/mcp/tools/monitor-stop.ts +0 -18
  173. package/src/mcp/tools/precision-live.ts +0 -158
  174. package/src/mcp/tools/precision-match.ts +0 -54
  175. package/src/mcp/tools/precision-paths.ts +0 -59
  176. package/src/mcp/tools/precision-query.ts +0 -127
  177. package/src/mcp/tools/precision-show.ts +0 -86
  178. package/src/mcp/tools/precision-visibility.ts +0 -44
  179. package/src/mcp/tools/precision-warp.ts +0 -101
  180. package/src/mcp/tools/precision.ts +0 -21
  181. package/src/mcp/tools/read-range.ts +0 -28
  182. package/src/mcp/tools/refactor-difficulty.ts +0 -42
  183. package/src/mcp/tools/run-capture.ts +0 -149
  184. package/src/mcp/tools/safe-read.ts +0 -148
  185. package/src/mcp/tools/since.ts +0 -53
  186. package/src/mcp/tools/state.ts +0 -39
  187. package/src/mcp/tools/stats.ts +0 -24
  188. package/src/mcp/tools/structural-blame.ts +0 -55
  189. package/src/mcp/tools/structural-churn.ts +0 -28
  190. package/src/mcp/tools/structural-log.ts +0 -41
  191. package/src/mcp/tools/structural-review.ts +0 -63
  192. package/src/mcp/tools/workspace-authorizations.ts +0 -14
  193. package/src/mcp/tools/workspace-authorize.ts +0 -20
  194. package/src/mcp/tools/workspace-bind.ts +0 -25
  195. package/src/mcp/tools/workspace-rebind.ts +0 -25
  196. package/src/mcp/tools/workspace-revoke.ts +0 -18
  197. package/src/mcp/tools/workspace-status.ts +0 -12
  198. package/src/mcp/warp-pool.ts +0 -36
  199. package/src/mcp/workspace-read-observation-model.ts +0 -48
  200. package/src/mcp/workspace-read-observation.ts +0 -103
  201. package/src/mcp/workspace-router-capability.ts +0 -32
  202. package/src/mcp/workspace-router-history.ts +0 -233
  203. package/src/mcp/workspace-router-model.ts +0 -131
  204. package/src/mcp/workspace-router-resolution.ts +0 -71
  205. package/src/mcp/workspace-router-runtime.ts +0 -246
  206. package/src/mcp/workspace-router.ts +0 -688
  207. package/src/metrics/logger.ts +0 -40
  208. package/src/metrics/types.ts +0 -40
  209. package/src/operations/adaptive-projection.ts +0 -54
  210. package/src/operations/agent-handoff.ts +0 -59
  211. package/src/operations/cached-file.ts +0 -40
  212. package/src/operations/capture-range.ts +0 -64
  213. package/src/operations/conversation-primer.ts +0 -82
  214. package/src/operations/cross-session-resume.ts +0 -104
  215. package/src/operations/deterministic-replay.ts +0 -143
  216. package/src/operations/diff-identity.ts +0 -127
  217. package/src/operations/export-surface-diff.ts +0 -355
  218. package/src/operations/file-outline.ts +0 -48
  219. package/src/operations/footprint-parallelism.ts +0 -98
  220. package/src/operations/graft-diff.ts +0 -169
  221. package/src/operations/horizon-of-readability.ts +0 -60
  222. package/src/operations/import-reference-impact.ts +0 -143
  223. package/src/operations/knowledge-map.ts +0 -96
  224. package/src/operations/observation-cache.ts +0 -165
  225. package/src/operations/projection-safety.ts +0 -111
  226. package/src/operations/read-range.ts +0 -64
  227. package/src/operations/repo-workspace.ts +0 -339
  228. package/src/operations/result-dto.ts +0 -23
  229. package/src/operations/safe-read.ts +0 -118
  230. package/src/operations/semantic-drift.ts +0 -70
  231. package/src/operations/session-filtration.ts +0 -76
  232. package/src/operations/session-replay.ts +0 -73
  233. package/src/operations/sludge-detector.ts +0 -356
  234. package/src/operations/state.ts +0 -66
  235. package/src/operations/structural-blame.ts +0 -197
  236. package/src/operations/structural-review.ts +0 -317
  237. package/src/operations/structured-buffer-compare.ts +0 -429
  238. package/src/operations/structured-buffer-model.ts +0 -456
  239. package/src/operations/structured-buffer-query.ts +0 -794
  240. package/src/operations/structured-buffer.ts +0 -181
  241. package/src/operations/teaching-hints.ts +0 -52
  242. package/src/parser/diff.ts +0 -320
  243. package/src/parser/lang.ts +0 -71
  244. package/src/parser/markdown.ts +0 -197
  245. package/src/parser/outline.ts +0 -316
  246. package/src/parser/runtime.ts +0 -71
  247. package/src/parser/types.ts +0 -75
  248. package/src/policy/evaluate.ts +0 -178
  249. package/src/policy/graftignore.ts +0 -6
  250. package/src/policy/types.ts +0 -87
  251. package/src/ports/codec.ts +0 -13
  252. package/src/ports/filesystem.ts +0 -18
  253. package/src/ports/git.ts +0 -16
  254. package/src/ports/guards.ts +0 -68
  255. package/src/ports/paths.ts +0 -22
  256. package/src/ports/process-runner.ts +0 -22
  257. package/src/release/security-gate.ts +0 -102
  258. package/src/session/tracker.ts +0 -145
  259. package/src/session/types.ts +0 -23
  260. package/src/version.ts +0 -3
  261. package/src/warp/ast-emitter.ts +0 -133
  262. package/src/warp/ast-import-resolver.ts +0 -333
  263. package/src/warp/commit-meta.ts +0 -19
  264. package/src/warp/context.ts +0 -48
  265. package/src/warp/dead-symbols.ts +0 -174
  266. package/src/warp/drift-sentinel.ts +0 -101
  267. package/src/warp/index-head.ts +0 -348
  268. package/src/warp/observers.ts +0 -101
  269. package/src/warp/open.ts +0 -67
  270. package/src/warp/outline-diff-trailer.ts +0 -100
  271. package/src/warp/plumbing.d.ts +0 -24
  272. package/src/warp/refactor-difficulty.ts +0 -257
  273. package/src/warp/references.ts +0 -77
  274. package/src/warp/stale-docs.ts +0 -210
  275. package/src/warp/structural-drift-detection.ts +0 -97
  276. package/src/warp/structural-queries.ts +0 -258
  277. package/src/warp/symbol-timeline.ts +0 -209
  278. package/src/warp/traverse-hydrate.ts +0 -61
  279. package/src/warp/warp-reference-count.ts +0 -47
  280. package/src/warp/warp-structural-blame.ts +0 -65
  281. package/src/warp/warp-structural-churn.ts +0 -309
  282. package/src/warp/warp-structural-log.ts +0 -149
  283. package/src/warp/writer-id.ts +0 -30
@@ -1,794 +0,0 @@
1
- import type Parser from "web-tree-sitter";
2
- import { extractOutline } from "../parser/outline.js";
3
- import {
4
- type BufferDiagnostic,
5
- type BufferOutlineResult,
6
- type BufferPoint,
7
- type BufferRange,
8
- type BufferSelection,
9
- type DiagnosticsResult,
10
- type FoldRegion,
11
- type FoldRegionsResult,
12
- type InjectionRegion,
13
- type InjectionResult,
14
- type NodeLookupResult,
15
- type NodeSummary,
16
- type RenamePreviewResult,
17
- type SelectionStepResult,
18
- type StructuredBufferSnapshot,
19
- type SymbolOccurrence,
20
- type SymbolOccurrencesResult,
21
- type SyntaxClass,
22
- type SyntaxSpan,
23
- type SyntaxSpanResult,
24
- type WarmProjectionBundleResult,
25
- collectIdentifierNodes,
26
- comparePoints,
27
- findCoveringNamedNode,
28
- isIdentifierType,
29
- nearestNamedChild,
30
- nodeRange,
31
- normalizeSelection,
32
- point,
33
- rangeOverlaps,
34
- rangesEqual,
35
- summarizeNode,
36
- } from "./structured-buffer-model.js";
37
-
38
- const KEYWORDS = new Set([
39
- "as",
40
- "async",
41
- "await",
42
- "break",
43
- "case",
44
- "catch",
45
- "class",
46
- "const",
47
- "continue",
48
- "debugger",
49
- "default",
50
- "delete",
51
- "do",
52
- "else",
53
- "enum",
54
- "export",
55
- "extends",
56
- "false",
57
- "finally",
58
- "for",
59
- "from",
60
- "function",
61
- "if",
62
- "implements",
63
- "import",
64
- "in",
65
- "instanceof",
66
- "interface",
67
- "let",
68
- "new",
69
- "null",
70
- "private",
71
- "protected",
72
- "public",
73
- "readonly",
74
- "return",
75
- "static",
76
- "super",
77
- "switch",
78
- "this",
79
- "throw",
80
- "true",
81
- "try",
82
- "type",
83
- "typeof",
84
- "var",
85
- "void",
86
- "while",
87
- "yield",
88
- ]);
89
-
90
- const OPERATORS = new Set([
91
- "=",
92
- "=>",
93
- "+",
94
- "-",
95
- "*",
96
- "/",
97
- "%",
98
- "&&",
99
- "||",
100
- "??",
101
- "!",
102
- "!=",
103
- "!==",
104
- "==",
105
- "===",
106
- "<",
107
- "<=",
108
- ">",
109
- ">=",
110
- ".",
111
- "?.",
112
- ":",
113
- "|",
114
- "&",
115
- ]);
116
-
117
- const PUNCTUATION = new Set(["(", ")", "{", "}", "[", "]", ";", ","]);
118
-
119
- const FOLDABLE_NODE_TYPES = new Set([
120
- "class_declaration",
121
- "enum_declaration",
122
- "function_declaration",
123
- "generator_function_declaration",
124
- "interface_declaration",
125
- "method_definition",
126
- "object",
127
- "statement_block",
128
- "switch_body",
129
- "jsx_element",
130
- "jsx_fragment",
131
- ]);
132
-
133
- interface SymbolResolution {
134
- readonly symbol: string;
135
- readonly kind: "declaration" | "occurrence";
136
- readonly nodeType: string;
137
- }
138
-
139
- function isLeaf(node: Parser.SyntaxNode): boolean {
140
- return node.childCount === 0;
141
- }
142
-
143
- function roleForIdentifier(node: Parser.SyntaxNode): SyntaxClass {
144
- const parent = node.parent;
145
- if (parent === null) {
146
- return node.type === "type_identifier" ? "type" : "variable";
147
- }
148
- const nameField = parent.childForFieldName("name");
149
- if (nameField !== null && nameField.id === node.id) {
150
- if (
151
- parent.type === "class_declaration"
152
- || parent.type === "interface_declaration"
153
- || parent.type === "type_alias_declaration"
154
- || parent.type === "enum_declaration"
155
- ) {
156
- return "type";
157
- }
158
- if (
159
- parent.type === "function_declaration"
160
- || parent.type === "generator_function_declaration"
161
- || parent.type === "method_definition"
162
- || parent.type === "function"
163
- || parent.type === "arrow_function"
164
- ) {
165
- return "function";
166
- }
167
- }
168
- if (node.type === "property_identifier" || parent.type === "member_expression" || parent.type === "pair") {
169
- return "property";
170
- }
171
- if (node.type === "type_identifier" || parent.type.includes("type")) {
172
- return "type";
173
- }
174
- return "variable";
175
- }
176
-
177
- function classifyLeaf(node: Parser.SyntaxNode): SyntaxClass | null {
178
- if (node.type === "comment") {
179
- return "comment";
180
- }
181
- if (node.parent?.type.includes("type") === true) {
182
- if (node.type === "type_identifier" || /^[A-Z]/.test(node.text)) {
183
- return "type";
184
- }
185
- if (new Set(["string", "number", "boolean", "unknown", "never", "void", "any"]).has(node.text)) {
186
- return "type";
187
- }
188
- }
189
- if (node.type === "string" || node.type === "template_string" || node.type === "regex") {
190
- return "string";
191
- }
192
- if (
193
- node.type === "number"
194
- || node.type === "number_literal"
195
- || node.type === "integer"
196
- || node.type === "float"
197
- ) {
198
- return "number";
199
- }
200
- if (isIdentifierType(node.type)) {
201
- return roleForIdentifier(node);
202
- }
203
- if (!node.isNamed()) {
204
- if (KEYWORDS.has(node.type)) {
205
- return "keyword";
206
- }
207
- if (PUNCTUATION.has(node.type)) {
208
- return "punctuation";
209
- }
210
- if (OPERATORS.has(node.type)) {
211
- return "operator";
212
- }
213
- }
214
- return null;
215
- }
216
-
217
- function collectMissingNodes(node: Parser.SyntaxNode, output: Parser.SyntaxNode[]): void {
218
- if (node.isMissing()) {
219
- output.push(node);
220
- }
221
- for (const child of node.children) {
222
- collectMissingNodes(child, output);
223
- }
224
- }
225
-
226
- function symbolNodeAt(root: Parser.SyntaxNode, position: BufferPoint): Parser.SyntaxNode | null {
227
- let current = root.descendantForPosition(position);
228
- while (!isIdentifierType(current.type)) {
229
- if (current.parent === null) {
230
- return null;
231
- }
232
- current = current.parent;
233
- }
234
- return current;
235
- }
236
-
237
- function fencedCodeInjections(source: string): InjectionRegion[] {
238
- const lines = source.split("\n");
239
- const regions: InjectionRegion[] = [];
240
- let active:
241
- | {
242
- readonly marker: string;
243
- readonly startRow: number;
244
- readonly language: string;
245
- }
246
- | undefined;
247
- for (let index = 0; index < lines.length; index += 1) {
248
- const line = lines[index] ?? "";
249
- const open = /^\s*([`~]{3,})([A-Za-z0-9_-]+)?/.exec(line);
250
- if (active === undefined && open !== null) {
251
- active = {
252
- marker: open[1] ?? "```",
253
- startRow: index,
254
- language: open[2] ?? "code",
255
- };
256
- continue;
257
- }
258
- if (active !== undefined && new RegExp(`^\\s*${active.marker}\\s*$`).test(line)) {
259
- regions.push({
260
- language: active.language,
261
- range: {
262
- start: point(active.startRow, 0),
263
- end: point(index, line.length),
264
- },
265
- reason: "fenced_code_block",
266
- hint: active.language,
267
- });
268
- active = undefined;
269
- }
270
- }
271
- return regions;
272
- }
273
-
274
- function taggedTemplateInjections(source: string): InjectionRegion[] {
275
- const injections: InjectionRegion[] = [];
276
- const pattern = /\b([A-Za-z_][A-Za-z0-9_]*)`([\s\S]*?)`/g;
277
- for (const match of source.matchAll(pattern)) {
278
- const full = match[0];
279
- const tag = match[1] ?? "template";
280
- const startIndex = match.index;
281
- const start = point(
282
- source.slice(0, startIndex + tag.length).split("\n").length - 1,
283
- (source.slice(0, startIndex + tag.length).split("\n").at(-1) ?? "").length,
284
- );
285
- const end = point(
286
- source.slice(0, startIndex + full.length).split("\n").length - 1,
287
- (source.slice(0, startIndex + full.length).split("\n").at(-1) ?? "").length,
288
- );
289
- injections.push({
290
- language: tag,
291
- range: { start, end },
292
- reason: "tagged_template",
293
- hint: tag,
294
- });
295
- }
296
- return injections;
297
- }
298
-
299
- function tsInjections(root: Parser.SyntaxNode): InjectionRegion[] {
300
- const injections: InjectionRegion[] = [];
301
- for (const node of root.descendantsOfType([
302
- "jsx_element",
303
- "jsx_fragment",
304
- "jsx_self_closing_element",
305
- ])) {
306
- injections.push({
307
- language: "jsx",
308
- range: nodeRange(node),
309
- reason: "jsx_syntax",
310
- hint: node.type,
311
- });
312
- }
313
- return injections;
314
- }
315
-
316
- function resolveSymbol(
317
- root: Parser.SyntaxNode,
318
- opts: { position?: BufferPoint | undefined; symbol?: string | undefined },
319
- ): SymbolResolution | null {
320
- if (opts.symbol !== undefined) {
321
- return { symbol: opts.symbol, kind: "occurrence", nodeType: "identifier" };
322
- }
323
- if (opts.position === undefined) {
324
- return null;
325
- }
326
- const node = symbolNodeAt(root, opts.position);
327
- if (node === null) {
328
- return null;
329
- }
330
- const parent = node.parent;
331
- const declaration = parent?.childForFieldName("name")?.id === node.id;
332
- return {
333
- symbol: node.text,
334
- kind: declaration ? "declaration" : "occurrence",
335
- nodeType: node.type,
336
- };
337
- }
338
-
339
- export function buildOutlineResult(snapshot: StructuredBufferSnapshot): BufferOutlineResult {
340
- if (snapshot.format === null) {
341
- return {
342
- path: snapshot.path,
343
- format: snapshot.format,
344
- basis: snapshot.basis,
345
- outline: [],
346
- jumpTable: [],
347
- partial: false,
348
- reason: "UNSUPPORTED_LANGUAGE",
349
- };
350
- }
351
- const result = extractOutline(snapshot.content, snapshot.format);
352
- return {
353
- path: snapshot.path,
354
- format: snapshot.format,
355
- basis: snapshot.basis,
356
- outline: result.entries,
357
- jumpTable: result.jumpTable ?? [],
358
- partial: result.partial === true,
359
- };
360
- }
361
-
362
- export function buildInjectionResult(snapshot: StructuredBufferSnapshot): InjectionResult {
363
- if (snapshot.format === "md") {
364
- return {
365
- path: snapshot.path,
366
- format: snapshot.format,
367
- basis: snapshot.basis,
368
- injections: fencedCodeInjections(snapshot.content),
369
- };
370
- }
371
- if (snapshot.parsed === null) {
372
- return {
373
- path: snapshot.path,
374
- format: snapshot.format,
375
- basis: snapshot.basis,
376
- injections: [],
377
- reason: "UNSUPPORTED_LANGUAGE",
378
- };
379
- }
380
- return {
381
- path: snapshot.path,
382
- format: snapshot.format,
383
- basis: snapshot.basis,
384
- injections: [
385
- ...tsInjections(snapshot.parsed.root),
386
- ...taggedTemplateInjections(snapshot.content),
387
- ],
388
- };
389
- }
390
-
391
- export function buildSyntaxSpansResult(
392
- snapshot: StructuredBufferSnapshot,
393
- opts: { viewport?: BufferRange | undefined } = {},
394
- ): SyntaxSpanResult {
395
- if (snapshot.parsed === null) {
396
- return {
397
- path: snapshot.path,
398
- format: snapshot.format,
399
- basis: snapshot.basis,
400
- partial: snapshot.partial,
401
- spans: [],
402
- injections: buildInjectionResult(snapshot).injections,
403
- reason: "UNSUPPORTED_LANGUAGE",
404
- };
405
- }
406
- const viewport = opts.viewport;
407
- const spans: SyntaxSpan[] = [];
408
- const stack: Parser.SyntaxNode[] = [snapshot.parsed.root];
409
- while (stack.length > 0) {
410
- const node = stack.pop();
411
- if (node === undefined) {
412
- continue;
413
- }
414
- const currentRange = nodeRange(node);
415
- if (viewport !== undefined && !rangeOverlaps(currentRange, viewport)) {
416
- continue;
417
- }
418
- if (
419
- (node.type === "comment" || node.type === "string" || node.type === "template_string" || node.type === "regex")
420
- && comparePoints(currentRange.start, currentRange.end) < 0
421
- ) {
422
- const className = classifyLeaf(node);
423
- if (className !== null) {
424
- spans.push({
425
- className,
426
- range: currentRange,
427
- text: node.text,
428
- });
429
- }
430
- continue;
431
- }
432
- if (isLeaf(node)) {
433
- const className = classifyLeaf(node);
434
- if (className !== null && comparePoints(currentRange.start, currentRange.end) < 0) {
435
- spans.push({
436
- className,
437
- range: currentRange,
438
- text: node.text,
439
- });
440
- }
441
- continue;
442
- }
443
- for (let index = node.children.length - 1; index >= 0; index -= 1) {
444
- const child = node.children[index];
445
- if (child !== undefined) {
446
- stack.push(child);
447
- }
448
- }
449
- }
450
- spans.sort((left, right) => {
451
- const startCompare = comparePoints(left.range.start, right.range.start);
452
- if (startCompare !== 0) {
453
- return startCompare;
454
- }
455
- return comparePoints(left.range.end, right.range.end);
456
- });
457
- return {
458
- path: snapshot.path,
459
- format: snapshot.format,
460
- basis: snapshot.basis,
461
- partial: snapshot.partial,
462
- spans,
463
- injections: buildInjectionResult(snapshot).injections,
464
- };
465
- }
466
-
467
- export function buildDiagnosticsResult(snapshot: StructuredBufferSnapshot): DiagnosticsResult {
468
- if (snapshot.parsed === null) {
469
- return {
470
- path: snapshot.path,
471
- format: snapshot.format,
472
- basis: snapshot.basis,
473
- partial: snapshot.partial,
474
- diagnostics: [],
475
- reason: "UNSUPPORTED_LANGUAGE",
476
- };
477
- }
478
- const diagnostics: BufferDiagnostic[] = [];
479
- for (const errorNode of snapshot.parsed.root.descendantsOfType("ERROR")) {
480
- diagnostics.push({
481
- severity: "error",
482
- code: "parse_error",
483
- message: "Parser found an error region in the buffer",
484
- range: nodeRange(errorNode),
485
- });
486
- }
487
- const missing: Parser.SyntaxNode[] = [];
488
- collectMissingNodes(snapshot.parsed.root, missing);
489
- for (const node of missing) {
490
- diagnostics.push({
491
- severity: "warning",
492
- code: "missing_node",
493
- message: `Parser inferred a missing ${node.type} node`,
494
- range: nodeRange(node),
495
- });
496
- }
497
- if (snapshot.partial && diagnostics.every((entry) => entry.code !== "parse_error")) {
498
- diagnostics.push({
499
- severity: "error",
500
- code: "parse_error",
501
- message: "Parser reported an incomplete or invalid syntax tree",
502
- range: nodeRange(snapshot.parsed.root),
503
- });
504
- }
505
- return {
506
- path: snapshot.path,
507
- format: snapshot.format,
508
- basis: snapshot.basis,
509
- partial: snapshot.partial,
510
- diagnostics,
511
- };
512
- }
513
-
514
- export function buildNodeLookupResult(snapshot: StructuredBufferSnapshot, position: BufferPoint): NodeLookupResult {
515
- if (snapshot.parsed === null) {
516
- return {
517
- path: snapshot.path,
518
- format: snapshot.format,
519
- basis: snapshot.basis,
520
- partial: snapshot.partial,
521
- node: null,
522
- parents: [],
523
- reason: "UNSUPPORTED_LANGUAGE",
524
- };
525
- }
526
- const node = snapshot.parsed.root.namedDescendantForPosition(position);
527
- const parents: NodeSummary[] = [];
528
- let current = node.parent;
529
- while (current !== null) {
530
- if (current.isNamed()) {
531
- parents.push(summarizeNode(current));
532
- }
533
- current = current.parent;
534
- }
535
- return {
536
- path: snapshot.path,
537
- format: snapshot.format,
538
- basis: snapshot.basis,
539
- partial: snapshot.partial,
540
- node: summarizeNode(node),
541
- parents,
542
- };
543
- }
544
-
545
- export function buildFoldRegionsResult(snapshot: StructuredBufferSnapshot): FoldRegionsResult {
546
- if (snapshot.format === "md") {
547
- const outline = buildOutlineResult(snapshot);
548
- return {
549
- path: snapshot.path,
550
- format: snapshot.format,
551
- basis: snapshot.basis,
552
- partial: outline.partial,
553
- regions: outline.jumpTable
554
- .filter((entry) => entry.end > entry.start)
555
- .map((entry) => ({
556
- kind: entry.kind,
557
- range: {
558
- start: point(entry.start - 1, 0),
559
- end: point(entry.end - 1, 0),
560
- },
561
- })),
562
- };
563
- }
564
- if (snapshot.parsed === null) {
565
- return {
566
- path: snapshot.path,
567
- format: snapshot.format,
568
- basis: snapshot.basis,
569
- partial: snapshot.partial,
570
- regions: [],
571
- reason: "UNSUPPORTED_LANGUAGE",
572
- };
573
- }
574
- const regions: FoldRegion[] = [];
575
- const stack: Parser.SyntaxNode[] = [snapshot.parsed.root];
576
- while (stack.length > 0) {
577
- const node = stack.pop();
578
- if (node === undefined) {
579
- continue;
580
- }
581
- if (FOLDABLE_NODE_TYPES.has(node.type) && node.endPosition.row > node.startPosition.row) {
582
- regions.push({
583
- kind: node.type,
584
- range: nodeRange(node),
585
- });
586
- }
587
- for (let index = node.children.length - 1; index >= 0; index -= 1) {
588
- const child = node.children[index];
589
- if (child !== undefined) {
590
- stack.push(child);
591
- }
592
- }
593
- }
594
- return {
595
- path: snapshot.path,
596
- format: snapshot.format,
597
- basis: snapshot.basis,
598
- partial: snapshot.partial,
599
- regions,
600
- };
601
- }
602
-
603
- export function buildSelectionExpandResult(
604
- snapshot: StructuredBufferSnapshot,
605
- selection: BufferSelection,
606
- ): SelectionStepResult {
607
- if (snapshot.parsed === null) {
608
- return {
609
- path: snapshot.path,
610
- format: snapshot.format,
611
- basis: snapshot.basis,
612
- partial: snapshot.partial,
613
- range: null,
614
- node: null,
615
- reason: "UNSUPPORTED_LANGUAGE",
616
- };
617
- }
618
- const normalized = normalizeSelection(selection);
619
- let node = findCoveringNamedNode(snapshot.parsed.root, normalized);
620
- if (rangesEqual(nodeRange(node), normalized) && node.parent?.isNamed()) {
621
- node = node.parent;
622
- }
623
- return {
624
- path: snapshot.path,
625
- format: snapshot.format,
626
- basis: snapshot.basis,
627
- partial: snapshot.partial,
628
- range: nodeRange(node),
629
- node: summarizeNode(node),
630
- };
631
- }
632
-
633
- export function buildSelectionShrinkResult(
634
- snapshot: StructuredBufferSnapshot,
635
- selection: BufferRange,
636
- ): SelectionStepResult {
637
- if (snapshot.parsed === null) {
638
- return {
639
- path: snapshot.path,
640
- format: snapshot.format,
641
- basis: snapshot.basis,
642
- partial: snapshot.partial,
643
- range: null,
644
- node: null,
645
- reason: "UNSUPPORTED_LANGUAGE",
646
- };
647
- }
648
- const normalized = normalizeSelection(selection);
649
- const node = findCoveringNamedNode(snapshot.parsed.root, normalized);
650
- if (!rangesEqual(nodeRange(node), normalized)) {
651
- return {
652
- path: snapshot.path,
653
- format: snapshot.format,
654
- basis: snapshot.basis,
655
- partial: snapshot.partial,
656
- range: nodeRange(node),
657
- node: summarizeNode(node),
658
- };
659
- }
660
- const child = nearestNamedChild(node, normalized.start);
661
- if (child === null) {
662
- return {
663
- path: snapshot.path,
664
- format: snapshot.format,
665
- basis: snapshot.basis,
666
- partial: snapshot.partial,
667
- range: null,
668
- node: null,
669
- reason: "NO_SELECTION_STEP",
670
- };
671
- }
672
- return {
673
- path: snapshot.path,
674
- format: snapshot.format,
675
- basis: snapshot.basis,
676
- partial: snapshot.partial,
677
- range: nodeRange(child),
678
- node: summarizeNode(child),
679
- };
680
- }
681
-
682
- export function buildSymbolOccurrencesResult(
683
- snapshot: StructuredBufferSnapshot,
684
- opts: { position?: BufferPoint | undefined; symbol?: string | undefined } = {},
685
- ): SymbolOccurrencesResult {
686
- if (snapshot.parsed === null) {
687
- return {
688
- path: snapshot.path,
689
- format: snapshot.format,
690
- basis: snapshot.basis,
691
- partial: snapshot.partial,
692
- symbol: null,
693
- occurrences: [],
694
- scopeApplied: "buffer",
695
- reason: "UNSUPPORTED_LANGUAGE",
696
- };
697
- }
698
- const resolved = resolveSymbol(snapshot.parsed.root, opts);
699
- if (resolved === null) {
700
- return {
701
- path: snapshot.path,
702
- format: snapshot.format,
703
- basis: snapshot.basis,
704
- partial: snapshot.partial,
705
- symbol: null,
706
- occurrences: [],
707
- scopeApplied: "buffer",
708
- reason: "SYMBOL_NOT_FOUND",
709
- };
710
- }
711
- const identifiers: Parser.SyntaxNode[] = [];
712
- collectIdentifierNodes(snapshot.parsed.root, identifiers);
713
- const occurrences = identifiers
714
- .filter((node) => node.text === resolved.symbol && (node.type === resolved.nodeType || resolved.nodeType === "identifier"))
715
- .map((node) => {
716
- const declaration = node.parent?.childForFieldName("name")?.id === node.id;
717
- return {
718
- symbol: resolved.symbol,
719
- kind: declaration ? "declaration" : "occurrence",
720
- range: nodeRange(node),
721
- } satisfies SymbolOccurrence;
722
- });
723
- return {
724
- path: snapshot.path,
725
- format: snapshot.format,
726
- basis: snapshot.basis,
727
- partial: snapshot.partial,
728
- symbol: resolved.symbol,
729
- occurrences,
730
- scopeApplied: "buffer",
731
- };
732
- }
733
-
734
- export function buildRenamePreviewResult(
735
- snapshot: StructuredBufferSnapshot,
736
- opts: { nextName: string; position?: BufferPoint | undefined; symbol?: string | undefined },
737
- ): RenamePreviewResult {
738
- const occurrences = buildSymbolOccurrencesResult(snapshot, opts);
739
- if (occurrences.reason !== undefined) {
740
- return {
741
- path: snapshot.path,
742
- format: snapshot.format,
743
- basis: snapshot.basis,
744
- partial: snapshot.partial,
745
- symbol: occurrences.symbol,
746
- nextName: opts.nextName,
747
- edits: [],
748
- scopeApplied: "buffer",
749
- reason: occurrences.reason,
750
- };
751
- }
752
- return {
753
- path: snapshot.path,
754
- format: snapshot.format,
755
- basis: snapshot.basis,
756
- partial: snapshot.partial,
757
- symbol: occurrences.symbol,
758
- nextName: opts.nextName,
759
- edits: occurrences.occurrences.map((occurrence) => ({
760
- path: snapshot.path,
761
- range: occurrence.range,
762
- before: occurrences.symbol ?? "",
763
- after: opts.nextName,
764
- })),
765
- scopeApplied: "buffer",
766
- };
767
- }
768
-
769
- export function buildWarmProjectionBundleResult(
770
- snapshot: StructuredBufferSnapshot,
771
- opts: { viewport?: BufferRange | undefined } = {},
772
- ): WarmProjectionBundleResult {
773
- const syntax = buildSyntaxSpansResult(snapshot, { viewport: opts.viewport });
774
- const diagnostics = buildDiagnosticsResult(snapshot);
775
- const folds = buildFoldRegionsResult(snapshot);
776
- const outline = buildOutlineResult(snapshot);
777
- return {
778
- path: snapshot.path,
779
- format: snapshot.format,
780
- basis: snapshot.basis,
781
- partial: snapshot.partial,
782
- parseStatus: {
783
- basis: snapshot.basis,
784
- format: snapshot.format,
785
- partial: snapshot.partial,
786
- status: snapshot.format === null ? "unsupported" : snapshot.partial ? "partial" : "full",
787
- reason: snapshot.format === null ? "UNSUPPORTED_LANGUAGE" : undefined,
788
- },
789
- syntax,
790
- diagnostics,
791
- folds,
792
- outline,
793
- };
794
- }