@danielblomma/cortex-mcp 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -14
- package/package.json +2 -2
- package/scaffold/mcp/package-lock.json +3 -7
- package/scaffold/mcp/package.json +1 -1
- package/scaffold/scripts/dashboard.mjs +15 -1
- package/scaffold/scripts/doctor.sh +64 -10
- package/scaffold/scripts/ingest.mjs +323 -50
- package/scaffold/scripts/parsers/bash-treesitter.mjs +229 -0
- package/scaffold/scripts/parsers/cpp-dispatch.mjs +56 -0
- package/scaffold/scripts/parsers/cpp-treesitter.mjs +333 -0
- package/scaffold/scripts/parsers/csharp.mjs +197 -10
- package/scaffold/scripts/parsers/dotnet/CSharpParser/CSharpParser.csproj +1 -0
- package/scaffold/scripts/parsers/dotnet/CSharpParser/Program.cs +126 -21
- package/scaffold/scripts/parsers/go-treesitter.mjs +283 -0
- package/scaffold/scripts/parsers/java-treesitter.mjs +250 -0
- package/scaffold/scripts/parsers/javascript/ast.mjs +118 -12
- package/scaffold/scripts/parsers/javascript/chunks.mjs +4 -0
- package/scaffold/scripts/parsers/javascript/patterns.mjs +6 -0
- package/scaffold/scripts/parsers/javascript.mjs +4 -19
- package/scaffold/scripts/parsers/node_modules/.package-lock.json +57 -0
- package/scaffold/scripts/parsers/node_modules/acorn/CHANGELOG.md +972 -0
- package/scaffold/scripts/parsers/node_modules/acorn/LICENSE +21 -0
- package/scaffold/scripts/parsers/node_modules/acorn/README.md +301 -0
- package/scaffold/scripts/parsers/node_modules/acorn/bin/acorn +4 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.d.mts +883 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.d.ts +883 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.js +6295 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.mjs +6266 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/bin.js +90 -0
- package/scaffold/scripts/parsers/node_modules/acorn/package.json +50 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/CHANGELOG.md +421 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/LICENSE +21 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/README.md +81 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/error.d.ts +103 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/error.js +78 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/error.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/decorators.d.ts +167 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/decorators.js +75 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/decorators.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/import-assertions.d.ts +177 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/import-assertions.js +56 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/import-assertions.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/index.d.ts +198 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/index.js +327 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/index.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/xhtml.d.ts +256 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/xhtml.js +256 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/xhtml.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.d.ts +472 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.js +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.mjs +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/middleware.d.ts +159 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/middleware.js +2 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/middleware.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/parseutil.d.ts +10 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/parseutil.js +38 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/parseutil.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/scopeflags.d.ts +12 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/scopeflags.js +29 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/scopeflags.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/tokenType.d.ts +2 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/tokenType.js +118 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/tokenType.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/types.d.ts +60 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/types.js +2 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/types.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/whitespace.d.ts +2 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/whitespace.js +19 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/whitespace.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/package.json +53 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/tsconfig.json +19 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/CHANGELOG.md +209 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/LICENSE +21 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/README.md +124 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.d.mts +152 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.d.ts +152 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.js +485 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.mjs +467 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/package.json +50 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/LICENSE +24 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/README.md +23 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-bash.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-c.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-c_sharp.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-cpp.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-css.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-dart.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-elisp.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-elixir.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-elm.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-embedded_template.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-go.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-html.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-java.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-javascript.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-json.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-kotlin.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-lua.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-objc.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-ocaml.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-php.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-python.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-ql.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-rescript.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-ruby.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-rust.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-scala.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-solidity.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-swift.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-systemrdl.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-tlaplus.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-toml.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-tsx.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-typescript.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-vue.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-yaml.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-zig.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/package.json +64 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/LICENSE +21 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/README.md +198 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/package.json +37 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/tree-sitter-web.d.ts +242 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/tree-sitter.js +1 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/tree-sitter.wasm +0 -0
- package/scaffold/scripts/parsers/package-lock.json +19 -1
- package/scaffold/scripts/parsers/package.json +3 -1
- package/scaffold/scripts/parsers/python-treesitter.mjs +271 -0
- package/scaffold/scripts/parsers/ruby-treesitter.mjs +271 -0
- package/scaffold/scripts/parsers/rust-dispatch.mjs +43 -0
- package/scaffold/scripts/parsers/rust-treesitter.mjs +291 -0
- package/scaffold/scripts/parsers/tree-sitter/base.mjs +163 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/bash.calls.scm +7 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/bash.chunks.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/bash.imports.scm +5 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/cpp.calls.scm +17 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/cpp.chunks.scm +30 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/cpp.imports.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/go.calls.scm +11 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/go.chunks.scm +19 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/go.imports.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/java.calls.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/java.chunks.scm +23 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/java.imports.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/python.calls.scm +11 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/python.chunks.scm +11 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/python.imports.scm +13 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/ruby.calls.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/ruby.chunks.scm +16 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/ruby.imports.scm +8 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/rust.calls.scm +31 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/rust.chunks.scm +29 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/rust.imports.scm +5 -0
- package/scaffold/scripts/parsers/vb6.mjs +395 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter parser infrastructure for Cortex.
|
|
3
|
+
*
|
|
4
|
+
* Provides shared utilities for tree-sitter-based language parsers:
|
|
5
|
+
* WASM grammar loading (cached), parser creation, query execution,
|
|
6
|
+
* and helpers for converting tree-sitter captures into Cortex chunks.
|
|
7
|
+
*
|
|
8
|
+
* Tree-sitter is async at init/load time but parsing itself is sync.
|
|
9
|
+
* Language modules call initTreeSitter() + loadGrammar() at module
|
|
10
|
+
* load time (via top-level await) so that parseCode() can remain sync
|
|
11
|
+
* and match the contract expected by scripts/ingest.mjs.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import fs from "node:fs";
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
17
|
+
import { createRequire } from "node:module";
|
|
18
|
+
|
|
19
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
20
|
+
const __dirname = path.dirname(__filename);
|
|
21
|
+
const require = createRequire(import.meta.url);
|
|
22
|
+
|
|
23
|
+
let TreeSitterModule = null;
|
|
24
|
+
let initPromise = null;
|
|
25
|
+
const grammarCache = new Map();
|
|
26
|
+
|
|
27
|
+
async function loadTreeSitter() {
|
|
28
|
+
if (TreeSitterModule) return TreeSitterModule;
|
|
29
|
+
const mod = await import("web-tree-sitter");
|
|
30
|
+
TreeSitterModule = mod.default ?? mod;
|
|
31
|
+
return TreeSitterModule;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function initTreeSitter() {
|
|
35
|
+
if (initPromise) return initPromise;
|
|
36
|
+
initPromise = (async () => {
|
|
37
|
+
const TreeSitter = await loadTreeSitter();
|
|
38
|
+
await TreeSitter.init();
|
|
39
|
+
return TreeSitter;
|
|
40
|
+
})();
|
|
41
|
+
return initPromise;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function resolveGrammarPath(grammarName) {
|
|
45
|
+
const override = process.env.CORTEX_TREE_SITTER_GRAMMAR_DIR;
|
|
46
|
+
const baseDir = override && override.trim().length > 0
|
|
47
|
+
? override.trim()
|
|
48
|
+
: path.dirname(require.resolve("tree-sitter-wasms/package.json"));
|
|
49
|
+
const wasmFile = path.join(baseDir, "out", `tree-sitter-${grammarName}.wasm`);
|
|
50
|
+
if (!fs.existsSync(wasmFile)) {
|
|
51
|
+
throw new Error(`tree-sitter grammar WASM not found: ${wasmFile}`);
|
|
52
|
+
}
|
|
53
|
+
return wasmFile;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function loadGrammar(grammarName) {
|
|
57
|
+
if (grammarCache.has(grammarName)) {
|
|
58
|
+
return grammarCache.get(grammarName);
|
|
59
|
+
}
|
|
60
|
+
const TreeSitter = await initTreeSitter();
|
|
61
|
+
const wasmPath = resolveGrammarPath(grammarName);
|
|
62
|
+
const language = await TreeSitter.Language.load(wasmPath);
|
|
63
|
+
grammarCache.set(grammarName, language);
|
|
64
|
+
return language;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function resetGrammarCache() {
|
|
68
|
+
grammarCache.clear();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function createParser(language) {
|
|
72
|
+
if (!TreeSitterModule) {
|
|
73
|
+
throw new Error("tree-sitter not initialized — call initTreeSitter() first");
|
|
74
|
+
}
|
|
75
|
+
const parser = new TreeSitterModule();
|
|
76
|
+
parser.setLanguage(language);
|
|
77
|
+
return parser;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function parseSource(language, code) {
|
|
81
|
+
const parser = createParser(language);
|
|
82
|
+
const tree = parser.parse(code);
|
|
83
|
+
return { tree, parser };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function runQuery(language, queryString, node) {
|
|
87
|
+
const query = language.query(queryString);
|
|
88
|
+
const captures = query.captures(node);
|
|
89
|
+
return captures;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Group captures into records keyed by an anchor capture name.
|
|
94
|
+
* Tree-sitter queries often produce multiple captures per match
|
|
95
|
+
* (e.g. @fn + @fn.name + @fn.body). This groups all captures whose
|
|
96
|
+
* node is contained within the same anchor node.
|
|
97
|
+
*
|
|
98
|
+
* @param {Array<{name: string, node: object}>} captures
|
|
99
|
+
* @param {string} anchorName - capture name that marks the outer scope
|
|
100
|
+
* @returns {Array<Map<string, object>>} list of maps from capture-name to node
|
|
101
|
+
*/
|
|
102
|
+
export function groupByAnchor(captures, anchorName) {
|
|
103
|
+
const anchors = captures
|
|
104
|
+
.filter((c) => c.name === anchorName)
|
|
105
|
+
.sort((a, b) => a.node.startIndex - b.node.startIndex);
|
|
106
|
+
|
|
107
|
+
const groups = anchors.map(() => new Map());
|
|
108
|
+
groups.forEach((g, i) => g.set(anchorName, anchors[i].node));
|
|
109
|
+
|
|
110
|
+
for (const cap of captures) {
|
|
111
|
+
if (cap.name === anchorName) continue;
|
|
112
|
+
const idx = anchors.findIndex((a) =>
|
|
113
|
+
cap.node.startIndex >= a.node.startIndex &&
|
|
114
|
+
cap.node.endIndex <= a.node.endIndex
|
|
115
|
+
);
|
|
116
|
+
if (idx >= 0 && !groups[idx].has(cap.name)) {
|
|
117
|
+
groups[idx].set(cap.name, cap.node);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return groups;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function lineRangeOf(node) {
|
|
125
|
+
return {
|
|
126
|
+
startLine: node.startPosition.row + 1,
|
|
127
|
+
endLine: node.endPosition.row + 1
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function bodyOf(node, maxChars = 12000) {
|
|
132
|
+
const text = node.text ?? "";
|
|
133
|
+
if (text.length <= maxChars) return text;
|
|
134
|
+
return text.slice(0, maxChars);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function normalizeWhitespace(value) {
|
|
138
|
+
return String(value).replace(/\s+/g, " ").trim();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function dedupe(items) {
|
|
142
|
+
return [...new Set(items.filter((item) => item != null && item !== ""))];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Convenience loader for language modules — initializes tree-sitter and
|
|
147
|
+
* pre-loads a grammar. Returns an object with the grammar handle and
|
|
148
|
+
* shared helpers so language modules don't need to reimport base.mjs.
|
|
149
|
+
*/
|
|
150
|
+
export async function prepareLanguage(grammarName) {
|
|
151
|
+
await initTreeSitter();
|
|
152
|
+
const language = await loadGrammar(grammarName);
|
|
153
|
+
return {
|
|
154
|
+
language,
|
|
155
|
+
parse: (code) => parseSource(language, code),
|
|
156
|
+
query: (queryString, node) => runQuery(language, queryString, node)
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function loadQueryFile(filePath) {
|
|
161
|
+
const url = filePath.startsWith("file:") ? new URL(filePath) : pathToFileURL(path.resolve(__dirname, filePath));
|
|
162
|
+
return fs.readFileSync(url, "utf8");
|
|
163
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
; Bash calls. Every `command` node has a `command_name` which contains
|
|
2
|
+
; the program / function being invoked. The adapter filters out
|
|
3
|
+
; builtins and common system commands so the graph reflects user-
|
|
4
|
+
; defined function calls rather than shell plumbing.
|
|
5
|
+
|
|
6
|
+
(command
|
|
7
|
+
name: (command_name) @call.name)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
; C/C++ call captures.
|
|
2
|
+
; - Direct calls: `foo()` — identifier as function child.
|
|
3
|
+
; - Member calls: `obj.m()` / `ptr->m()` — field_expression with a
|
|
4
|
+
; field_identifier; we capture the trailing field name.
|
|
5
|
+
; - Qualified calls: `ns::f()` / `Class::staticMethod()` —
|
|
6
|
+
; qualified_identifier with a trailing name identifier.
|
|
7
|
+
|
|
8
|
+
(call_expression
|
|
9
|
+
function: (identifier) @call.name)
|
|
10
|
+
|
|
11
|
+
(call_expression
|
|
12
|
+
function: (field_expression
|
|
13
|
+
field: (field_identifier) @call.name))
|
|
14
|
+
|
|
15
|
+
(call_expression
|
|
16
|
+
function: (qualified_identifier
|
|
17
|
+
name: (identifier) @call.name))
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
; C/C++ chunk captures. tree-sitter-cpp parses C too (superset), so
|
|
2
|
+
; one grammar covers .c, .h, .cpp, .cc, .hpp, .hh.
|
|
3
|
+
;
|
|
4
|
+
; - function_definition: top-level functions, methods defined inline
|
|
5
|
+
; inside class bodies, and out-of-class method definitions (with
|
|
6
|
+
; qualified_identifier like `Foo::bar`). The adapter inspects the
|
|
7
|
+
; function_declarator to pick the name form.
|
|
8
|
+
; - class_specifier / struct_specifier / union_specifier: type decls.
|
|
9
|
+
; - enum_specifier: plain `enum` and `enum class`.
|
|
10
|
+
; - namespace_definition: named namespaces (including nested `a::b`).
|
|
11
|
+
; - template_declaration is NOT captured directly — the inner
|
|
12
|
+
; class/function is captured separately, and walking up to the
|
|
13
|
+
; template_declaration parent for start-line is handled in the
|
|
14
|
+
; adapter if needed.
|
|
15
|
+
|
|
16
|
+
(function_definition) @fn.decl
|
|
17
|
+
|
|
18
|
+
(class_specifier
|
|
19
|
+
name: (type_identifier) @class.name) @class.decl
|
|
20
|
+
|
|
21
|
+
(struct_specifier
|
|
22
|
+
name: (type_identifier) @struct.name) @struct.decl
|
|
23
|
+
|
|
24
|
+
(union_specifier
|
|
25
|
+
name: (type_identifier) @union.name) @union.decl
|
|
26
|
+
|
|
27
|
+
(enum_specifier
|
|
28
|
+
name: (type_identifier) @enum.name) @enum.decl
|
|
29
|
+
|
|
30
|
+
(namespace_definition) @namespace.decl
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
; C/C++ include directives. `#include <x>` uses system_lib_string
|
|
2
|
+
; (the path includes the angle brackets); `#include "x"` uses
|
|
3
|
+
; string_literal. The adapter normalizes both to the bare path
|
|
4
|
+
; (without angle brackets or quotes).
|
|
5
|
+
|
|
6
|
+
(preproc_include) @include.decl
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
; Go call-expression captures. Function field can be:
|
|
2
|
+
; - identifier: direct call like foo()
|
|
3
|
+
; - selector_expression: qualified call like pkg.Fn() or obj.Method()
|
|
4
|
+
; The adapter extracts the trailing identifier (the "name" of the call).
|
|
5
|
+
|
|
6
|
+
(call_expression
|
|
7
|
+
function: (identifier) @call.name)
|
|
8
|
+
|
|
9
|
+
(call_expression
|
|
10
|
+
function: (selector_expression
|
|
11
|
+
field: (field_identifier) @call.name))
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
; Go chunk captures.
|
|
2
|
+
; - function_declaration: top-level funcs
|
|
3
|
+
; - method_declaration: methods with receiver (adapter extracts receiver type)
|
|
4
|
+
; - type_declaration: wraps type_spec and type_alias — the adapter inspects
|
|
5
|
+
; the body type (struct_type / interface_type / other) to choose the kind.
|
|
6
|
+
|
|
7
|
+
(function_declaration
|
|
8
|
+
name: (identifier) @fn.name) @fn.decl
|
|
9
|
+
|
|
10
|
+
(method_declaration
|
|
11
|
+
name: (field_identifier) @method.name) @method.decl
|
|
12
|
+
|
|
13
|
+
(type_declaration
|
|
14
|
+
(type_spec
|
|
15
|
+
name: (type_identifier) @type.name)) @type.decl
|
|
16
|
+
|
|
17
|
+
(type_declaration
|
|
18
|
+
(type_alias
|
|
19
|
+
name: (type_identifier) @type.name)) @type.decl
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
; Go import captures. import_spec covers both single imports and
|
|
2
|
+
; entries inside grouped import_spec_list. The adapter unquotes the
|
|
3
|
+
; path string literal so "fmt" -> fmt, "github.com/foo/bar" -> github.com/foo/bar.
|
|
4
|
+
|
|
5
|
+
(import_spec
|
|
6
|
+
path: (interpreted_string_literal) @import.path)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
; Java chunk captures.
|
|
2
|
+
; - class_declaration, interface_declaration, enum_declaration,
|
|
3
|
+
; record_declaration — each has an identifier name.
|
|
4
|
+
; - method_declaration and constructor_declaration are nested in
|
|
5
|
+
; class/interface bodies; the adapter walks up to qualify names.
|
|
6
|
+
|
|
7
|
+
(class_declaration
|
|
8
|
+
name: (identifier) @class.name) @class.decl
|
|
9
|
+
|
|
10
|
+
(interface_declaration
|
|
11
|
+
name: (identifier) @interface.name) @interface.decl
|
|
12
|
+
|
|
13
|
+
(enum_declaration
|
|
14
|
+
name: (identifier) @enum.name) @enum.decl
|
|
15
|
+
|
|
16
|
+
(record_declaration
|
|
17
|
+
name: (identifier) @record.name) @record.decl
|
|
18
|
+
|
|
19
|
+
(method_declaration
|
|
20
|
+
name: (identifier) @method.name) @method.decl
|
|
21
|
+
|
|
22
|
+
(constructor_declaration
|
|
23
|
+
name: (identifier) @ctor.name) @ctor.decl
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
; Java import captures. The import_declaration node wraps either a
|
|
2
|
+
; scoped_identifier (for the full path) or a scoped_identifier plus an
|
|
3
|
+
; asterisk (wildcard). The adapter extracts the path text and appends
|
|
4
|
+
; ".*" for wildcards.
|
|
5
|
+
|
|
6
|
+
(import_declaration) @import.decl
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
; Python call captures. The `call` node's `function` field may be:
|
|
2
|
+
; - identifier: direct call like foo()
|
|
3
|
+
; - attribute: method/qualified call like obj.method() or pkg.fn()
|
|
4
|
+
; - subscript: rare dynamic indexing — intentionally skipped.
|
|
5
|
+
|
|
6
|
+
(call
|
|
7
|
+
function: (identifier) @call.name)
|
|
8
|
+
|
|
9
|
+
(call
|
|
10
|
+
function: (attribute
|
|
11
|
+
attribute: (identifier) @call.name))
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
; Python chunk captures. function_definition covers both sync `def`
|
|
2
|
+
; and `async def` in tree-sitter-python (async is a token on the node,
|
|
3
|
+
; not a distinct node type). Decorated definitions wrap the inner
|
|
4
|
+
; function/class; we capture the inner nodes directly since startLine
|
|
5
|
+
; of the def/class is more useful than the decorator line.
|
|
6
|
+
|
|
7
|
+
(function_definition
|
|
8
|
+
name: (identifier) @fn.name) @fn.decl
|
|
9
|
+
|
|
10
|
+
(class_definition
|
|
11
|
+
name: (identifier) @class.name) @class.decl
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
; Python import captures. Covers three forms:
|
|
2
|
+
; import foo
|
|
3
|
+
; import foo as bar
|
|
4
|
+
; from pkg import name
|
|
5
|
+
; from .pkg import name
|
|
6
|
+
; from pkg import name as alias
|
|
7
|
+
;
|
|
8
|
+
; The adapter renders each as a dot-separated fully-qualified string
|
|
9
|
+
; matching what a user would grep for ("pkg.name", "foo", ".pkg.name").
|
|
10
|
+
|
|
11
|
+
(import_statement) @import.stmt
|
|
12
|
+
|
|
13
|
+
(import_from_statement) @import.stmt
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
; Ruby chunk captures.
|
|
2
|
+
; - class / module: top-level or nested type-like declarations
|
|
3
|
+
; - method: regular `def name` inside a class/module (or top-level)
|
|
4
|
+
; - singleton_method: `def self.name` — class-level methods
|
|
5
|
+
|
|
6
|
+
(class
|
|
7
|
+
name: (constant) @class.name) @class.decl
|
|
8
|
+
|
|
9
|
+
(module
|
|
10
|
+
name: (constant) @module.name) @module.decl
|
|
11
|
+
|
|
12
|
+
(method
|
|
13
|
+
name: (identifier) @method.name) @method.decl
|
|
14
|
+
|
|
15
|
+
(singleton_method
|
|
16
|
+
name: (identifier) @singleton.name) @singleton.decl
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
; Ruby imports are function-style calls. Capture top-level calls
|
|
2
|
+
; whose method identifier is a loader function; the adapter filters
|
|
3
|
+
; to just require / require_relative / load / autoload and extracts
|
|
4
|
+
; the string-literal path argument.
|
|
5
|
+
|
|
6
|
+
(call
|
|
7
|
+
method: (identifier) @import.func
|
|
8
|
+
arguments: (argument_list)) @import.call
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
; Call-expression captures for Rust. Extracts the callee identifier from
|
|
2
|
+
; call_expression nodes. The function field may be:
|
|
3
|
+
; - identifier: direct call like foo()
|
|
4
|
+
; - scoped_identifier: path call like std::fs::read()
|
|
5
|
+
; - field_expression: method call like self.foo()
|
|
6
|
+
; The adapter resolves the trailing name for each form.
|
|
7
|
+
|
|
8
|
+
(call_expression
|
|
9
|
+
function: (identifier) @call.name)
|
|
10
|
+
|
|
11
|
+
(call_expression
|
|
12
|
+
function: (scoped_identifier
|
|
13
|
+
name: (identifier) @call.name))
|
|
14
|
+
|
|
15
|
+
(call_expression
|
|
16
|
+
function: (field_expression
|
|
17
|
+
field: (field_identifier) @call.name))
|
|
18
|
+
|
|
19
|
+
(call_expression
|
|
20
|
+
function: (generic_function
|
|
21
|
+
function: (identifier) @call.name))
|
|
22
|
+
|
|
23
|
+
(call_expression
|
|
24
|
+
function: (generic_function
|
|
25
|
+
function: (scoped_identifier
|
|
26
|
+
name: (identifier) @call.name)))
|
|
27
|
+
|
|
28
|
+
(call_expression
|
|
29
|
+
function: (generic_function
|
|
30
|
+
function: (field_expression
|
|
31
|
+
field: (field_identifier) @call.name)))
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
; Top-level item captures for Rust.
|
|
2
|
+
; Each @*.decl anchor wraps the whole item; companion captures expose
|
|
3
|
+
; the name or other fields used by the adapter.
|
|
4
|
+
|
|
5
|
+
(function_item
|
|
6
|
+
name: (identifier) @fn.name
|
|
7
|
+
body: (block)) @fn.decl
|
|
8
|
+
|
|
9
|
+
(struct_item
|
|
10
|
+
name: (type_identifier) @struct.name) @struct.decl
|
|
11
|
+
|
|
12
|
+
(enum_item
|
|
13
|
+
name: (type_identifier) @enum.name) @enum.decl
|
|
14
|
+
|
|
15
|
+
(trait_item
|
|
16
|
+
name: (type_identifier) @trait.name) @trait.decl
|
|
17
|
+
|
|
18
|
+
(impl_item
|
|
19
|
+
type: (type_identifier) @impl.type) @impl.decl
|
|
20
|
+
|
|
21
|
+
(impl_item
|
|
22
|
+
type: (generic_type
|
|
23
|
+
type: (type_identifier) @impl.type)) @impl.decl
|
|
24
|
+
|
|
25
|
+
(mod_item
|
|
26
|
+
name: (identifier) @mod.name) @mod.decl
|
|
27
|
+
|
|
28
|
+
(macro_definition
|
|
29
|
+
name: (identifier) @macro.name) @macro.decl
|