@wrongstack/tools 1.0.11 → 1.0.12

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 (75) hide show
  1. package/dist/builtin.js +15 -15
  2. package/dist/{chunk-GU7TZE6Z.js → chunk-2BCRQAIW.js} +7 -7
  3. package/dist/{chunk-XRNN44QY.js → chunk-2IRHFHZY.js} +235 -71
  4. package/dist/{chunk-NEYUPZL6.js → chunk-6D3UIQMF.js} +651 -303
  5. package/dist/chunk-BJ5LXLKE.js +351 -0
  6. package/dist/{chunk-C6ZOXNXV.js → chunk-CSS42GRP.js} +2 -2
  7. package/dist/{chunk-SKRMUHTU.js → chunk-HSLDY55L.js} +41 -8
  8. package/dist/{chunk-ENE22I5W.js → chunk-K37AKCTN.js} +884 -362
  9. package/dist/{chunk-DKXMDO5F.js → chunk-K3VX6V5P.js} +3 -3
  10. package/dist/chunk-OIFY4XNP.js +855 -0
  11. package/dist/{chunk-7GOE2ZTZ.js → chunk-OMWC2OGT.js} +2 -2
  12. package/dist/{chunk-IE4KDAOB.js → chunk-OYQE2UNT.js} +3 -3
  13. package/dist/chunk-R3HR3QI3.js +97 -0
  14. package/dist/{chunk-XPVYZ2S6.js → chunk-RYLMSGR5.js} +2 -2
  15. package/dist/{chunk-HYHE4VNA.js → chunk-UMOP3VGK.js} +79 -45
  16. package/dist/{chunk-6OIEYJM4.js → chunk-VMNWQI4V.js} +2 -2
  17. package/dist/{chunk-2UVAIS5O.js → chunk-YPSVPCIE.js} +2 -2
  18. package/dist/{chunk-PWZUHZP7.js → chunk-Z77XMU3U.js} +2 -2
  19. package/dist/codebase-index/ast-invariant-engine.d.ts +19 -2
  20. package/dist/codebase-index/atlas-projection.d.ts +19 -0
  21. package/dist/codebase-index/background-indexer.d.ts +14 -0
  22. package/dist/codebase-index/circuit-breaker.d.ts +7 -0
  23. package/dist/codebase-index/codebase-ast-replace-tool.d.ts +1 -1
  24. package/dist/codebase-index/codebase-impact-analysis-tool.d.ts +6 -0
  25. package/dist/codebase-index/codebase-invariant-check-tool.d.ts +2 -0
  26. package/dist/codebase-index/codebase-targeted-test-tool.d.ts +26 -0
  27. package/dist/codebase-index/dead-code-scan.d.ts +4 -0
  28. package/dist/codebase-index/go-parser.d.ts +23 -3
  29. package/dist/codebase-index/graph-rank-pass.d.ts +10 -0
  30. package/dist/codebase-index/graph-rank.d.ts +8 -0
  31. package/dist/codebase-index/index.d.ts +1 -1
  32. package/dist/codebase-index/index.js +9 -9
  33. package/dist/codebase-index/lsp-kind.d.ts +3 -1
  34. package/dist/codebase-index/module-resolver.d.ts +21 -1
  35. package/dist/codebase-index/parser-batch.d.ts +6 -8
  36. package/dist/codebase-index/parser-output.d.ts +5 -1
  37. package/dist/codebase-index/parser-worker-script.js +4 -4
  38. package/dist/codebase-index/project-server-framing.d.ts +1 -17
  39. package/dist/codebase-index/project-server-watcher.d.ts +6 -0
  40. package/dist/codebase-index/project-server.js +72 -26
  41. package/dist/codebase-index/py-parser.d.ts +4 -4
  42. package/dist/codebase-index/rs-parser.d.ts +7 -0
  43. package/dist/codebase-index/toolchain-scripts.d.ts +64 -0
  44. package/dist/codebase-index/tree-sitter/queries.d.ts +14 -0
  45. package/dist/codebase-index/tree-sitter/util.d.ts +6 -1
  46. package/dist/codebase-index/tree-sitter-parser.d.ts +7 -0
  47. package/dist/codebase-index/worker.js +23 -16
  48. package/dist/codebase-index/writer-refs.d.ts +17 -2
  49. package/dist/codebase-index/writer-search-helpers.d.ts +9 -0
  50. package/dist/codebase-index/writer.d.ts +20 -1
  51. package/dist/edit.js +8 -8
  52. package/dist/{generic-parser-N2PLGBC2.js → generic-parser-IVWLFKMR.js} +2 -2
  53. package/dist/go-parser-LWV3L5V7.js +197 -0
  54. package/dist/index.js +17 -17
  55. package/dist/json-parser-PERV2JHX.js +204 -0
  56. package/dist/pack.js +16 -16
  57. package/dist/parser-dispatch-ZSWCQB6M.js +14 -0
  58. package/dist/patch.js +8 -8
  59. package/dist/{py-parser-4PFZYAJ7.js → py-parser-B6D6RGH7.js} +4 -4
  60. package/dist/read.js +8 -8
  61. package/dist/replace.js +8 -8
  62. package/dist/rs-parser-L7SP4GWJ.js +182 -0
  63. package/dist/tool-tier.js +17 -17
  64. package/dist/{tree-sitter-parser-GILYQLS4.js → tree-sitter-parser-KU6JF3ZC.js} +6 -4
  65. package/dist/{ts-parser-7W26YB26.js → ts-parser-PML6QIH7.js} +55 -23
  66. package/dist/write.js +8 -8
  67. package/dist/{yaml-parser-DFBC5FWH.js → yaml-parser-7BJN544B.js} +41 -6
  68. package/package.json +5 -5
  69. package/dist/chunk-4CE3RKEP.js +0 -390
  70. package/dist/chunk-KHUCKLOR.js +0 -899
  71. package/dist/chunk-ZKC5UNGD.js +0 -167
  72. package/dist/go-parser-Z4H6SR3R.js +0 -474
  73. package/dist/json-parser-IJD77VL4.js +0 -256
  74. package/dist/parser-dispatch-WG4DNBHH.js +0 -14
  75. package/dist/rs-parser-GIWPUA3T.js +0 -81
@@ -1,899 +0,0 @@
1
- import {
2
- resolvePythonBinary
3
- } from "./chunk-4CE3RKEP.js";
4
- import {
5
- parseParserBatchOutput,
6
- recordParserSubprocess,
7
- withSpawnGate
8
- } from "./chunk-ZKC5UNGD.js";
9
- import {
10
- resolveWin32Command
11
- } from "./chunk-XZLVJD56.js";
12
-
13
- // src/codebase-index/import-extractor.ts
14
- var IMPORT_MAX_FILE_CHARS = 512 * 1024;
15
- var IMPORT_MAX_PER_FILE = 400;
16
- var DOTTED_IMPORT = [
17
- { re: /^[ \t]*import\s+(?:static\s+)?([\w.]+(?:\.\*)?)\s*;?\s*$/gm }
18
- ];
19
- var LANG_IMPORTS = {
20
- // Go and Python have real AST extractors; these patterns are the fallback for
21
- // machines with no Go toolchain or Python interpreter installed, where the
22
- // parser degrades to regex symbols and would otherwise contribute no edges.
23
- go: [
24
- { re: /^[ \t]*import\s+(?:[\w.]+\s+)?"([^"]+)"/gm },
25
- // Grouped form: inside `import ( … )` each line is an optional alias plus a
26
- // quoted path. A stray match elsewhere resolves to no file and is dropped.
27
- { re: /^[ \t]*(?:[A-Za-z_.]\w*\s+)?"([^"]+)"\s*$/gm }
28
- ],
29
- py: [{ re: /^[ \t]*import\s+([\w.]+)/gm }, { re: /^[ \t]*from\s+([.\w]+)\s+import\b/gm }],
30
- rs: [
31
- // use a::b::C; | use a::b::{C, D}; → the path before any brace
32
- { re: /^[ \t]*(?:pub\s+)?use\s+([\w:]+?)(?:::\{|\s*;|\s+as\b)/gm },
33
- // mod foo; (a declaration *and* a dependency on foo.rs / foo/mod.rs)
34
- { re: /^[ \t]*(?:pub\s+)?mod\s+(\w+)\s*;/gm }
35
- ],
36
- java: DOTTED_IMPORT,
37
- kotlin: DOTTED_IMPORT,
38
- scala: [{ re: /^[ \t]*import\s+([\w.]+(?:\.[_*])?)\s*$/gm }],
39
- csharp: [
40
- // using Foo.Bar; | using static Foo.Bar; | using Alias = Foo.Bar;
41
- { re: /^[ \t]*global\s+using\s+(?:static\s+)?([\w.]+)\s*;/gm, name: "full" },
42
- { re: /^[ \t]*using\s+(?:static\s+)?(?:\w+\s*=\s*)?([\w.]+)\s*;/gm, name: "full" }
43
- ],
44
- // Quoted includes only: <stdio.h> is a system header with no indexed file.
45
- c: [{ re: /^[ \t]*#\s*include\s+"([^"]+)"/gm }],
46
- cpp: [{ re: /^[ \t]*#\s*include\s+"([^"]+)"/gm }],
47
- ruby: [{ re: /^[ \t]*(?:require|require_relative|load)\s*\(?\s*['"]([^'"]+)['"]/gm }],
48
- php: [
49
- // `use A\B\C` imports the class C, which is what the index has a symbol
50
- // for — the namespace symbol only covers the `A\B` prefix.
51
- { re: /^[ \t]*use\s+(?:function\s+|const\s+)?([\w\\]+)/gm },
52
- { re: /^[ \t]*(?:require|require_once|include|include_once)\s*\(?\s*['"]([^'"]+)['"]/gm }
53
- ],
54
- swift: [{ re: /^[ \t]*import\s+(?:struct\s+|class\s+|func\s+)?([\w.]+)\s*$/gm }],
55
- dart: [{ re: /^[ \t]*(?:import|export|part)\s+['"]([^'"]+)['"]/gm }],
56
- lua: [{ re: /\brequire\s*\(?\s*['"]([^'"]+)['"]/g }],
57
- elixir: [{ re: /^[ \t]*(?:alias|import|require|use)\s+([A-Z][\w.]*)/gm, name: "full" }],
58
- haskell: [{ re: /^[ \t]*import\s+(?:qualified\s+)?([\w.]+)/gm, name: "full" }],
59
- zig: [{ re: /@import\s*\(\s*"([^"]+)"\s*\)/g }],
60
- proto: [{ re: /^[ \t]*import\s+(?:public\s+|weak\s+)?"([^"]+)"\s*;/gm }],
61
- // `@import "x"`, `@use "x"`, `@forward "x"` — Sass and plain CSS alike.
62
- css: [{ re: /^[ \t]*@(?:import|use|forward)\s+(?:url\()?\s*['"]([^'"]+)['"]/gm }],
63
- // A .vue/.svelte file's <script> block is JS; the same ESM syntax applies.
64
- vue: [{ re: /^[ \t]*import\s[^'"]*from\s*['"]([^'"]+)['"]/gm }],
65
- svelte: [{ re: /^[ \t]*import\s[^'"]*from\s*['"]([^'"]+)['"]/gm }],
66
- html: [
67
- { re: /<script[^>]+src\s*=\s*['"]([^'"]+)['"]/g },
68
- { re: /<link[^>]+href\s*=\s*['"]([^'"]+)['"]/g }
69
- ],
70
- shell: [{ re: /^[ \t]*(?:source|\.)\s+(\S+)/gm }],
71
- r: [{ re: /\b(?:source|library|require)\s*\(\s*['"]?([\w./-]+)['"]?\s*\)/g }]
72
- };
73
- function lastSegment(specifier) {
74
- const pathLike = /[/\\]|::/.test(specifier);
75
- const segments = specifier.split(/[/\\]|::/).filter(Boolean);
76
- let last = segments[segments.length - 1] ?? specifier;
77
- if (last === "*" || last === "_") {
78
- last = segments[segments.length - 2] ?? specifier;
79
- }
80
- if (pathLike) return last.replace(/\.[A-Za-z0-9]{1,8}$/, "") || last;
81
- const dotted = last.split(".").filter((part) => part && part !== "*" && part !== "_");
82
- return dotted[dotted.length - 1] ?? last;
83
- }
84
- function newlineOffsets(content) {
85
- const offsets = [];
86
- for (let i = 0; i < content.length; i++) {
87
- if (content.charCodeAt(i) === 10) offsets.push(i);
88
- }
89
- return offsets;
90
- }
91
- function lineAt(offsets, index) {
92
- let low = 0;
93
- let high = offsets.length;
94
- while (low < high) {
95
- const mid = low + high >>> 1;
96
- if ((offsets[mid] ?? 0) < index) low = mid + 1;
97
- else high = mid;
98
- }
99
- return low + 1;
100
- }
101
- function hasImportPatterns(lang) {
102
- return LANG_IMPORTS[lang] !== void 0;
103
- }
104
- function extractImports(opts) {
105
- const patterns = LANG_IMPORTS[opts.lang];
106
- if (!patterns || !opts.content) return [];
107
- const limit = opts.maxImports ?? IMPORT_MAX_PER_FILE;
108
- const content = opts.content.length > IMPORT_MAX_FILE_CHARS ? opts.content.slice(0, IMPORT_MAX_FILE_CHARS) : opts.content;
109
- const refs = [];
110
- const seen = /* @__PURE__ */ new Set();
111
- const offsets = newlineOffsets(content);
112
- for (const pattern of patterns) {
113
- const re = new RegExp(pattern.re.source, pattern.re.flags);
114
- for (const match of content.matchAll(re)) {
115
- if (refs.length >= limit) return refs;
116
- const specifier = match[1]?.trim();
117
- if (!specifier) continue;
118
- const module = specifier;
119
- const toName = pattern.name === "full" ? module : lastSegment(module);
120
- if (!toName) continue;
121
- const key = `${module}\0${toName}`;
122
- if (seen.has(key)) continue;
123
- seen.add(key);
124
- refs.push({
125
- fromId: 0,
126
- toName,
127
- callType: "import",
128
- line: lineAt(offsets, match.index ?? 0),
129
- lang: opts.lang,
130
- module
131
- });
132
- }
133
- }
134
- return refs;
135
- }
136
-
137
- // src/codebase-index/parser-batch.ts
138
- import { spawn } from "node:child_process";
139
- import * as fsSync from "node:fs";
140
- import * as fs from "node:fs/promises";
141
- import * as os from "node:os";
142
- import * as path from "node:path";
143
- import { StringDecoder } from "node:string_decoder";
144
- var MAX_BATCH_FILES = 100;
145
- var MAX_BATCH_BYTES = 8 * 1024 * 1024;
146
- function chunkBatchFiles(files) {
147
- const chunks = [];
148
- let current = [];
149
- let bytes = 0;
150
- for (const file of files) {
151
- const size = Buffer.byteLength(file.content, "utf8");
152
- if (current.length > 0 && (current.length >= MAX_BATCH_FILES || bytes + size > MAX_BATCH_BYTES)) {
153
- chunks.push(current);
154
- current = [];
155
- bytes = 0;
156
- }
157
- current.push(file);
158
- bytes += size;
159
- }
160
- if (current.length > 0) chunks.push(current);
161
- return chunks;
162
- }
163
- function batchTimeoutMs(fileCount) {
164
- return Math.min(12e4, 15e3 + fileCount * 1500);
165
- }
166
- var GO_BATCH_SCRIPT = `
167
- package main
168
-
169
- import (
170
- "encoding/json"
171
- "fmt"
172
- "go/ast"
173
- "go/parser"
174
- "go/token"
175
- "io"
176
- "os"
177
- "strconv"
178
- "strings"
179
- )
180
-
181
- type Sym struct {
182
- Name string \`json:"name"\`
183
- Kind string \`json:"kind"\`
184
- Line int \`json:"line"\`
185
- Col int \`json:"col"\`
186
- Signature string \`json:"signature"\`
187
- Scope string \`json:"scope"\`
188
- }
189
-
190
- type Ref struct {
191
- ToName string \`json:"toName"\`
192
- CallType string \`json:"callType"\`
193
- Line int \`json:"line"\`
194
- Module string \`json:"module"\`
195
- }
196
-
197
- type FileResult struct {
198
- File string \`json:"file"\`
199
- Error string \`json:"error,omitempty"\`
200
- Symbols []Sym \`json:"symbols"\`
201
- Refs []Ref \`json:"refs"\`
202
- }
203
-
204
- type BatchResult struct {
205
- Version int \`json:"version"\`
206
- Results []FileResult \`json:"results"\`
207
- }
208
-
209
- type inputFile struct {
210
- File string \`json:"file"\`
211
- Content string \`json:"content"\`
212
- }
213
-
214
- func parseOne(name string, src []byte) FileResult {
215
- res := FileResult{File: name, Symbols: []Sym{}, Refs: []Ref{}}
216
- fset := token.NewFileSet()
217
- node, err := parser.ParseFile(fset, "src.go", src, 0)
218
- if err != nil {
219
- res.Error = err.Error()
220
- return res
221
- }
222
- pkgScope := node.Name.Name
223
- for _, decl := range node.Decls {
224
- switch d := decl.(type) {
225
- case *ast.FuncDecl:
226
- symName := d.Name.Name
227
- kind := "function"
228
- scope := pkgScope
229
- if d.Recv != nil && len(d.Recv.List) > 0 {
230
- scope = pkgScope + "." + recvTypeName(d.Recv.List[0].Type) + "." + symName
231
- kind = "method"
232
- } else {
233
- scope = pkgScope + "." + symName
234
- }
235
- pos := fset.Position(d.Pos())
236
- res.Symbols = append(res.Symbols, Sym{Name: symName, Kind: kind, Line: pos.Line, Col: pos.Column, Signature: formatFuncSig(d), Scope: scope})
237
- case *ast.GenDecl:
238
- for _, spec := range d.Specs {
239
- switch s := spec.(type) {
240
- case *ast.TypeSpec:
241
- typeName := s.Name.Name
242
- pos := fset.Position(s.Pos())
243
- sig := "type " + typeName
244
- if s.TypeParams != nil {
245
- sig += formatTypeParams(s.TypeParams)
246
- }
247
- if st, ok := s.Type.(*ast.StructType); ok {
248
- sig += " = struct { " + formatFields(st.Fields.List) + " }"
249
- } else if it, ok := s.Type.(*ast.InterfaceType); ok {
250
- sig += " = interface { " + formatMethods(it.Methods.List) + " }"
251
- } else {
252
- sig += " = " + formatType(s.Type)
253
- }
254
- res.Symbols = append(res.Symbols, Sym{Name: typeName, Kind: "type", Line: pos.Line, Col: pos.Column, Signature: sig, Scope: pkgScope})
255
- case *ast.ValueSpec:
256
- for _, n := range s.Names {
257
- valueName := n.Name
258
- pos := fset.Position(n.Pos())
259
- kind := "var"
260
- if d.Tok == token.CONST {
261
- kind = "const"
262
- }
263
- sig := kind + " " + valueName
264
- if s.Type != nil {
265
- sig += " " + formatType(s.Type)
266
- }
267
- res.Symbols = append(res.Symbols, Sym{Name: valueName, Kind: kind, Line: pos.Line, Col: pos.Column, Signature: sig, Scope: pkgScope})
268
- }
269
- }
270
- }
271
- }
272
- }
273
- ast.Inspect(node, func(n ast.Node) bool {
274
- switch expr := n.(type) {
275
- case *ast.CallExpr:
276
- line := fset.Position(expr.Pos()).Line
277
- switch fun := expr.Fun.(type) {
278
- case *ast.Ident:
279
- res.Refs = append(res.Refs, Ref{ToName: fun.Name, CallType: "call", Line: line})
280
- case *ast.SelectorExpr:
281
- res.Refs = append(res.Refs, Ref{ToName: fun.Sel.Name, CallType: "call", Line: line})
282
- }
283
- case *ast.ImportSpec:
284
- if expr.Path != nil {
285
- if importPath, uerr := strconv.Unquote(expr.Path.Value); uerr == nil {
286
- line := fset.Position(expr.Pos()).Line
287
- name := importPath
288
- if idx := strings.LastIndex(importPath, "/"); idx >= 0 {
289
- name = importPath[idx+1:]
290
- }
291
- res.Refs = append(res.Refs, Ref{ToName: name, CallType: "import", Line: line, Module: importPath})
292
- }
293
- }
294
- }
295
- return true
296
- })
297
- return res
298
- }
299
-
300
- func main() {
301
- raw, err := io.ReadAll(os.Stdin)
302
- if err != nil {
303
- out, _ := json.Marshal(BatchResult{Version: 1, Results: []FileResult{}})
304
- fmt.Print(string(out))
305
- return
306
- }
307
- var inputs []inputFile
308
- if err := json.Unmarshal(raw, &inputs); err != nil {
309
- out, _ := json.Marshal(BatchResult{Version: 1, Results: []FileResult{}})
310
- fmt.Print(string(out))
311
- return
312
- }
313
- results := make([]FileResult, 0, len(inputs))
314
- for _, in := range inputs {
315
- results = append(results, parseOne(in.File, []byte(in.Content)))
316
- }
317
- data, err := json.Marshal(BatchResult{Version: 1, Results: results})
318
- if err != nil {
319
- fmt.Print("{\\"version\\":1,\\"results\\":[]}")
320
- return
321
- }
322
- fmt.Print(string(data))
323
- }
324
-
325
- func recvTypeName(t ast.Expr) string {
326
- switch v := t.(type) {
327
- case *ast.Ident:
328
- return v.Name
329
- case *ast.StarExpr:
330
- return recvTypeName(v.X)
331
- default:
332
- return "?"
333
- }
334
- }
335
-
336
- func formatFuncSig(d *ast.FuncDecl) string {
337
- scope := ""
338
- if d.Recv != nil && len(d.Recv.List) > 0 {
339
- scope = "(" + formatFieldList(d.Recv.List) + ") "
340
- }
341
- scope += formatFuncType(d.Type)
342
- return "func " + scope
343
- }
344
-
345
- func formatFuncType(f *ast.FuncType) string {
346
- params := formatFieldList(f.Params.List)
347
- results := ""
348
- if f.Results != nil {
349
- results = " -> " + formatFieldList(f.Results.List)
350
- }
351
- return params + results
352
- }
353
-
354
- func formatFieldList(fields []*ast.Field) string {
355
- if len(fields) == 0 {
356
- return "()"
357
- }
358
- names := make([]string, 0, len(fields))
359
- for _, f := range fields {
360
- name := ""
361
- if len(f.Names) > 0 {
362
- name = f.Names[0].Name
363
- }
364
- t := formatType(f.Type)
365
- if name != "" {
366
- names = append(names, name+" "+t)
367
- } else {
368
- names = append(names, t)
369
- }
370
- }
371
- return "(" + strings.Join(names, ", ") + ")"
372
- }
373
-
374
- func formatFields(fields []*ast.Field) string {
375
- lines := make([]string, 0)
376
- for _, f := range fields {
377
- name := ""
378
- if len(f.Names) > 0 {
379
- name = f.Names[0].Name
380
- }
381
- t := formatType(f.Type)
382
- if name != "" {
383
- lines = append(lines, name+" "+t)
384
- } else {
385
- lines = append(lines, t)
386
- }
387
- }
388
- return strings.Join(lines, "; ")
389
- }
390
-
391
- func formatMethods(fields []*ast.Field) string {
392
- return formatFields(fields)
393
- }
394
-
395
- func formatTypeParams(tp *ast.FieldList) string {
396
- if tp == nil || len(tp.List) == 0 {
397
- return ""
398
- }
399
- params := make([]string, len(tp.List))
400
- for i, p := range tp.List {
401
- if len(p.Names) > 0 {
402
- params[i] = p.Names[0].Name
403
- } else {
404
- params[i] = "T"
405
- }
406
- }
407
- return "[" + strings.Join(params, ", ") + "]"
408
- }
409
-
410
- func formatType(t ast.Expr) string {
411
- if t == nil {
412
- return "?"
413
- }
414
- switch v := t.(type) {
415
- case *ast.Ident:
416
- return v.Name
417
- case *ast.SelectorExpr:
418
- return formatType(v.X) + "." + v.Sel.Name
419
- case *ast.StarExpr:
420
- return "*" + formatType(v.X)
421
- case *ast.ArrayType:
422
- if v.Len == nil {
423
- return "[]" + formatType(v.Elt)
424
- }
425
- return "[...]" + formatType(v.Elt)
426
- case *ast.MapType:
427
- return "map[" + formatType(v.Key) + "]" + formatType(v.Value)
428
- case *ast.InterfaceType:
429
- return "interface{}"
430
- case *ast.StructType:
431
- return "struct{}"
432
- case *ast.FuncType:
433
- return formatFuncType(v)
434
- case *ast.ChanType:
435
- return "chan " + formatType(v.Value)
436
- case *ast.BasicLit:
437
- return v.Value
438
- case *ast.IndexExpr:
439
- return formatType(v.X) + "[" + formatType(v.Index) + "]"
440
- case *ast.IndexListExpr:
441
- args := make([]string, len(v.Indices))
442
- for i, idx := range v.Indices {
443
- args[i] = formatType(idx)
444
- }
445
- return formatType(v.X) + "[" + strings.Join(args, ", ") + "]"
446
- default:
447
- return "?"
448
- }
449
- }
450
- `;
451
- var PY_BATCH_SCRIPT = `import ast, json, sys
452
-
453
- def get_name(node):
454
- if isinstance(node, ast.Name):
455
- return node.id
456
- elif isinstance(node, ast.Attribute):
457
- return get_name(node.value) + "." + node.attr
458
- elif isinstance(node, ast.Subscript):
459
- return get_name(node.value)
460
- elif isinstance(node, ast.Call):
461
- return get_name(node.func)
462
- elif isinstance(node, ast.Constant):
463
- return str(node.value)
464
- return ""
465
-
466
- def leaf_name(node):
467
- if isinstance(node, ast.Attribute):
468
- return node.attr
469
- if isinstance(node, ast.Name):
470
- return node.id
471
- return get_name(node).split(".")[-1]
472
-
473
- def is_private(name):
474
- return name.startswith("__") and not name.endswith("__")
475
-
476
- def parse_one(name, source, module_name):
477
- result = {"file": name, "symbols": [], "refs": []}
478
- try:
479
- tree = ast.parse(source, filename=name)
480
- except Exception as e:
481
- result["error"] = str(e)
482
- return result
483
- syms = []
484
- refs = []
485
- scope_stack = [module_name]
486
-
487
- def sym(d):
488
- return {
489
- "name": d["name"], "kind": d["kind"], "line": d["line"], "col": d["col"],
490
- "signature": d["signature"], "scope": d["scope"],
491
- }
492
-
493
- class Visitor(ast.NodeVisitor):
494
- def visit_ClassDef(self, node):
495
- bases = [get_name(b) for b in node.bases]
496
- sig = "class " + node.name
497
- if bases:
498
- sig += "(" + ", ".join(bases) + ")"
499
- sig += ": ..."
500
- syms.append(sym({
501
- "name": node.name, "kind": "class", "line": node.lineno,
502
- "col": node.col_offset, "signature": sig,
503
- "scope": ".".join(scope_stack) + "." + node.name,
504
- }))
505
- scope_stack.append(node.name)
506
- self.generic_visit(node)
507
- scope_stack.pop()
508
-
509
- def visit_FunctionDef(self, node):
510
- args = ", ".join(a.arg for a in node.args.args)
511
- returns = get_name(node.returns) if node.returns is not None else ""
512
- is_async = isinstance(node, ast.AsyncFunctionDef)
513
- kind = "function"
514
- prefix = "def "
515
- for dec in node.decorator_list:
516
- d = get_name(dec)
517
- if d.endswith(".staticmethod"):
518
- kind = "staticmethod"
519
- elif d.endswith(".classmethod"):
520
- kind = "classmethod"
521
- elif d == "property":
522
- kind = "property"
523
- if is_async:
524
- kind = "async_" + kind
525
- sig = f"{prefix}{node.name}({args})"
526
- if returns:
527
- sig += f" -> {returns}"
528
- syms.append(sym({
529
- "name": node.name, "kind": kind, "line": node.lineno,
530
- "col": node.col_offset, "signature": sig,
531
- "scope": ".".join(scope_stack) + "." + node.name,
532
- }))
533
-
534
- def visit_AsyncFunctionDef(self, node):
535
- self.visit_FunctionDef(node)
536
-
537
- def visit_Assign(self, node):
538
- for target in node.targets:
539
- if isinstance(target, ast.Name):
540
- tname = target.id
541
- if is_private(tname):
542
- continue
543
- kind = "const" if tname.isupper() else "var"
544
- col = target.col_offset if hasattr(target, "col_offset") else 0
545
- syms.append(sym({
546
- "name": tname, "kind": kind, "line": node.lineno, "col": col,
547
- "signature": f"{tname} = ...", "scope": ".".join(scope_stack),
548
- }))
549
-
550
- def visit_AnnAssign(self, node):
551
- if isinstance(node.target, ast.Name):
552
- tname = node.target.id
553
- if is_private(tname):
554
- return
555
- kind = "const" if tname.isupper() else "var"
556
- col = node.target.col_offset if hasattr(node.target, "col_offset") else 0
557
- sig = f"{tname}: {get_name(node.annotation)}"
558
- if node.value:
559
- sig += " = ..."
560
- syms.append(sym({
561
- "name": tname, "kind": kind, "line": node.lineno, "col": col,
562
- "signature": sig, "scope": ".".join(scope_stack),
563
- }))
564
-
565
- def visit_Import(self, node):
566
- # Parity with the single-file parser: imports are symbols too.
567
- for alias in node.names:
568
- name = alias.asname or alias.name
569
- syms.append(sym({
570
- "name": name, "kind": "import", "line": node.lineno,
571
- "col": node.col_offset, "signature": f"import {alias.name}",
572
- "scope": ".".join(scope_stack),
573
- }))
574
-
575
- def visit_ImportFrom(self, node):
576
- module = node.module or ""
577
- for alias in node.names:
578
- name = alias.asname or alias.name
579
- syms.append(sym({
580
- "name": name, "kind": "import", "line": node.lineno,
581
- "col": node.col_offset, "signature": f"from {module} import {alias.name}",
582
- "scope": ".".join(scope_stack),
583
- }))
584
-
585
- Visitor().visit(tree)
586
-
587
- for node in ast.walk(tree):
588
- if isinstance(node, ast.Call):
589
- cname = leaf_name(node.func)
590
- if cname:
591
- refs.append({"toName": cname, "callType": "call", "line": node.lineno})
592
- elif isinstance(node, ast.Import):
593
- for alias in node.names:
594
- refs.append({
595
- "toName": alias.name.split(".")[-1], "callType": "import",
596
- "line": node.lineno, "module": alias.name,
597
- })
598
- elif isinstance(node, ast.ImportFrom):
599
- module = ("." * (node.level or 0)) + (node.module or "")
600
- for alias in node.names:
601
- refs.append({
602
- "toName": alias.name, "callType": "import",
603
- "line": node.lineno, "module": module,
604
- })
605
- elif isinstance(node, ast.ClassDef):
606
- for base in node.bases:
607
- bname = leaf_name(base)
608
- if bname:
609
- refs.append({"toName": bname, "callType": "inherit", "line": node.lineno})
610
-
611
- result["symbols"] = syms
612
- result["refs"] = refs
613
- return result
614
-
615
- def main():
616
- try:
617
- inputs = json.loads(sys.stdin.read())
618
- except Exception:
619
- print(json.dumps({"version": 1, "results": []}))
620
- return
621
- results = []
622
- for entry in inputs:
623
- name = entry.get("file", "")
624
- module_name = name.rsplit("/", 1)[-1].rsplit("\\\\", 1)[-1][:-3]
625
- results.append(parse_one(name, entry.get("content", ""), module_name))
626
- print(json.dumps({"version": 1, "results": results}))
627
-
628
- main()
629
- `;
630
- var _goBatchScriptPath = null;
631
- var _pyBatchScriptPath = null;
632
- async function ensureScriptPath(cached, prefix, fileName, script) {
633
- if (cached) return { path: cached, wrote: false };
634
- const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
635
- const scriptPath = path.join(dir, fileName);
636
- await fs.writeFile(scriptPath, script, { encoding: "utf8", flag: "wx" });
637
- process.once("exit", () => {
638
- try {
639
- fsSync.rmSync(dir, { recursive: true, force: true });
640
- } catch {
641
- }
642
- });
643
- return { path: scriptPath, wrote: true };
644
- }
645
- function runToolchainChild(binary, args, stdinPayload, timeoutMs) {
646
- return new Promise((resolve) => {
647
- let settled = false;
648
- let stdout = "";
649
- let proc;
650
- try {
651
- recordParserSubprocess();
652
- proc = spawn(binary, args, { stdio: ["pipe", "pipe", "pipe"], windowsHide: true });
653
- } catch {
654
- resolve(null);
655
- return;
656
- }
657
- const finish = (value) => {
658
- if (settled) return;
659
- settled = true;
660
- clearTimeout(timer);
661
- resolve(value);
662
- };
663
- const timer = setTimeout(() => {
664
- proc.kill("SIGKILL");
665
- finish(null);
666
- }, timeoutMs);
667
- timer.unref?.();
668
- proc.on("error", () => finish(null));
669
- const stdoutDecoder = new StringDecoder("utf8");
670
- proc.stdout?.on("data", (chunk) => {
671
- stdout += stdoutDecoder.write(chunk);
672
- });
673
- proc.stderr?.resume();
674
- proc.stdin?.on("error", () => {
675
- });
676
- proc.stdin?.write(stdinPayload);
677
- proc.stdin?.end();
678
- proc.on("close", (code) => {
679
- stdout += stdoutDecoder.end();
680
- finish({ code, stdout });
681
- });
682
- });
683
- }
684
- async function runGoBatch(files, goBinary) {
685
- const out = /* @__PURE__ */ new Map();
686
- if (files.length === 0) return out;
687
- const { path: scriptPath } = await ensureScriptPath(
688
- _goBatchScriptPath,
689
- "ws-go-parse",
690
- "batch.go",
691
- GO_BATCH_SCRIPT
692
- );
693
- _goBatchScriptPath = scriptPath;
694
- const payload = JSON.stringify(files.map((f) => ({ file: f.file, content: f.content })));
695
- const result = await withSpawnGate(
696
- () => runToolchainChild(
697
- goBinary ?? resolveWin32Command("go"),
698
- ["run", scriptPath],
699
- payload,
700
- batchTimeoutMs(files.length)
701
- )
702
- );
703
- if (result?.code !== 0 || !result.stdout.trim()) return out;
704
- for (const entry of parseParserBatchOutput(result.stdout, "go")) {
705
- if (entry.error !== void 0) continue;
706
- out.set(entry.file, {
707
- file: entry.file,
708
- lang: "go",
709
- symbols: entry.symbols.map((s) => ({
710
- id: 0,
711
- lang: "go",
712
- kind: s.kind,
713
- name: s.name,
714
- file: entry.file,
715
- line: s.line,
716
- col: s.col,
717
- signature: s.signature ?? "",
718
- docComment: "",
719
- scope: s.scope ?? "",
720
- text: `${s.name} ${s.signature ?? ""}`.trim()
721
- })),
722
- refs: entry.refs,
723
- mtimeMs: Date.now()
724
- });
725
- }
726
- return out;
727
- }
728
- async function runPyBatch(files, pythonBinary) {
729
- const out = /* @__PURE__ */ new Map();
730
- if (files.length === 0) return out;
731
- const { path: scriptPath } = await ensureScriptPath(
732
- _pyBatchScriptPath,
733
- "ws-py-parse",
734
- "batch.py",
735
- PY_BATCH_SCRIPT
736
- );
737
- _pyBatchScriptPath = scriptPath;
738
- const payload = JSON.stringify(files.map((f) => ({ file: f.file, content: f.content })));
739
- const result = await withSpawnGate(
740
- () => runToolchainChild(pythonBinary, [scriptPath], payload, batchTimeoutMs(files.length))
741
- );
742
- if (result?.code !== 0 || !result.stdout.trim()) return out;
743
- for (const entry of parseParserBatchOutput(result.stdout, "py")) {
744
- if (entry.error !== void 0) continue;
745
- out.set(entry.file, {
746
- file: entry.file,
747
- lang: "py",
748
- symbols: entry.symbols.map((s) => ({
749
- id: 0,
750
- lang: "py",
751
- kind: s.kind,
752
- name: s.name,
753
- file: entry.file,
754
- line: s.line,
755
- col: s.col,
756
- signature: s.signature ?? "",
757
- docComment: "",
758
- scope: s.scope ?? "",
759
- text: `${s.name} ${s.signature ?? ""}`.trim()
760
- })),
761
- refs: entry.refs,
762
- mtimeMs: Date.now()
763
- });
764
- }
765
- return out;
766
- }
767
-
768
- // src/codebase-index/parser-dispatch.ts
769
- async function parseFileContent(file, content, lang) {
770
- const parsed = await dispatch(file, content, lang);
771
- return withRelations(parsed, content, lang);
772
- }
773
- async function parseFilesContent(files) {
774
- if (files.length === 0) return [];
775
- const slots = files.map(() => ({ result: null }));
776
- const batchingEnabled = process.env["WRONGSTACK_TOOLCHAIN_BATCH"] !== "0";
777
- if (batchingEnabled) {
778
- const goFiles = [];
779
- const pyFiles = [];
780
- files.forEach((f, index) => {
781
- if (f.lang === "go") goFiles.push({ ...f, index });
782
- else if (f.lang === "py") pyFiles.push({ ...f, index });
783
- });
784
- if (goFiles.length > 0) {
785
- await applyBatchResults(slots, goFiles, (chunks) => runGoBatch(chunks), "go");
786
- }
787
- if (pyFiles.length > 0) {
788
- const pyBinary = await resolvePythonBinary();
789
- if (pyBinary) {
790
- await applyBatchResults(slots, pyFiles, (chunks) => runPyBatch(chunks, pyBinary), "py");
791
- }
792
- }
793
- }
794
- const jobs = [];
795
- for (let i = 0; i < files.length; i++) {
796
- if (slots[i].result !== null) continue;
797
- const { file, content, lang } = files[i];
798
- const slot = slots[i];
799
- jobs.push(
800
- (async () => {
801
- try {
802
- slot.result = await parseFileContent(file, content, lang);
803
- } catch (err) {
804
- slot.error = err instanceof Error ? err.message : String(err);
805
- }
806
- })()
807
- );
808
- }
809
- await Promise.all(jobs);
810
- return slots;
811
- }
812
- async function applyBatchResults(slots, batchFiles, runBatch, lang) {
813
- for (const chunk of chunkBatchFiles(batchFiles)) {
814
- let byFile = null;
815
- try {
816
- byFile = await runBatch(chunk);
817
- } catch {
818
- byFile = null;
819
- }
820
- if (!byFile) continue;
821
- for (const item of chunk) {
822
- const parsed = byFile.get(item.file);
823
- if (!parsed) continue;
824
- slots[item.index] = { result: withRelations(parsed, item.content, lang) };
825
- }
826
- }
827
- }
828
- async function dispatch(file, content, lang) {
829
- switch (lang) {
830
- case "ts":
831
- case "tsx":
832
- case "js":
833
- case "jsx": {
834
- const { parseSymbols } = await import("./ts-parser-7W26YB26.js");
835
- return parseSymbols({ file, content, lang });
836
- }
837
- case "go": {
838
- const { parseSymbols } = await import("./go-parser-Z4H6SR3R.js");
839
- return parseSymbols({ file, content, lang: "go" });
840
- }
841
- case "py": {
842
- const { parseSymbols } = await import("./py-parser-4PFZYAJ7.js");
843
- return parseSymbols({ file, content, lang: "py" });
844
- }
845
- case "rs": {
846
- const { parseSymbols } = await import("./rs-parser-GIWPUA3T.js");
847
- return parseSymbols({ file, content, lang: "rs" });
848
- }
849
- case "json": {
850
- const { parseSymbols } = await import("./json-parser-IJD77VL4.js");
851
- return parseSymbols({ file, content, lang: "json" });
852
- }
853
- case "yaml": {
854
- const { parseSymbols } = await import("./yaml-parser-DFBC5FWH.js");
855
- return parseSymbols({ file, content, lang: "yaml" });
856
- }
857
- // Phase 1: ten languages now route through the Tree-Sitter WASM
858
- // universal parser (`tree-sitter-parser.ts`). The dispatch falls back to
859
- // the regex extractor in `generic-parser.ts` whenever WASM loading fails
860
- // or the parser returns zero symbols — preserving the indexable-file
861
- // contract that "missing a parser must never mean skipping the file".
862
- case "c":
863
- case "cpp":
864
- case "java":
865
- case "csharp":
866
- case "php":
867
- case "ruby":
868
- case "swift":
869
- case "kotlin":
870
- case "shell":
871
- case "elixir": {
872
- try {
873
- const { parseSymbols: parseSymbols2 } = await import("./tree-sitter-parser-GILYQLS4.js");
874
- const parsed = await parseSymbols2({ file, content, lang });
875
- if (parsed.symbols.length > 0) return parsed;
876
- } catch {
877
- }
878
- const { parseSymbols } = await import("./generic-parser-N2PLGBC2.js");
879
- return parseSymbols({ file, content, lang });
880
- }
881
- default: {
882
- const { parseSymbols } = await import("./generic-parser-N2PLGBC2.js");
883
- return parseSymbols({ file, content, lang });
884
- }
885
- }
886
- }
887
- function withRelations(parsed, content, lang) {
888
- let refs = parsed.refs ?? [];
889
- if (refs.length === 0 && hasImportPatterns(lang)) {
890
- refs = extractImports({ content, lang });
891
- }
892
- return { ...parsed, refs: refs.map((ref) => ref.lang ? ref : { ...ref, lang }) };
893
- }
894
-
895
- export {
896
- parseFileContent,
897
- parseFilesContent
898
- };
899
- //# sourceMappingURL=chunk-KHUCKLOR.js.map