@vibgrate/cli 2026.702.2 → 2026.703.3
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.
- package/DOCS.md +521 -146
- package/LICENSE +202 -0
- package/NOTICE +40 -0
- package/README.md +232 -250
- package/dist/baseline-ZBXJONQ6.js +6 -0
- package/dist/baseline-ZBXJONQ6.js.map +1 -0
- package/dist/chunk-2PJRXVUW.js +11389 -0
- package/dist/chunk-2PJRXVUW.js.map +1 -0
- package/dist/chunk-4M2MUQRO.js +800 -0
- package/dist/chunk-4M2MUQRO.js.map +1 -0
- package/dist/chunk-FPUNJNXD.js +31 -0
- package/dist/chunk-FPUNJNXD.js.map +1 -0
- package/dist/chunk-J4DFLN2Q.js +6267 -0
- package/dist/chunk-J4DFLN2Q.js.map +1 -0
- package/dist/chunk-RXP66R2E.js +39 -0
- package/dist/chunk-RXP66R2E.js.map +1 -0
- package/dist/chunk-X5YT263H.js +912 -0
- package/dist/chunk-X5YT263H.js.map +1 -0
- package/dist/cli.d.ts +44 -1
- package/dist/cli.js +3816 -165
- package/dist/cli.js.map +1 -0
- package/dist/fs-7KZ4F3SB.js +3 -0
- package/dist/fs-7KZ4F3SB.js.map +1 -0
- package/dist/index.d.ts +1010 -1
- package/dist/index.js +42 -1
- package/dist/index.js.map +1 -0
- package/dist/parse-worker.d.ts +23 -0
- package/dist/parse-worker.js +32 -0
- package/dist/parse-worker.js.map +1 -0
- package/dist/types-C6ZyQpa9.d.ts +168 -0
- package/grammars/tree-sitter-bash.wasm +0 -0
- package/grammars/tree-sitter-c.wasm +0 -0
- package/grammars/tree-sitter-c_sharp.wasm +0 -0
- package/grammars/tree-sitter-cpp.wasm +0 -0
- package/grammars/tree-sitter-dart.wasm +0 -0
- package/grammars/tree-sitter-elixir.wasm +0 -0
- package/grammars/tree-sitter-go.wasm +0 -0
- package/grammars/tree-sitter-java.wasm +0 -0
- package/grammars/tree-sitter-javascript.wasm +0 -0
- package/grammars/tree-sitter-kotlin.wasm +0 -0
- package/grammars/tree-sitter-lua.wasm +0 -0
- package/grammars/tree-sitter-php.wasm +0 -0
- package/grammars/tree-sitter-python.wasm +0 -0
- package/grammars/tree-sitter-ruby.wasm +0 -0
- package/grammars/tree-sitter-rust.wasm +0 -0
- package/grammars/tree-sitter-scala.wasm +0 -0
- package/grammars/tree-sitter-swift.wasm +0 -0
- package/grammars/tree-sitter-tsx.wasm +0 -0
- package/grammars/tree-sitter-typescript.wasm +0 -0
- package/grammars/tree-sitter-zig.wasm +0 -0
- package/package.json +68 -33
- package/scripts/postinstall.mjs +84 -0
- package/skills/README.md +58 -0
- package/skills/vg/SKILL.md +42 -0
- package/HCS-RUNTIME-SETUP.md +0 -73
- package/LICENSE.md +0 -45
- package/dist/baseline-TJDKYSFL.js +0 -1
- package/dist/chunk-EK7ODJWE.js +0 -1
- package/dist/chunk-GGDB72YE.js +0 -323
- package/dist/chunk-MKDRULJ6.js +0 -1
- package/dist/chunk-NGFYX3CW.js +0 -2
- package/dist/chunk-OQSVJXWJ.js +0 -143
- package/dist/chunk-XTHPCEME.js +0 -2
- package/dist/dist-5D3BKCOR.js +0 -1
- package/dist/fs-PXXYZATK-ZP2RBR47.js +0 -1
- package/dist/hcs-wasm/package.json +0 -3
- package/dist/hcs-wasm/vibgrate_hcs_wasm.js +0 -450
- package/dist/hcs-wasm/vibgrate_hcs_wasm_bg.wasm +0 -0
- package/dist/hcs-worker.js +0 -374406
- package/dist/semver-TPPMM2NV.js +0 -1
|
@@ -0,0 +1,912 @@
|
|
|
1
|
+
import { redactSecrets } from './chunk-RXP66R2E.js';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { createRequire } from 'module';
|
|
6
|
+
import { Language, Parser, Query } from 'web-tree-sitter';
|
|
7
|
+
import { blake3 } from '@noble/hashes/blake3.js';
|
|
8
|
+
import { bytesToHex } from '@noble/hashes/utils.js';
|
|
9
|
+
|
|
10
|
+
// src/engine/languages.ts
|
|
11
|
+
var LANGUAGES = [
|
|
12
|
+
{
|
|
13
|
+
id: "ts",
|
|
14
|
+
label: "TypeScript",
|
|
15
|
+
extensions: [".ts", ".mts", ".cts"],
|
|
16
|
+
grammarFile: "tree-sitter-typescript"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: "tsx",
|
|
20
|
+
label: "TSX",
|
|
21
|
+
extensions: [".tsx"],
|
|
22
|
+
grammarFile: "tree-sitter-tsx"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "js",
|
|
26
|
+
label: "JavaScript",
|
|
27
|
+
extensions: [".js", ".mjs", ".cjs", ".jsx"],
|
|
28
|
+
grammarFile: "tree-sitter-javascript"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "py",
|
|
32
|
+
label: "Python",
|
|
33
|
+
extensions: [".py", ".pyi"],
|
|
34
|
+
grammarFile: "tree-sitter-python"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "go",
|
|
38
|
+
label: "Go",
|
|
39
|
+
extensions: [".go"],
|
|
40
|
+
grammarFile: "tree-sitter-go"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "java",
|
|
44
|
+
label: "Java",
|
|
45
|
+
extensions: [".java"],
|
|
46
|
+
grammarFile: "tree-sitter-java"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: "rust",
|
|
50
|
+
label: "Rust",
|
|
51
|
+
extensions: [".rs"],
|
|
52
|
+
grammarFile: "tree-sitter-rust"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: "cs",
|
|
56
|
+
label: "C#",
|
|
57
|
+
extensions: [".cs"],
|
|
58
|
+
grammarFile: "tree-sitter-c_sharp"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "rb",
|
|
62
|
+
label: "Ruby",
|
|
63
|
+
extensions: [".rb"],
|
|
64
|
+
grammarFile: "tree-sitter-ruby"
|
|
65
|
+
},
|
|
66
|
+
{ id: "php", label: "PHP", extensions: [".php"], grammarFile: "tree-sitter-php" },
|
|
67
|
+
{ id: "kotlin", label: "Kotlin", extensions: [".kt", ".kts"], grammarFile: "tree-sitter-kotlin" },
|
|
68
|
+
{ id: "swift", label: "Swift", extensions: [".swift"], grammarFile: "tree-sitter-swift" },
|
|
69
|
+
{ id: "scala", label: "Scala", extensions: [".scala", ".sc"], grammarFile: "tree-sitter-scala" },
|
|
70
|
+
{ id: "dart", label: "Dart", extensions: [".dart"], grammarFile: "tree-sitter-dart" },
|
|
71
|
+
{ id: "lua", label: "Lua", extensions: [".lua"], grammarFile: "tree-sitter-lua" },
|
|
72
|
+
{ id: "ex", label: "Elixir", extensions: [".ex", ".exs"], grammarFile: "tree-sitter-elixir" },
|
|
73
|
+
// Known limitation: the bundled bash grammar's external scanner throws under
|
|
74
|
+
// web-tree-sitter 0.25.10 on `case`/heredoc constructs. Such files degrade
|
|
75
|
+
// gracefully (per-file empty parse + a surfaced warning, never a build crash);
|
|
76
|
+
// functions in case/heredoc-free scripts extract normally.
|
|
77
|
+
{ id: "sh", label: "Shell", extensions: [".sh", ".bash"], grammarFile: "tree-sitter-bash" },
|
|
78
|
+
{ id: "zig", label: "Zig", extensions: [".zig"], grammarFile: "tree-sitter-zig" },
|
|
79
|
+
{ id: "c", label: "C", extensions: [".c"], grammarFile: "tree-sitter-c" },
|
|
80
|
+
// C++ owns `.h`: the cpp grammar is a superset of C, so C headers parse clean
|
|
81
|
+
// under it, while C++ headers (classes/templates) break the C grammar.
|
|
82
|
+
{
|
|
83
|
+
id: "cpp",
|
|
84
|
+
label: "C++",
|
|
85
|
+
extensions: [".cpp", ".cc", ".cxx", ".hpp", ".hh", ".hxx", ".h"],
|
|
86
|
+
grammarFile: "tree-sitter-cpp"
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
var EXT_TO_LANG = /* @__PURE__ */ new Map();
|
|
90
|
+
for (const lang of LANGUAGES) {
|
|
91
|
+
for (const ext of lang.extensions) EXT_TO_LANG.set(ext, lang);
|
|
92
|
+
}
|
|
93
|
+
var ID_TO_LANG = new Map(LANGUAGES.map((l) => [l.id, l]));
|
|
94
|
+
function langForExtension(ext) {
|
|
95
|
+
return EXT_TO_LANG.get(ext.toLowerCase());
|
|
96
|
+
}
|
|
97
|
+
function langById(id) {
|
|
98
|
+
return ID_TO_LANG.get(id);
|
|
99
|
+
}
|
|
100
|
+
function allLanguageIds() {
|
|
101
|
+
return LANGUAGES.map((l) => l.id);
|
|
102
|
+
}
|
|
103
|
+
var require2 = createRequire(import.meta.url);
|
|
104
|
+
var parserInit = null;
|
|
105
|
+
var languageCache = /* @__PURE__ */ new Map();
|
|
106
|
+
var grammarsOverride;
|
|
107
|
+
function setGrammarsOverride(dir) {
|
|
108
|
+
grammarsOverride = dir ? path.resolve(dir) : void 0;
|
|
109
|
+
}
|
|
110
|
+
function thisDir() {
|
|
111
|
+
return path.dirname(fileURLToPath(import.meta.url));
|
|
112
|
+
}
|
|
113
|
+
var cachedTreeSitterWasmsDir = null;
|
|
114
|
+
function treeSitterWasmsOutDir() {
|
|
115
|
+
if (cachedTreeSitterWasmsDir) return cachedTreeSitterWasmsDir;
|
|
116
|
+
const pkgJson = require2.resolve("tree-sitter-wasms/package.json");
|
|
117
|
+
cachedTreeSitterWasmsDir = path.join(path.dirname(pkgJson), "out");
|
|
118
|
+
return cachedTreeSitterWasmsDir;
|
|
119
|
+
}
|
|
120
|
+
function grammarSetVersion() {
|
|
121
|
+
try {
|
|
122
|
+
const pkgJson = require2.resolve("tree-sitter-wasms/package.json");
|
|
123
|
+
const { version } = JSON.parse(fs.readFileSync(pkgJson, "utf8"));
|
|
124
|
+
return `tree-sitter-wasms@${version}+swift-vendored@0.7.1`;
|
|
125
|
+
} catch {
|
|
126
|
+
return "tree-sitter-wasms@unknown+swift-vendored@0.7.1";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function grammarDirs() {
|
|
130
|
+
const dirs = [];
|
|
131
|
+
if (grammarsOverride) dirs.push(grammarsOverride);
|
|
132
|
+
dirs.push(path.join(thisDir(), "..", "grammars"));
|
|
133
|
+
dirs.push(path.join(thisDir(), "grammars"));
|
|
134
|
+
dirs.push(path.join(thisDir(), "..", "vendor"));
|
|
135
|
+
dirs.push(path.join(thisDir(), "..", "..", "vendor"));
|
|
136
|
+
try {
|
|
137
|
+
dirs.push(treeSitterWasmsOutDir());
|
|
138
|
+
} catch {
|
|
139
|
+
}
|
|
140
|
+
return dirs;
|
|
141
|
+
}
|
|
142
|
+
var isVendorOverlay = (dir) => path.basename(dir) === "vendor";
|
|
143
|
+
function grammarsSourceDir() {
|
|
144
|
+
for (const dir of grammarDirs()) {
|
|
145
|
+
if (isVendorOverlay(dir)) continue;
|
|
146
|
+
if (fs.existsSync(dir) && fs.readdirSync(dir).some((f) => f.endsWith(".wasm"))) return dir;
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
function resolveGrammarFile(grammarFile) {
|
|
151
|
+
const fileName = `${grammarFile}.wasm`;
|
|
152
|
+
for (const dir of grammarDirs()) {
|
|
153
|
+
const candidate = path.join(dir, fileName);
|
|
154
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
155
|
+
}
|
|
156
|
+
throw new Error(
|
|
157
|
+
`grammar "${fileName}" not found. Looked in: ${grammarDirs().join(", ")}. Pass --grammars <dir> pointing at a directory of grammar .wasm files.`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
function resolvedGrammarFiles() {
|
|
161
|
+
return LANGUAGES.map((l) => ({
|
|
162
|
+
fileName: `${l.grammarFile}.wasm`,
|
|
163
|
+
absPath: resolveGrammarFile(l.grammarFile)
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
async function ensureParserInit() {
|
|
167
|
+
if (!parserInit) parserInit = Parser.init();
|
|
168
|
+
await parserInit;
|
|
169
|
+
}
|
|
170
|
+
async function loadLanguage(langId) {
|
|
171
|
+
const cached = languageCache.get(langId);
|
|
172
|
+
if (cached) return cached;
|
|
173
|
+
const def = langById(langId);
|
|
174
|
+
if (!def) throw new Error(`unknown language id "${langId}"`);
|
|
175
|
+
await ensureParserInit();
|
|
176
|
+
const wasmPath = resolveGrammarFile(def.grammarFile);
|
|
177
|
+
const language = await Language.load(fs.readFileSync(wasmPath));
|
|
178
|
+
languageCache.set(langId, language);
|
|
179
|
+
return language;
|
|
180
|
+
}
|
|
181
|
+
async function parserFor(def) {
|
|
182
|
+
const language = await loadLanguage(def.id);
|
|
183
|
+
const parser = new Parser();
|
|
184
|
+
parser.setLanguage(language);
|
|
185
|
+
return parser;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/engine/queries.ts
|
|
189
|
+
var ASSERT_CALLS = [
|
|
190
|
+
'(call_expression function: (identifier) @_g (#match? @_g "^(assert|invariant|require|precondition|invariantViolation)$")) @guard'
|
|
191
|
+
];
|
|
192
|
+
var TS_JS_CALLS = [
|
|
193
|
+
"(call_expression function: (identifier) @callee)",
|
|
194
|
+
"(call_expression function: (member_expression property: (property_identifier) @callee))",
|
|
195
|
+
"(new_expression constructor: (identifier) @callee)"
|
|
196
|
+
];
|
|
197
|
+
var TS_JS_IMPORTS = [
|
|
198
|
+
"(import_statement source: (string) @source)",
|
|
199
|
+
'(call_expression function: (identifier) @_req (#eq? @_req "require") arguments: (arguments (string) @source))'
|
|
200
|
+
];
|
|
201
|
+
var TYPESCRIPT = {
|
|
202
|
+
defs: [
|
|
203
|
+
{ kind: "function", query: "(function_declaration name: (identifier) @name) @def" },
|
|
204
|
+
{
|
|
205
|
+
kind: "function",
|
|
206
|
+
query: "(generator_function_declaration name: (identifier) @name) @def"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
kind: "function",
|
|
210
|
+
query: "(variable_declarator name: (identifier) @name value: [(arrow_function) (function_expression)]) @def"
|
|
211
|
+
},
|
|
212
|
+
{ kind: "method", query: "(method_definition name: (property_identifier) @name) @def" },
|
|
213
|
+
{ kind: "class", query: "(class_declaration name: (type_identifier) @name) @def" },
|
|
214
|
+
{ kind: "class", query: "(abstract_class_declaration name: (type_identifier) @name) @def" },
|
|
215
|
+
{ kind: "interface", query: "(interface_declaration name: (type_identifier) @name) @def" }
|
|
216
|
+
],
|
|
217
|
+
calls: TS_JS_CALLS,
|
|
218
|
+
imports: TS_JS_IMPORTS,
|
|
219
|
+
heritage: [
|
|
220
|
+
"(class_heritage (extends_clause value: (identifier) @extends))",
|
|
221
|
+
"(class_heritage (extends_clause value: (member_expression property: (property_identifier) @extends)))",
|
|
222
|
+
"(class_heritage (implements_clause (type_identifier) @implements))",
|
|
223
|
+
"(extends_type_clause type: (type_identifier) @extends)"
|
|
224
|
+
],
|
|
225
|
+
guards: ASSERT_CALLS
|
|
226
|
+
};
|
|
227
|
+
var JAVASCRIPT = {
|
|
228
|
+
defs: [
|
|
229
|
+
{ kind: "function", query: "(function_declaration name: (identifier) @name) @def" },
|
|
230
|
+
{
|
|
231
|
+
kind: "function",
|
|
232
|
+
query: "(generator_function_declaration name: (identifier) @name) @def"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
kind: "function",
|
|
236
|
+
query: "(variable_declarator name: (identifier) @name value: [(arrow_function) (function_expression)]) @def"
|
|
237
|
+
},
|
|
238
|
+
{ kind: "method", query: "(method_definition name: (property_identifier) @name) @def" },
|
|
239
|
+
{ kind: "class", query: "(class_declaration name: (identifier) @name) @def" }
|
|
240
|
+
],
|
|
241
|
+
calls: TS_JS_CALLS,
|
|
242
|
+
imports: TS_JS_IMPORTS,
|
|
243
|
+
heritage: [
|
|
244
|
+
"(class_heritage (identifier) @extends)",
|
|
245
|
+
"(class_heritage (member_expression property: (property_identifier) @extends))"
|
|
246
|
+
],
|
|
247
|
+
guards: ASSERT_CALLS
|
|
248
|
+
};
|
|
249
|
+
var PYTHON = {
|
|
250
|
+
defs: [
|
|
251
|
+
{ kind: "function", query: "(function_definition name: (identifier) @name) @def" },
|
|
252
|
+
{ kind: "class", query: "(class_definition name: (identifier) @name) @def" }
|
|
253
|
+
],
|
|
254
|
+
calls: [
|
|
255
|
+
"(call function: (identifier) @callee)",
|
|
256
|
+
"(call function: (attribute attribute: (identifier) @callee))"
|
|
257
|
+
],
|
|
258
|
+
imports: [
|
|
259
|
+
"(import_statement name: (dotted_name) @source)",
|
|
260
|
+
"(import_from_statement module_name: (dotted_name) @source)",
|
|
261
|
+
// Relative imports (`from .models import X`, `from ..core.utils import Y`) —
|
|
262
|
+
// the module is a `relative_import` node, not a `dotted_name`. These are the
|
|
263
|
+
// bulk of intra-package edges and were previously dropped entirely.
|
|
264
|
+
"(import_from_statement module_name: (relative_import) @source)"
|
|
265
|
+
],
|
|
266
|
+
heritage: ["(class_definition superclasses: (argument_list (identifier) @extends))"],
|
|
267
|
+
guards: ["(assert_statement) @guard"]
|
|
268
|
+
};
|
|
269
|
+
var GO = {
|
|
270
|
+
defs: [
|
|
271
|
+
{ kind: "function", query: "(function_declaration name: (identifier) @name) @def" },
|
|
272
|
+
{ kind: "method", query: "(method_declaration name: (field_identifier) @name) @def" },
|
|
273
|
+
{ kind: "class", query: "(type_declaration (type_spec name: (type_identifier) @name)) @def" }
|
|
274
|
+
],
|
|
275
|
+
calls: [
|
|
276
|
+
"(call_expression function: (identifier) @callee)",
|
|
277
|
+
"(call_expression function: (selector_expression field: (field_identifier) @callee))"
|
|
278
|
+
],
|
|
279
|
+
imports: ["(import_spec path: (interpreted_string_literal) @source)"],
|
|
280
|
+
heritage: []
|
|
281
|
+
};
|
|
282
|
+
var JAVA = {
|
|
283
|
+
defs: [
|
|
284
|
+
{ kind: "method", query: "(method_declaration name: (identifier) @name) @def" },
|
|
285
|
+
{ kind: "method", query: "(constructor_declaration name: (identifier) @name) @def" },
|
|
286
|
+
{ kind: "class", query: "(class_declaration name: (identifier) @name) @def" },
|
|
287
|
+
{ kind: "interface", query: "(interface_declaration name: (identifier) @name) @def" }
|
|
288
|
+
],
|
|
289
|
+
calls: ["(method_invocation name: (identifier) @callee)", "(object_creation_expression type: (type_identifier) @callee)"],
|
|
290
|
+
imports: ["(import_declaration (scoped_identifier) @source)"],
|
|
291
|
+
heritage: [
|
|
292
|
+
"(superclass (type_identifier) @extends)",
|
|
293
|
+
"(super_interfaces (type_list (type_identifier) @implements))"
|
|
294
|
+
]
|
|
295
|
+
};
|
|
296
|
+
var RUST = {
|
|
297
|
+
defs: [
|
|
298
|
+
{ kind: "function", query: "(function_item name: (identifier) @name) @def" },
|
|
299
|
+
{ kind: "class", query: "(struct_item name: (type_identifier) @name) @def" },
|
|
300
|
+
{ kind: "class", query: "(enum_item name: (type_identifier) @name) @def" },
|
|
301
|
+
{ kind: "interface", query: "(trait_item name: (type_identifier) @name) @def" }
|
|
302
|
+
],
|
|
303
|
+
calls: [
|
|
304
|
+
"(call_expression function: (identifier) @callee)",
|
|
305
|
+
"(call_expression function: (field_expression field: (field_identifier) @callee))",
|
|
306
|
+
"(call_expression function: (scoped_identifier name: (identifier) @callee))"
|
|
307
|
+
],
|
|
308
|
+
imports: ["(use_declaration (scoped_identifier) @source)"],
|
|
309
|
+
heritage: []
|
|
310
|
+
};
|
|
311
|
+
var C_SHARP = {
|
|
312
|
+
defs: [
|
|
313
|
+
{ kind: "method", query: "(method_declaration name: (identifier) @name) @def" },
|
|
314
|
+
{ kind: "class", query: "(class_declaration name: (identifier) @name) @def" },
|
|
315
|
+
{ kind: "interface", query: "(interface_declaration name: (identifier) @name) @def" },
|
|
316
|
+
{ kind: "class", query: "(struct_declaration name: (identifier) @name) @def" }
|
|
317
|
+
],
|
|
318
|
+
calls: ["(invocation_expression function: (member_access_expression name: (identifier) @callee))", "(invocation_expression function: (identifier) @callee)"],
|
|
319
|
+
imports: ["(using_directive (qualified_name) @source)", "(using_directive (identifier) @source)"],
|
|
320
|
+
heritage: ["(base_list (identifier) @extends)"]
|
|
321
|
+
};
|
|
322
|
+
var RUBY = {
|
|
323
|
+
defs: [
|
|
324
|
+
{ kind: "method", query: "(method name: (identifier) @name) @def" },
|
|
325
|
+
{ kind: "class", query: "(class name: (constant) @name) @def" },
|
|
326
|
+
{ kind: "module", query: "(module name: (constant) @name) @def" }
|
|
327
|
+
],
|
|
328
|
+
calls: ["(call method: (identifier) @callee)", "(command method: (identifier) @callee)"],
|
|
329
|
+
imports: [
|
|
330
|
+
'(call method: (identifier) @_m (#match? @_m "require") arguments: (argument_list (string (string_content) @source)))'
|
|
331
|
+
],
|
|
332
|
+
heritage: ["(class (superclass (constant) @extends))"]
|
|
333
|
+
};
|
|
334
|
+
var PHP = {
|
|
335
|
+
defs: [
|
|
336
|
+
{ kind: "function", query: "(function_definition name: (name) @name) @def" },
|
|
337
|
+
{
|
|
338
|
+
kind: "function",
|
|
339
|
+
query: "(assignment_expression left: (variable_name (name) @name) right: [(anonymous_function_creation_expression) (arrow_function)]) @def"
|
|
340
|
+
},
|
|
341
|
+
{ kind: "method", query: "(method_declaration name: (name) @name) @def" },
|
|
342
|
+
{ kind: "class", query: "(class_declaration name: (name) @name) @def" },
|
|
343
|
+
{ kind: "class", query: "(trait_declaration name: (name) @name) @def" },
|
|
344
|
+
{ kind: "interface", query: "(interface_declaration name: (name) @name) @def" }
|
|
345
|
+
],
|
|
346
|
+
calls: [
|
|
347
|
+
"(function_call_expression function: (name) @callee)",
|
|
348
|
+
"(member_call_expression name: (name) @callee)",
|
|
349
|
+
"(nullsafe_member_call_expression name: (name) @callee)",
|
|
350
|
+
"(scoped_call_expression name: (name) @callee)",
|
|
351
|
+
"(object_creation_expression (name) @callee)"
|
|
352
|
+
],
|
|
353
|
+
imports: [
|
|
354
|
+
"(namespace_use_clause (qualified_name) @source)",
|
|
355
|
+
"(namespace_use_clause (name) @source)",
|
|
356
|
+
"[(require_expression (string) @source) (require_once_expression (string) @source) (include_expression (string) @source) (include_once_expression (string) @source)]"
|
|
357
|
+
],
|
|
358
|
+
heritage: ["(base_clause (name) @extends)", "(class_interface_clause (name) @implements)"],
|
|
359
|
+
guards: ['(function_call_expression function: (name) @_g (#eq? @_g "assert")) @guard']
|
|
360
|
+
};
|
|
361
|
+
var KOTLIN = {
|
|
362
|
+
defs: [
|
|
363
|
+
{ kind: "function", query: "(function_declaration (simple_identifier) @name) @def" },
|
|
364
|
+
{ kind: "class", query: '(class_declaration "class" (type_identifier) @name) @def' },
|
|
365
|
+
{ kind: "interface", query: '(class_declaration "interface" (type_identifier) @name) @def' },
|
|
366
|
+
{ kind: "class", query: "(object_declaration (type_identifier) @name) @def" }
|
|
367
|
+
],
|
|
368
|
+
calls: [
|
|
369
|
+
"(call_expression (simple_identifier) @callee)",
|
|
370
|
+
"(call_expression (navigation_expression (navigation_suffix (simple_identifier) @callee)))"
|
|
371
|
+
],
|
|
372
|
+
imports: ["(import_header (identifier) @source)"],
|
|
373
|
+
heritage: [
|
|
374
|
+
"(delegation_specifier (constructor_invocation (user_type (type_identifier) @extends)))",
|
|
375
|
+
"(delegation_specifier (user_type (type_identifier) @implements))"
|
|
376
|
+
],
|
|
377
|
+
guards: ['(call_expression (simple_identifier) @_g (#match? @_g "^(require|check|assert)$")) @guard']
|
|
378
|
+
};
|
|
379
|
+
var SWIFT = {
|
|
380
|
+
defs: [
|
|
381
|
+
{ kind: "function", query: "(function_declaration name: (simple_identifier) @name) @def" },
|
|
382
|
+
{ kind: "method", query: "(protocol_function_declaration name: (simple_identifier) @name) @def" },
|
|
383
|
+
{ kind: "class", query: "(class_declaration name: (type_identifier) @name) @def" },
|
|
384
|
+
{ kind: "class", query: "(class_declaration name: (user_type (type_identifier) @name)) @def" },
|
|
385
|
+
{ kind: "interface", query: "(protocol_declaration name: (type_identifier) @name) @def" }
|
|
386
|
+
],
|
|
387
|
+
calls: [
|
|
388
|
+
"(call_expression (simple_identifier) @callee)",
|
|
389
|
+
"(call_expression (navigation_expression suffix: (navigation_suffix suffix: (simple_identifier) @callee)))"
|
|
390
|
+
],
|
|
391
|
+
imports: ["(import_declaration (identifier) @source)"],
|
|
392
|
+
heritage: ["(inheritance_specifier inherits_from: (user_type (type_identifier) @extends))"],
|
|
393
|
+
guards: [
|
|
394
|
+
'(call_expression (simple_identifier) @_g (#match? @_g "^(assert|precondition|assertionFailure|preconditionFailure)$")) @guard'
|
|
395
|
+
]
|
|
396
|
+
};
|
|
397
|
+
var SCALA = {
|
|
398
|
+
defs: [
|
|
399
|
+
{ kind: "function", query: "(function_definition name: (identifier) @name) @def" },
|
|
400
|
+
{ kind: "method", query: "(function_declaration name: (identifier) @name) @def" },
|
|
401
|
+
{ kind: "class", query: "(class_definition name: (identifier) @name) @def" },
|
|
402
|
+
{ kind: "interface", query: "(trait_definition name: (identifier) @name) @def" },
|
|
403
|
+
{ kind: "module", query: "(object_definition name: (identifier) @name) @def" }
|
|
404
|
+
],
|
|
405
|
+
calls: [
|
|
406
|
+
"(call_expression function: (identifier) @callee)",
|
|
407
|
+
"(call_expression function: (field_expression field: (identifier) @callee))"
|
|
408
|
+
],
|
|
409
|
+
imports: [
|
|
410
|
+
"(import_declaration path: (stable_identifier) @source)",
|
|
411
|
+
"(import_declaration path: (identifier) @source)"
|
|
412
|
+
],
|
|
413
|
+
heritage: [
|
|
414
|
+
"(extends_clause type: (type_identifier) @extends)",
|
|
415
|
+
"(extends_clause type: (generic_type type: (type_identifier) @extends))",
|
|
416
|
+
"(extends_clause type: (compound_type base: (type_identifier) @extends))",
|
|
417
|
+
"(extends_clause type: (compound_type extra: (type_identifier) @implements))"
|
|
418
|
+
],
|
|
419
|
+
guards: ['(call_expression function: (identifier) @_g (#match? @_g "^(require|assert|assume)$")) @guard']
|
|
420
|
+
};
|
|
421
|
+
var DART = {
|
|
422
|
+
defs: [
|
|
423
|
+
{ kind: "function", query: "(function_signature name: (identifier) @name) @def" },
|
|
424
|
+
{ kind: "method", query: "(constructor_signature name: (identifier) @name) @def" },
|
|
425
|
+
{ kind: "class", query: "(class_definition name: (identifier) @name) @def" },
|
|
426
|
+
{ kind: "class", query: "(mixin_declaration (identifier) @name) @def" }
|
|
427
|
+
],
|
|
428
|
+
calls: [
|
|
429
|
+
"(_ (identifier) @callee . (selector (argument_part)))",
|
|
430
|
+
"(_ (selector (unconditional_assignable_selector (identifier) @callee)) . (selector (argument_part)))",
|
|
431
|
+
"(_ (selector (conditional_assignable_selector (identifier) @callee)) . (selector (argument_part)))",
|
|
432
|
+
"(cascade_section (cascade_selector (identifier) @callee) . (argument_part))"
|
|
433
|
+
],
|
|
434
|
+
imports: ["(import_specification (configurable_uri (uri (string_literal) @source)))"],
|
|
435
|
+
heritage: [
|
|
436
|
+
"(superclass (type_identifier) @extends)",
|
|
437
|
+
"(interfaces (type_identifier) @implements)",
|
|
438
|
+
"(mixins (type_identifier) @implements)"
|
|
439
|
+
],
|
|
440
|
+
guards: ["(assert_statement) @guard"]
|
|
441
|
+
};
|
|
442
|
+
var LUA = {
|
|
443
|
+
defs: [
|
|
444
|
+
{ kind: "function", query: "(function_definition_statement name: (identifier) @name) @def" },
|
|
445
|
+
{ kind: "function", query: "(function_definition_statement name: (variable field: (identifier) @name)) @def" },
|
|
446
|
+
{ kind: "method", query: "(function_definition_statement name: (variable method: (identifier) @name)) @def" },
|
|
447
|
+
{ kind: "function", query: "(local_function_definition_statement name: (identifier) @name) @def" },
|
|
448
|
+
{
|
|
449
|
+
kind: "function",
|
|
450
|
+
query: "(variable_assignment (variable_list (variable field: (identifier) @name)) (expression_list value: (function_definition))) @def"
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
kind: "function",
|
|
454
|
+
query: "(local_variable_declaration (variable_list (variable name: (identifier) @name)) (expression_list value: (function_definition))) @def"
|
|
455
|
+
}
|
|
456
|
+
],
|
|
457
|
+
calls: [
|
|
458
|
+
"(call function: (variable name: (identifier) @callee))",
|
|
459
|
+
"(call function: (variable field: (identifier) @callee))",
|
|
460
|
+
"(call function: (variable method: (identifier) @callee))"
|
|
461
|
+
],
|
|
462
|
+
imports: [
|
|
463
|
+
'(call function: (variable name: (identifier) @_r (#eq? @_r "require")) arguments: (argument_list (expression_list (string) @source)))'
|
|
464
|
+
],
|
|
465
|
+
heritage: [],
|
|
466
|
+
guards: ['(call function: (variable name: (identifier) @_g (#eq? @_g "assert"))) @guard']
|
|
467
|
+
};
|
|
468
|
+
var ELIXIR = {
|
|
469
|
+
defs: [
|
|
470
|
+
{ kind: "module", query: '(call target: (identifier) @_kw (#eq? @_kw "defmodule") (arguments (alias) @name)) @def' },
|
|
471
|
+
{
|
|
472
|
+
kind: "function",
|
|
473
|
+
query: '(call target: (identifier) @_kw (#match? @_kw "^(def|defp|defmacro|defmacrop|defguard|defguardp)$") (arguments (call target: (identifier) @name))) @def'
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
kind: "function",
|
|
477
|
+
query: '(call target: (identifier) @_kw (#match? @_kw "^(def|defp|defmacro|defmacrop)$") (arguments (identifier) @name)) @def'
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
kind: "function",
|
|
481
|
+
query: '(call target: (identifier) @_kw (#match? @_kw "^(def|defp|defmacro|defmacrop|defguard|defguardp)$") (arguments (binary_operator left: (call target: (identifier) @name)))) @def'
|
|
482
|
+
}
|
|
483
|
+
],
|
|
484
|
+
calls: [
|
|
485
|
+
"(call target: (dot right: (identifier) @callee))",
|
|
486
|
+
'(call target: (identifier) @callee (#not-match? @callee "^(def|defp|defmacro|defmacrop|defmodule|defstruct|defprotocol|defimpl|defguard|defguardp|defdelegate|defexception|defoverridable|alias|import|require|use|quote|unquote|moduledoc|doc|spec|type|typep|typedoc|opaque|behaviour|impl|derive|enforce_keys|callback|macrocallback|optional_callbacks|compile|deprecated|dialyzer|external_resource|on_definition|on_load|after_compile|before_compile)$"))'
|
|
487
|
+
],
|
|
488
|
+
imports: [
|
|
489
|
+
'(call target: (identifier) @_kw (#match? @_kw "^(alias|import|require|use)$") (arguments (alias) @source))',
|
|
490
|
+
'(call target: (identifier) @_kw (#match? @_kw "^(alias|import|require|use)$") (arguments (dot left: (alias) @source)))'
|
|
491
|
+
],
|
|
492
|
+
heritage: []
|
|
493
|
+
};
|
|
494
|
+
var BASH = {
|
|
495
|
+
defs: [{ kind: "function", query: "(function_definition name: (word) @name) @def" }],
|
|
496
|
+
calls: ["(command name: (command_name (word) @callee))"],
|
|
497
|
+
imports: [
|
|
498
|
+
'(command name: (command_name (word) @_c (#match? @_c "^(source|\\.)$")) argument: [(word) (string) (raw_string) (concatenation)] @source)'
|
|
499
|
+
],
|
|
500
|
+
heritage: []
|
|
501
|
+
};
|
|
502
|
+
var ZIG = {
|
|
503
|
+
defs: [
|
|
504
|
+
{ kind: "function", query: "(function_declaration name: (identifier) @name) @def" },
|
|
505
|
+
{ kind: "class", query: "(variable_declaration (identifier) @name (struct_declaration)) @def" },
|
|
506
|
+
{ kind: "class", query: "(variable_declaration (identifier) @name (enum_declaration)) @def" },
|
|
507
|
+
{ kind: "class", query: "(variable_declaration (identifier) @name (union_declaration)) @def" }
|
|
508
|
+
],
|
|
509
|
+
calls: [
|
|
510
|
+
"(call_expression function: (identifier) @callee)",
|
|
511
|
+
"(call_expression function: (field_expression member: (identifier) @callee))"
|
|
512
|
+
],
|
|
513
|
+
imports: ['(builtin_function (builtin_identifier) @_i (#eq? @_i "@import") (arguments (string) @source))'],
|
|
514
|
+
heritage: [],
|
|
515
|
+
guards: ['(call_expression function: (field_expression member: (identifier) @_g (#eq? @_g "assert"))) @guard']
|
|
516
|
+
};
|
|
517
|
+
var C_LANG = {
|
|
518
|
+
defs: [
|
|
519
|
+
{
|
|
520
|
+
kind: "function",
|
|
521
|
+
query: "(function_definition declarator: [(function_declarator declarator: (identifier) @name) (pointer_declarator declarator: (function_declarator declarator: (identifier) @name))]) @def"
|
|
522
|
+
},
|
|
523
|
+
{ kind: "class", query: "(struct_specifier name: (type_identifier) @name body: (field_declaration_list)) @def" },
|
|
524
|
+
{ kind: "class", query: "(enum_specifier name: (type_identifier) @name body: (enumerator_list)) @def" },
|
|
525
|
+
{ kind: "class", query: "(type_definition declarator: (type_identifier) @name) @def" }
|
|
526
|
+
],
|
|
527
|
+
calls: [
|
|
528
|
+
"(call_expression function: (identifier) @callee)",
|
|
529
|
+
"(call_expression function: (field_expression field: (field_identifier) @callee))"
|
|
530
|
+
],
|
|
531
|
+
imports: ["(preproc_include path: (string_literal) @source)", "(preproc_include path: (system_lib_string) @source)"],
|
|
532
|
+
heritage: [],
|
|
533
|
+
guards: ['(call_expression function: (identifier) @_g (#match? @_g "^(assert|static_assert)$")) @guard']
|
|
534
|
+
};
|
|
535
|
+
var CPP = {
|
|
536
|
+
defs: [
|
|
537
|
+
{
|
|
538
|
+
kind: "function",
|
|
539
|
+
query: "(function_definition declarator: [(function_declarator declarator: (identifier) @name) (pointer_declarator declarator: (function_declarator declarator: (identifier) @name)) (reference_declarator (function_declarator declarator: (identifier) @name))]) @def"
|
|
540
|
+
},
|
|
541
|
+
{ kind: "method", query: "(function_definition declarator: (function_declarator declarator: (field_identifier) @name)) @def" },
|
|
542
|
+
{
|
|
543
|
+
kind: "method",
|
|
544
|
+
query: "(function_definition declarator: [(function_declarator declarator: (qualified_identifier name: (identifier) @name)) (pointer_declarator declarator: (function_declarator declarator: (qualified_identifier name: (identifier) @name))) (reference_declarator (function_declarator declarator: (qualified_identifier name: (identifier) @name)))]) @def"
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
kind: "method",
|
|
548
|
+
query: "(function_definition declarator: (function_declarator declarator: (qualified_identifier name: (qualified_identifier name: (identifier) @name)))) @def"
|
|
549
|
+
},
|
|
550
|
+
{ kind: "class", query: "(class_specifier name: (type_identifier) @name body: (field_declaration_list)) @def" },
|
|
551
|
+
{ kind: "class", query: "(struct_specifier name: (type_identifier) @name body: (field_declaration_list)) @def" },
|
|
552
|
+
{ kind: "module", query: "(namespace_definition name: (namespace_identifier) @name) @def" }
|
|
553
|
+
],
|
|
554
|
+
calls: [
|
|
555
|
+
"(call_expression function: (identifier) @callee)",
|
|
556
|
+
"(call_expression function: (field_expression field: (field_identifier) @callee))",
|
|
557
|
+
"(call_expression function: (qualified_identifier name: (identifier) @callee))",
|
|
558
|
+
"(call_expression function: (qualified_identifier name: (qualified_identifier name: (identifier) @callee)))",
|
|
559
|
+
"(new_expression type: (type_identifier) @callee)"
|
|
560
|
+
],
|
|
561
|
+
imports: ["(preproc_include path: (string_literal) @source)", "(preproc_include path: (system_lib_string) @source)"],
|
|
562
|
+
heritage: [
|
|
563
|
+
"(base_class_clause (type_identifier) @extends)",
|
|
564
|
+
"(base_class_clause (qualified_identifier name: (type_identifier) @extends))"
|
|
565
|
+
],
|
|
566
|
+
guards: ['(call_expression function: (identifier) @_g (#match? @_g "^(assert|static_assert)$")) @guard']
|
|
567
|
+
};
|
|
568
|
+
var BY_LANG = {
|
|
569
|
+
ts: TYPESCRIPT,
|
|
570
|
+
tsx: TYPESCRIPT,
|
|
571
|
+
js: JAVASCRIPT,
|
|
572
|
+
py: PYTHON,
|
|
573
|
+
go: GO,
|
|
574
|
+
java: JAVA,
|
|
575
|
+
rust: RUST,
|
|
576
|
+
cs: C_SHARP,
|
|
577
|
+
rb: RUBY,
|
|
578
|
+
php: PHP,
|
|
579
|
+
kotlin: KOTLIN,
|
|
580
|
+
swift: SWIFT,
|
|
581
|
+
scala: SCALA,
|
|
582
|
+
dart: DART,
|
|
583
|
+
lua: LUA,
|
|
584
|
+
ex: ELIXIR,
|
|
585
|
+
sh: BASH,
|
|
586
|
+
zig: ZIG,
|
|
587
|
+
c: C_LANG,
|
|
588
|
+
cpp: CPP
|
|
589
|
+
};
|
|
590
|
+
function queriesFor(langId) {
|
|
591
|
+
return BY_LANG[langId];
|
|
592
|
+
}
|
|
593
|
+
var encoder = new TextEncoder();
|
|
594
|
+
function hashString(input) {
|
|
595
|
+
return bytesToHex(blake3(encoder.encode(input)));
|
|
596
|
+
}
|
|
597
|
+
function hashBytes(input) {
|
|
598
|
+
return bytesToHex(blake3(input));
|
|
599
|
+
}
|
|
600
|
+
function shortId(input) {
|
|
601
|
+
return bytesToHex(blake3(encoder.encode(input), { dkLen: 16 }));
|
|
602
|
+
}
|
|
603
|
+
function canonicalize(value) {
|
|
604
|
+
return JSON.stringify(sortKeys(value));
|
|
605
|
+
}
|
|
606
|
+
function sortKeys(value) {
|
|
607
|
+
if (Array.isArray(value)) return value.map(sortKeys);
|
|
608
|
+
if (value && typeof value === "object") {
|
|
609
|
+
const out = {};
|
|
610
|
+
for (const key of Object.keys(value).sort()) {
|
|
611
|
+
out[key] = sortKeys(value[key]);
|
|
612
|
+
}
|
|
613
|
+
return out;
|
|
614
|
+
}
|
|
615
|
+
return value;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// src/engine/parse.ts
|
|
619
|
+
var compiledCache = /* @__PURE__ */ new Map();
|
|
620
|
+
function compile(lang, langId, source) {
|
|
621
|
+
const key = `${langId}::${source}`;
|
|
622
|
+
if (compiledCache.has(key)) return compiledCache.get(key) ?? null;
|
|
623
|
+
let q = null;
|
|
624
|
+
try {
|
|
625
|
+
q = new Query(lang, source);
|
|
626
|
+
} catch {
|
|
627
|
+
q = null;
|
|
628
|
+
}
|
|
629
|
+
compiledCache.set(key, q);
|
|
630
|
+
return q;
|
|
631
|
+
}
|
|
632
|
+
function namedCapture(captures, name) {
|
|
633
|
+
return captures.find((c) => c.name === name)?.node;
|
|
634
|
+
}
|
|
635
|
+
var MEMBER_PARENT_TYPES = /* @__PURE__ */ new Set([
|
|
636
|
+
"member_expression",
|
|
637
|
+
// ts/js: obj.foo()
|
|
638
|
+
"attribute",
|
|
639
|
+
// python: obj.foo()
|
|
640
|
+
"selector_expression",
|
|
641
|
+
// go: pkg.Foo()
|
|
642
|
+
"field_expression",
|
|
643
|
+
// rust/scala/c/cpp/zig: recv.foo()
|
|
644
|
+
"scoped_identifier",
|
|
645
|
+
// rust: Type::foo()
|
|
646
|
+
"member_access_expression",
|
|
647
|
+
// c#: obj.Foo()
|
|
648
|
+
"qualified_identifier",
|
|
649
|
+
// c++: ns::f(), Type::m()
|
|
650
|
+
"dot",
|
|
651
|
+
// elixir: Mod.fun()
|
|
652
|
+
"navigation_suffix",
|
|
653
|
+
// kotlin/swift: recv.foo()
|
|
654
|
+
"member_call_expression",
|
|
655
|
+
// php: $x->m()
|
|
656
|
+
"nullsafe_member_call_expression",
|
|
657
|
+
// php: $x?->m()
|
|
658
|
+
"scoped_call_expression",
|
|
659
|
+
// php: X::m()
|
|
660
|
+
"unconditional_assignable_selector",
|
|
661
|
+
// dart: x.foo()
|
|
662
|
+
"conditional_assignable_selector",
|
|
663
|
+
// dart: x?.foo()
|
|
664
|
+
"cascade_selector"
|
|
665
|
+
// dart: x..foo()
|
|
666
|
+
]);
|
|
667
|
+
function isQualifiedCallee(node) {
|
|
668
|
+
const parent = node.parent;
|
|
669
|
+
if (!parent) return false;
|
|
670
|
+
if (MEMBER_PARENT_TYPES.has(parent.type)) return true;
|
|
671
|
+
if (parent.type === "method_invocation") return parent.childForFieldName("object") != null;
|
|
672
|
+
if (parent.type === "call") return parent.childForFieldName("receiver") != null;
|
|
673
|
+
if (parent.type === "variable") return parent.childForFieldName("table") != null;
|
|
674
|
+
return false;
|
|
675
|
+
}
|
|
676
|
+
function signatureOf(source, def, langId) {
|
|
677
|
+
const full = source.slice(def.startIndex, def.endIndex);
|
|
678
|
+
let head;
|
|
679
|
+
if (langId === "py") head = pythonHeader(full);
|
|
680
|
+
else if (langId === "rb" || langId === "ex") head = full.split("\n")[0];
|
|
681
|
+
else {
|
|
682
|
+
const braceIdx = full.indexOf("{");
|
|
683
|
+
head = braceIdx >= 0 ? full.slice(0, braceIdx) : full.split("\n")[0];
|
|
684
|
+
}
|
|
685
|
+
head = head.replace(/\s+/g, " ").trim().replace(/[:{]\s*$/, "").trim();
|
|
686
|
+
return head.length > 200 ? `${head.slice(0, 197)}...` : head;
|
|
687
|
+
}
|
|
688
|
+
function scrubbedDoc(source, def, langId) {
|
|
689
|
+
const doc = docOf(source, def, langId);
|
|
690
|
+
return doc === void 0 ? void 0 : redactSecrets(doc);
|
|
691
|
+
}
|
|
692
|
+
function docOf(source, def, langId) {
|
|
693
|
+
const lines = source.split("\n");
|
|
694
|
+
if (langId === "py") return pythonDocstring(lines, def.startPosition.row);
|
|
695
|
+
return leadingComment(lines, def.startPosition.row);
|
|
696
|
+
}
|
|
697
|
+
function leadingComment(lines, row) {
|
|
698
|
+
const collected = [];
|
|
699
|
+
for (let r = row - 1; r >= 0; r--) {
|
|
700
|
+
const line = lines[r].trim();
|
|
701
|
+
if (line === "") break;
|
|
702
|
+
if (/^(\/\/|\/\*\*?|\*\/?|#|;|--)/.test(line)) collected.unshift(line);
|
|
703
|
+
else break;
|
|
704
|
+
}
|
|
705
|
+
if (!collected.length) return void 0;
|
|
706
|
+
const text = collected.join("\n").replace(/\/\*\*?|\*\//g, " ").replace(/^\s*[*]\s?/gm, " ").replace(/^\s*(\/\/+|#+|;+|--)\s?/gm, " ").replace(/@\w+/g, " ");
|
|
707
|
+
return clip(text);
|
|
708
|
+
}
|
|
709
|
+
function pythonDocstring(lines, row) {
|
|
710
|
+
let r = row;
|
|
711
|
+
while (r < lines.length && !/:\s*(#.*)?$/.test(lines[r])) r++;
|
|
712
|
+
let j = r + 1;
|
|
713
|
+
while (j < lines.length && lines[j].trim() === "") j++;
|
|
714
|
+
const first = lines[j]?.trim() ?? "";
|
|
715
|
+
const m = /^[rubfRUBF]{0,2}("""|''')/.exec(first);
|
|
716
|
+
if (!m) return void 0;
|
|
717
|
+
const q = m[1];
|
|
718
|
+
let rest = first.slice(first.indexOf(q) + 3);
|
|
719
|
+
if (rest.includes(q)) return clip(rest.slice(0, rest.indexOf(q)));
|
|
720
|
+
const parts = [rest];
|
|
721
|
+
for (let k = j + 1; k < lines.length; k++) {
|
|
722
|
+
const idx = lines[k].indexOf(q);
|
|
723
|
+
if (idx >= 0) {
|
|
724
|
+
parts.push(lines[k].slice(0, idx));
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
parts.push(lines[k]);
|
|
728
|
+
}
|
|
729
|
+
return clip(parts.join(" "));
|
|
730
|
+
}
|
|
731
|
+
function clip(s) {
|
|
732
|
+
const t = s.replace(/\s+/g, " ").trim();
|
|
733
|
+
if (!t) return void 0;
|
|
734
|
+
return t.length > 200 ? `${t.slice(0, 197)}...` : t;
|
|
735
|
+
}
|
|
736
|
+
function pythonHeader(full) {
|
|
737
|
+
let depth = 0;
|
|
738
|
+
for (let i = 0; i < full.length; i++) {
|
|
739
|
+
const c = full[i];
|
|
740
|
+
if (c === "(" || c === "[" || c === "{") depth++;
|
|
741
|
+
else if (c === ")" || c === "]" || c === "}") depth--;
|
|
742
|
+
else if (c === ":" && depth === 0) return full.slice(0, i);
|
|
743
|
+
}
|
|
744
|
+
return full.split("\n")[0];
|
|
745
|
+
}
|
|
746
|
+
async function parseSource(rel, langId, source) {
|
|
747
|
+
const def = langById(langId);
|
|
748
|
+
const langQueries = queriesFor(langId);
|
|
749
|
+
const hash = hashString(source);
|
|
750
|
+
const result = {
|
|
751
|
+
rel,
|
|
752
|
+
lang: langId,
|
|
753
|
+
hash,
|
|
754
|
+
bytes: Buffer.byteLength(source, "utf8"),
|
|
755
|
+
defs: [],
|
|
756
|
+
calls: [],
|
|
757
|
+
imports: [],
|
|
758
|
+
heritage: [],
|
|
759
|
+
guards: []
|
|
760
|
+
};
|
|
761
|
+
if (!def || !langQueries) return result;
|
|
762
|
+
const language = await loadLanguage(langId);
|
|
763
|
+
const parser = await parserFor(def);
|
|
764
|
+
const tree = parser.parse(source);
|
|
765
|
+
if (!tree) return result;
|
|
766
|
+
const root = tree.rootNode;
|
|
767
|
+
const rawDefs = [];
|
|
768
|
+
for (const rule of langQueries.defs) {
|
|
769
|
+
collectDefs(language, langId, source, root, rule, rawDefs);
|
|
770
|
+
}
|
|
771
|
+
const seen = /* @__PURE__ */ new Set();
|
|
772
|
+
const deduped = rawDefs.filter((d) => {
|
|
773
|
+
const key = `${d._start}:${d._end}:${d.name}:${d.kind}`;
|
|
774
|
+
if (seen.has(key)) return false;
|
|
775
|
+
seen.add(key);
|
|
776
|
+
return true;
|
|
777
|
+
});
|
|
778
|
+
const byStart = [...deduped].sort((a, b) => a._start - b._start || b._end - a._end);
|
|
779
|
+
for (const d of byStart) {
|
|
780
|
+
const parent = enclosing(byStart, d._start, d._end);
|
|
781
|
+
d.qualifiedName = parent ? `${parent.qualifiedName}.${d.name}` : d.name;
|
|
782
|
+
}
|
|
783
|
+
result.defs = byStart.map((d) => {
|
|
784
|
+
const { _start, _end, ...rest } = d;
|
|
785
|
+
return rest;
|
|
786
|
+
}).sort(
|
|
787
|
+
(a, b) => a.startLine - b.startLine || a.qualifiedName.localeCompare(b.qualifiedName) || a.name.localeCompare(b.name)
|
|
788
|
+
);
|
|
789
|
+
const defNameBytes = /* @__PURE__ */ new Set();
|
|
790
|
+
for (const qsrc of langQueries.defs) {
|
|
791
|
+
const q = compile(language, langId, qsrc.query);
|
|
792
|
+
if (!q) continue;
|
|
793
|
+
for (const m of q.matches(root)) {
|
|
794
|
+
const nameNode = namedCapture(m.captures, "name");
|
|
795
|
+
if (nameNode) defNameBytes.add(nameNode.startIndex);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
const calls = [];
|
|
799
|
+
for (const qsrc of langQueries.calls) {
|
|
800
|
+
const q = compile(language, langId, qsrc);
|
|
801
|
+
if (!q) continue;
|
|
802
|
+
for (const cap of q.captures(root)) {
|
|
803
|
+
if (cap.name !== "callee") continue;
|
|
804
|
+
if (defNameBytes.has(cap.node.startIndex)) continue;
|
|
805
|
+
calls.push({
|
|
806
|
+
callee: cap.node.text,
|
|
807
|
+
byte: cap.node.startIndex,
|
|
808
|
+
line: cap.node.startPosition.row + 1,
|
|
809
|
+
qualified: isQualifiedCallee(cap.node)
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
result.calls = calls.sort((a, b) => a.byte - b.byte || a.callee.localeCompare(b.callee));
|
|
814
|
+
const imports = [];
|
|
815
|
+
for (const qsrc of langQueries.imports) {
|
|
816
|
+
const q = compile(language, langId, qsrc);
|
|
817
|
+
if (!q) continue;
|
|
818
|
+
for (const cap of q.captures(root)) {
|
|
819
|
+
if (cap.name !== "source") continue;
|
|
820
|
+
imports.push({ source: stripQuotes(cap.node.text) });
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
result.imports = dedupeImports(imports);
|
|
824
|
+
const heritage = [];
|
|
825
|
+
for (const qsrc of langQueries.heritage) {
|
|
826
|
+
const q = compile(language, langId, qsrc);
|
|
827
|
+
if (!q) continue;
|
|
828
|
+
for (const cap of q.captures(root)) {
|
|
829
|
+
if (cap.name !== "extends" && cap.name !== "implements") continue;
|
|
830
|
+
heritage.push({ superName: cap.node.text, byte: cap.node.startIndex, kind: cap.name });
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
result.heritage = heritage.sort(
|
|
834
|
+
(a, b) => a.byte - b.byte || a.kind.localeCompare(b.kind) || a.superName.localeCompare(b.superName)
|
|
835
|
+
);
|
|
836
|
+
const guards = [];
|
|
837
|
+
for (const qsrc of langQueries.guards ?? []) {
|
|
838
|
+
const q = compile(language, langId, qsrc);
|
|
839
|
+
if (!q) continue;
|
|
840
|
+
for (const cap of q.captures(root)) {
|
|
841
|
+
if (cap.name !== "guard") continue;
|
|
842
|
+
const expr = cap.node.text.replace(/\s+/g, " ").trim();
|
|
843
|
+
guards.push({ expr: expr.length > 160 ? `${expr.slice(0, 157)}...` : expr, line: cap.node.startPosition.row + 1 });
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
result.guards = guards.sort((a, b) => a.line - b.line || a.expr.localeCompare(b.expr));
|
|
847
|
+
tree.delete();
|
|
848
|
+
return result;
|
|
849
|
+
}
|
|
850
|
+
function dartBodyOf(defNode) {
|
|
851
|
+
if (!defNode.type.endsWith("_signature")) return null;
|
|
852
|
+
if (defNode.nextNamedSibling?.type === "function_body") return defNode.nextNamedSibling;
|
|
853
|
+
const wrapper = defNode.parent;
|
|
854
|
+
if (wrapper?.type === "method_signature" && wrapper.nextNamedSibling?.type === "function_body") {
|
|
855
|
+
return wrapper.nextNamedSibling;
|
|
856
|
+
}
|
|
857
|
+
return null;
|
|
858
|
+
}
|
|
859
|
+
function collectDefs(language, langId, source, root, rule, out) {
|
|
860
|
+
const q = compile(language, langId, rule.query);
|
|
861
|
+
if (!q) return;
|
|
862
|
+
for (const match of q.matches(root)) {
|
|
863
|
+
const defNode = namedCapture(match.captures, "def");
|
|
864
|
+
const nameNode = namedCapture(match.captures, "name");
|
|
865
|
+
if (!defNode || !nameNode) continue;
|
|
866
|
+
const spanEnd = dartBodyOf(defNode) ?? defNode;
|
|
867
|
+
out.push({
|
|
868
|
+
kind: rule.kind,
|
|
869
|
+
name: nameNode.text,
|
|
870
|
+
qualifiedName: nameNode.text,
|
|
871
|
+
// refined after nesting is computed
|
|
872
|
+
startLine: defNode.startPosition.row + 1,
|
|
873
|
+
endLine: spanEnd.endPosition.row + 1,
|
|
874
|
+
startByte: defNode.startIndex,
|
|
875
|
+
endByte: spanEnd.endIndex,
|
|
876
|
+
signature: rule.kind === "function" || rule.kind === "method" ? redactSecrets(signatureOf(source, defNode, langId)) : void 0,
|
|
877
|
+
// GUARDRAILS §1: signatures/docs are lifted verbatim from source and are
|
|
878
|
+
// persisted (graph.json, `vg share` commits it) — scrub at ingest.
|
|
879
|
+
doc: scrubbedDoc(source, defNode, langId),
|
|
880
|
+
visibility: void 0,
|
|
881
|
+
_start: defNode.startIndex,
|
|
882
|
+
_end: spanEnd.endIndex
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
function enclosing(defs, start, end) {
|
|
887
|
+
let best;
|
|
888
|
+
for (const d of defs) {
|
|
889
|
+
if (d._start === start && d._end === end) continue;
|
|
890
|
+
if (d._start <= start && d._end >= end) {
|
|
891
|
+
if (!best || d._end - d._start < best._end - best._start) best = d;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
return best;
|
|
895
|
+
}
|
|
896
|
+
function stripQuotes(text) {
|
|
897
|
+
return text.replace(/^['"`]|['"`]$/g, "");
|
|
898
|
+
}
|
|
899
|
+
function dedupeImports(imports) {
|
|
900
|
+
const seen = /* @__PURE__ */ new Set();
|
|
901
|
+
const out = [];
|
|
902
|
+
for (const i of imports.sort((a, b) => a.source.localeCompare(b.source))) {
|
|
903
|
+
if (seen.has(i.source)) continue;
|
|
904
|
+
seen.add(i.source);
|
|
905
|
+
out.push(i);
|
|
906
|
+
}
|
|
907
|
+
return out;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
export { LANGUAGES, allLanguageIds, canonicalize, grammarSetVersion, grammarsSourceDir, hashBytes, hashString, langById, langForExtension, parseSource, resolvedGrammarFiles, setGrammarsOverride, shortId };
|
|
911
|
+
//# sourceMappingURL=chunk-X5YT263H.js.map
|
|
912
|
+
//# sourceMappingURL=chunk-X5YT263H.js.map
|