@optave/codegraph 2.6.0 → 3.0.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 +109 -52
- package/package.json +5 -5
- package/src/ast.js +392 -0
- package/src/batch.js +93 -3
- package/src/builder.js +314 -95
- package/src/cfg.js +1451 -0
- package/src/change-journal.js +130 -0
- package/src/cli.js +411 -139
- package/src/complexity.js +8 -8
- package/src/dataflow.js +1187 -0
- package/src/db.js +96 -0
- package/src/embedder.js +16 -16
- package/src/export.js +305 -0
- package/src/extractors/csharp.js +64 -1
- package/src/extractors/go.js +66 -1
- package/src/extractors/hcl.js +22 -0
- package/src/extractors/java.js +61 -1
- package/src/extractors/javascript.js +142 -0
- package/src/extractors/php.js +79 -0
- package/src/extractors/python.js +134 -0
- package/src/extractors/ruby.js +89 -0
- package/src/extractors/rust.js +71 -1
- package/src/index.js +51 -3
- package/src/mcp.js +403 -222
- package/src/paginate.js +3 -3
- package/src/parser.js +8 -0
- package/src/queries.js +362 -36
- package/src/structure.js +4 -1
- package/src/viewer.js +948 -0
- package/src/watcher.js +36 -1
package/src/watcher.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { readFileSafe } from './builder.js';
|
|
4
|
+
import { appendChangeEvents, buildChangeEvent, diffSymbols } from './change-journal.js';
|
|
4
5
|
import { EXTENSIONS, IGNORE_DIRS, normalizePath } from './constants.js';
|
|
5
6
|
import { closeDb, initSchema, openDb } from './db.js';
|
|
6
7
|
import { appendJournalEntries } from './journal.js';
|
|
@@ -25,13 +26,25 @@ async function updateFile(_db, rootDir, filePath, stmts, engineOpts, cache) {
|
|
|
25
26
|
|
|
26
27
|
const oldNodes = stmts.countNodes.get(relPath)?.c || 0;
|
|
27
28
|
const _oldEdges = stmts.countEdgesForFile.get(relPath)?.c || 0;
|
|
29
|
+
const oldSymbols = stmts.listSymbols.all(relPath);
|
|
28
30
|
|
|
29
31
|
stmts.deleteEdgesForFile.run(relPath);
|
|
30
32
|
stmts.deleteNodes.run(relPath);
|
|
31
33
|
|
|
32
34
|
if (!fs.existsSync(filePath)) {
|
|
33
35
|
if (cache) cache.remove(filePath);
|
|
34
|
-
|
|
36
|
+
const symbolDiff = diffSymbols(oldSymbols, []);
|
|
37
|
+
return {
|
|
38
|
+
file: relPath,
|
|
39
|
+
nodesAdded: 0,
|
|
40
|
+
nodesRemoved: oldNodes,
|
|
41
|
+
edgesAdded: 0,
|
|
42
|
+
deleted: true,
|
|
43
|
+
event: 'deleted',
|
|
44
|
+
symbolDiff,
|
|
45
|
+
nodesBefore: oldNodes,
|
|
46
|
+
nodesAfter: 0,
|
|
47
|
+
};
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
let code;
|
|
@@ -55,6 +68,7 @@ async function updateFile(_db, rootDir, filePath, stmts, engineOpts, cache) {
|
|
|
55
68
|
}
|
|
56
69
|
|
|
57
70
|
const newNodes = stmts.countNodes.get(relPath)?.c || 0;
|
|
71
|
+
const newSymbols = stmts.listSymbols.all(relPath);
|
|
58
72
|
|
|
59
73
|
let edgesAdded = 0;
|
|
60
74
|
const fileNodeRow = stmts.getNodeId.get(relPath, 'file', relPath, 0);
|
|
@@ -129,12 +143,19 @@ async function updateFile(_db, rootDir, filePath, stmts, engineOpts, cache) {
|
|
|
129
143
|
}
|
|
130
144
|
}
|
|
131
145
|
|
|
146
|
+
const symbolDiff = diffSymbols(oldSymbols, newSymbols);
|
|
147
|
+
const event = oldNodes === 0 ? 'added' : 'modified';
|
|
148
|
+
|
|
132
149
|
return {
|
|
133
150
|
file: relPath,
|
|
134
151
|
nodesAdded: newNodes,
|
|
135
152
|
nodesRemoved: oldNodes,
|
|
136
153
|
edgesAdded,
|
|
137
154
|
deleted: false,
|
|
155
|
+
event,
|
|
156
|
+
symbolDiff,
|
|
157
|
+
nodesBefore: oldNodes,
|
|
158
|
+
nodesAfter: newNodes,
|
|
138
159
|
};
|
|
139
160
|
}
|
|
140
161
|
|
|
@@ -180,6 +201,7 @@ export async function watchProject(rootDir, opts = {}) {
|
|
|
180
201
|
findNodeByName: db.prepare(
|
|
181
202
|
"SELECT id, file FROM nodes WHERE name = ? AND kind IN ('function', 'method', 'class', 'interface', 'type', 'struct', 'enum', 'trait', 'record', 'module')",
|
|
182
203
|
),
|
|
204
|
+
listSymbols: db.prepare("SELECT name, kind, line FROM nodes WHERE file = ? AND kind != 'file'"),
|
|
183
205
|
};
|
|
184
206
|
|
|
185
207
|
// Use named params for statements needing the same value twice
|
|
@@ -218,6 +240,19 @@ export async function watchProject(rootDir, opts = {}) {
|
|
|
218
240
|
} catch {
|
|
219
241
|
/* journal write failure is non-fatal */
|
|
220
242
|
}
|
|
243
|
+
|
|
244
|
+
const changeEvents = updates.map((r) =>
|
|
245
|
+
buildChangeEvent(r.file, r.event, r.symbolDiff, {
|
|
246
|
+
nodesBefore: r.nodesBefore,
|
|
247
|
+
nodesAfter: r.nodesAfter,
|
|
248
|
+
edgesAdded: r.edgesAdded,
|
|
249
|
+
}),
|
|
250
|
+
);
|
|
251
|
+
try {
|
|
252
|
+
appendChangeEvents(rootDir, changeEvents);
|
|
253
|
+
} catch {
|
|
254
|
+
/* change event write failure is non-fatal */
|
|
255
|
+
}
|
|
221
256
|
}
|
|
222
257
|
|
|
223
258
|
for (const r of updates) {
|