revgraph 0.0.0-stage → 0.1.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.
@@ -0,0 +1,253 @@
1
+ import path from "node:path";
2
+ import { dedupeImports, findBraceBlockEndLine, stripCommentsKeepLines } from "./common.mjs";
3
+ import { extractRustTauri } from "./tauri.mjs";
4
+
5
+ /**
6
+ * Expand nested Rust `use` paths like `crate::a::{b, c::{d, e as f}}`.
7
+ */
8
+ function expandRustUseTree(expr) {
9
+ const s = expr.trim().replace(/;$/, "").trim();
10
+ if (!s) return [];
11
+ const braceIdx = s.indexOf("{");
12
+ if (braceIdx === -1) {
13
+ const noAlias = s.replace(/\s+as\s+[A-Za-z0-9_]+$/, "").trim();
14
+ return noAlias ? [noAlias] : [];
15
+ }
16
+ const prefix = s.slice(0, braceIdx).trim().replace(/::$/, "");
17
+ let depth = 0;
18
+ let endIdx = -1;
19
+ for (let i = braceIdx; i < s.length; i++) {
20
+ if (s[i] === "{") depth++;
21
+ else if (s[i] === "}") {
22
+ depth--;
23
+ if (depth === 0) {
24
+ endIdx = i;
25
+ break;
26
+ }
27
+ }
28
+ }
29
+ if (endIdx === -1) return [];
30
+ const inner = s.slice(braceIdx + 1, endIdx);
31
+ const parts = [];
32
+ let d = 0;
33
+ let cur = "";
34
+ for (let i = 0; i < inner.length; i++) {
35
+ const ch = inner[i];
36
+ if (ch === "{") d++;
37
+ else if (ch === "}") d--;
38
+ if (ch === "," && d === 0) {
39
+ if (cur.trim()) parts.push(cur.trim());
40
+ cur = "";
41
+ } else {
42
+ cur += ch;
43
+ }
44
+ }
45
+ if (cur.trim()) parts.push(cur.trim());
46
+
47
+ const expanded = [];
48
+ for (const p of parts) {
49
+ for (const sub of expandRustUseTree(p)) {
50
+ if (sub === "self") {
51
+ if (prefix) expanded.push(prefix);
52
+ } else if (prefix) {
53
+ expanded.push(`${prefix}::${sub}`);
54
+ } else {
55
+ expanded.push(sub);
56
+ }
57
+ }
58
+ }
59
+ return expanded;
60
+ }
61
+
62
+ /**
63
+ * Auto-detect Rust crate roots (src/lib.rs, src/main.rs, crates/*\/src/lib.rs, src-tauri/src/lib.rs, etc.)
64
+ * so single crates, Cargo workspaces, and Tauri repos all resolve `crate::` accurately.
65
+ */
66
+ export function buildRustModuleIndex(rustFiles) {
67
+ const crateRoots = new Set();
68
+ for (const rel of rustFiles) {
69
+ const base = path.posix.basename(rel);
70
+ if (base === "lib.rs" || base === "main.rs") {
71
+ const dir = path.posix.dirname(rel);
72
+ crateRoots.add(dir === "." ? "" : `${dir}/`);
73
+ }
74
+ }
75
+ if (crateRoots.size === 0) crateRoots.add("src/");
76
+
77
+ const sortedRoots = Array.from(crateRoots).sort((a, b) => b.length - a.length);
78
+ const crates = new Map(); // rootPrefix -> { modToFile, fileToMod }
79
+ const fileToCrate = new Map();
80
+
81
+ for (const rel of rustFiles) {
82
+ const root = sortedRoots.find((r) => !r || rel.startsWith(r));
83
+ if (root === undefined) continue;
84
+ if (!crates.has(root)) {
85
+ crates.set(root, { modToFile: new Map(), fileToMod: new Map() });
86
+ }
87
+ const { modToFile, fileToMod } = crates.get(root);
88
+ const sub = rel.slice(root.length);
89
+ let modPath = "";
90
+ if (sub === "lib.rs" || sub === "main.rs") {
91
+ modPath = "crate";
92
+ } else if (sub.endsWith("/mod.rs")) {
93
+ modPath = "crate::" + sub.slice(0, -"/mod.rs".length).replace(/\//g, "::");
94
+ } else if (sub.endsWith(".rs")) {
95
+ modPath = "crate::" + sub.slice(0, -".rs".length).replace(/\//g, "::");
96
+ }
97
+ if (!modPath) continue;
98
+ if (!modToFile.has(modPath) || sub === "lib.rs") {
99
+ modToFile.set(modPath, rel);
100
+ }
101
+ fileToMod.set(rel, modPath);
102
+ fileToCrate.set(rel, root);
103
+ }
104
+
105
+ return { crates, fileToCrate };
106
+ }
107
+
108
+ function resolveRustPath(fromFile, usePath, rustIndex) {
109
+ const crateRoot = rustIndex.fileToCrate.get(fromFile);
110
+ const crate = crateRoot !== undefined ? rustIndex.crates.get(crateRoot) : null;
111
+ if (!crate) return null;
112
+
113
+ const { modToFile, fileToMod } = crate;
114
+ const curMod = fileToMod.get(fromFile) || "crate";
115
+ let normalized = usePath.trim();
116
+ if (normalized.startsWith("::")) normalized = normalized.slice(2);
117
+
118
+ if (normalized.startsWith("self::")) {
119
+ normalized = `${curMod}::${normalized.slice("self::".length)}`;
120
+ } else if (normalized.startsWith("super::")) {
121
+ const baseParts = curMod.split("::");
122
+ while (normalized.startsWith("super::")) {
123
+ if (baseParts.length > 1) baseParts.pop();
124
+ normalized = normalized.slice("super::".length);
125
+ }
126
+ normalized = `${baseParts.join("::")}::${normalized}`;
127
+ } else if (!normalized.startsWith("crate::") && normalized !== "crate") {
128
+ return null; // external crate
129
+ }
130
+
131
+ const segs = normalized.split("::").filter(Boolean);
132
+ for (let i = segs.length; i >= 2; i--) {
133
+ const cand = segs.slice(0, i).join("::");
134
+ if (modToFile.has(cand)) {
135
+ const sym = segs[i] && segs[i] !== "*" ? segs[i] : null;
136
+ return { target: modToFile.get(cand), symbol: sym };
137
+ }
138
+ }
139
+ return null;
140
+ }
141
+
142
+ export function parseRustFile(relPath, content, fileSet, rustIndex, { enableTauri = false } = {}) {
143
+ const clean = stripCommentsKeepLines(content, "rust");
144
+ const lines = clean.split("\n");
145
+ const imports = [];
146
+ const symbols = [];
147
+
148
+ // `mod foo;` declarations
149
+ const modRe = /(?:^|\n)\s*(?:pub(?:\([^)]*\))?\s+)?mod\s+([A-Za-z0-9_]+)\s*;/g;
150
+ const dir = path.posix.dirname(relPath);
151
+ const baseNoExt = path.posix.basename(relPath, ".rs");
152
+ for (const m of clean.matchAll(modRe)) {
153
+ const childName = m[1];
154
+ const searchBases =
155
+ baseNoExt === "mod" || baseNoExt === "lib" || baseNoExt === "main"
156
+ ? [dir]
157
+ : [path.posix.join(dir, baseNoExt), dir];
158
+ for (const b of searchBases) {
159
+ const f1 = path.posix.join(b, `${childName}.rs`);
160
+ const f2 = path.posix.join(b, childName, "mod.rs");
161
+ if (fileSet.has(f1)) {
162
+ imports.push({ target: f1, symbols: [], kind: "mod" });
163
+ break;
164
+ }
165
+ if (fileSet.has(f2)) {
166
+ imports.push({ target: f2, symbols: [], kind: "mod" });
167
+ break;
168
+ }
169
+ }
170
+ }
171
+
172
+ // `use ...;` statements
173
+ const useRe = /(?:^|\n)\s*(?:pub(?:\([^)]*\))?\s+)?use\s+([\s\S]*?);/g;
174
+ for (const m of clean.matchAll(useRe)) {
175
+ for (const item of expandRustUseTree(m[1])) {
176
+ const resolved = resolveRustPath(relPath, item, rustIndex);
177
+ if (resolved && resolved.target !== relPath) {
178
+ imports.push({
179
+ target: resolved.target,
180
+ symbols: resolved.symbol ? [resolved.symbol] : [],
181
+ kind: "use",
182
+ });
183
+ }
184
+ }
185
+ }
186
+
187
+ // Symbols: functions, impl methods, structs, enums, traits, type aliases
188
+ let currentImpl = null;
189
+ let implEndLine = 0;
190
+ for (let i = 0; i < lines.length; i++) {
191
+ const line = lines[i];
192
+ if (i + 1 > implEndLine) currentImpl = null;
193
+
194
+ const implMatch = line.match(
195
+ /^\s*impl(?:<[^>]*>)?\s+(?:[A-Za-z0-9_:]+(?:<[^>]*>)?\s+for\s+)?([A-Za-z0-9_]+)/,
196
+ );
197
+ if (implMatch) {
198
+ currentImpl = implMatch[1];
199
+ implEndLine = findBraceBlockEndLine(lines, i, 1200);
200
+ continue;
201
+ }
202
+
203
+ const fnMatch = line.match(
204
+ /^\s*(pub(?:\([^)]*\))?\s+)?(?:async\s+)?(?:unsafe\s+)?fn\s+([A-Za-z0-9_]+)/,
205
+ );
206
+ if (fnMatch) {
207
+ const endLine = findBraceBlockEndLine(lines, i, 400);
208
+ const rawName = fnMatch[2];
209
+ let sigEnd = i + 1;
210
+ for (let s = i; s < Math.min(lines.length, i + 12); s++) {
211
+ if (lines[s].includes("{") || lines[s].includes(";")) {
212
+ sigEnd = s + 1;
213
+ break;
214
+ }
215
+ }
216
+ symbols.push({
217
+ name: currentImpl ? `${currentImpl}::${rawName}` : rawName,
218
+ shortName: rawName,
219
+ kind: currentImpl ? "method" : "fn",
220
+ exported: Boolean(fnMatch[1]),
221
+ startLine: i + 1,
222
+ sigEndLine: sigEnd,
223
+ endLine,
224
+ });
225
+ continue;
226
+ }
227
+
228
+ const itemMatch = line.match(
229
+ /^\s*(pub(?:\([^)]*\))?\s+)?(struct|enum|trait|type)\s+([A-Za-z0-9_]+)/,
230
+ );
231
+ if (itemMatch) {
232
+ if (itemMatch[2] === "type" && currentImpl) continue;
233
+ const endLine = findBraceBlockEndLine(lines, i, 200);
234
+ symbols.push({
235
+ name: itemMatch[3],
236
+ shortName: itemMatch[3],
237
+ kind: itemMatch[2],
238
+ exported: Boolean(itemMatch[1]),
239
+ startLine: i + 1,
240
+ sigEndLine: i + 1,
241
+ endLine,
242
+ });
243
+ }
244
+ }
245
+
246
+ const tauri = enableTauri ? extractRustTauri(clean) : {};
247
+ return {
248
+ lang: "rust",
249
+ imports: dedupeImports(imports),
250
+ symbols,
251
+ ...tauri,
252
+ };
253
+ }
@@ -0,0 +1,363 @@
1
+ import { lineNumberAt } from "./common.mjs";
2
+
3
+ export function detectTauriRepo(allFiles) {
4
+ return allFiles.some(
5
+ (f) => f === "tauri.conf.json" || f.endsWith("/tauri.conf.json") || f.startsWith("src-tauri/") || f.includes("/src-tauri/"),
6
+ );
7
+ }
8
+
9
+ function snakeToCamel(s) {
10
+ return s.replace(/^_+/, "").replace(/_([a-zA-Z0-9])/g, (_, ch) => ch.toUpperCase());
11
+ }
12
+
13
+ function parseRustParams(paramStr, renameAll) {
14
+ const params = [];
15
+ let depth = 0;
16
+ let cur = "";
17
+ const parts = [];
18
+ for (let i = 0; i < paramStr.length; i++) {
19
+ const c = paramStr[i];
20
+ if ("<([".includes(c)) depth++;
21
+ else if (">)]".includes(c)) depth = Math.max(0, depth - 1);
22
+ if (c === "," && depth === 0) {
23
+ if (cur.trim()) parts.push(cur.trim());
24
+ cur = "";
25
+ } else {
26
+ cur += c;
27
+ }
28
+ }
29
+ if (cur.trim()) parts.push(cur.trim());
30
+
31
+ for (const part of parts) {
32
+ const cleaned = part.replace(/#\[[^\]]+\]\s*/g, "").trim();
33
+ const colonIdx = cleaned.indexOf(":");
34
+ if (colonIdx === -1) continue;
35
+ const rawName = cleaned.slice(0, colonIdx).replace(/\bmut\b/g, "").trim();
36
+ const typeStr = cleaned.slice(colonIdx + 1).trim();
37
+ if (
38
+ /\b(?:State|AppHandle|Window|WebviewWindow|Runtime|Channel|HeaderMap|Request)\b/.test(typeStr) ||
39
+ rawName === "self"
40
+ ) {
41
+ continue;
42
+ }
43
+ const isOptional = /^Option\s*</.test(typeStr);
44
+ const jsName = renameAll === "snake_case" ? rawName.replace(/^_+/, "") : snakeToCamel(rawName);
45
+ params.push({ rustName: rawName, jsName, optional: isOptional, type: typeStr.slice(0, 60) });
46
+ }
47
+ return params;
48
+ }
49
+
50
+ export function extractTsTauri(clean, rawContent) {
51
+ const tauriInvokes = [];
52
+ const tauriListens = [];
53
+ const tauriEmits = [];
54
+
55
+ const invokeRe =
56
+ /\binvoke\s*(?:<[\s\S]{0,180}?>)?\s*\(\s*["'`]([A-Za-z0-9_]+)["'`]\s*(?:,\s*([\s\S]{0,300}?))?\)/g;
57
+ for (const m of clean.matchAll(invokeRe)) {
58
+ const cmd = m[1];
59
+ const argSnippet = m[2] ? m[2].trim() : "";
60
+ let argKeys = null;
61
+ let hasSpread = false;
62
+ if (argSnippet.startsWith("{")) {
63
+ let depth = 0;
64
+ let endIdx = -1;
65
+ for (let i = 0; i < argSnippet.length; i++) {
66
+ if (argSnippet[i] === "{") depth++;
67
+ else if (argSnippet[i] === "}") {
68
+ depth--;
69
+ if (depth === 0) {
70
+ endIdx = i;
71
+ break;
72
+ }
73
+ }
74
+ }
75
+ const body = endIdx > 0 ? argSnippet.slice(1, endIdx) : argSnippet.slice(1);
76
+ if (body.includes("...")) {
77
+ hasSpread = true;
78
+ } else {
79
+ argKeys = [];
80
+ let d = 0;
81
+ let cur = "";
82
+ for (let i = 0; i < body.length; i++) {
83
+ const c = body[i];
84
+ if ("({[".includes(c)) d++;
85
+ else if (")}]".includes(c)) d--;
86
+ if (c === "," && d === 0) {
87
+ const keyM = cur.trim().match(/^([A-Za-z_$][\w$]*)\s*(?::|$)/);
88
+ if (keyM) argKeys.push(keyM[1]);
89
+ cur = "";
90
+ } else {
91
+ cur += c;
92
+ }
93
+ }
94
+ const lastKey = cur.trim().match(/^([A-Za-z_$][\w$]*)\s*(?::|$)/);
95
+ if (lastKey) argKeys.push(lastKey[1]);
96
+ }
97
+ }
98
+ tauriInvokes.push({ command: cmd, line: lineNumberAt(clean, m.index), argKeys, hasSpread });
99
+ }
100
+
101
+ const listenRe = /\b(?:listen|once)\s*(?:<[^>]{0,120}>)?\s*\(\s*["'`]([A-Za-z0-9_.:-]+)["'`]/g;
102
+ for (const m of clean.matchAll(listenRe)) {
103
+ tauriListens.push({ event: m[1], line: lineNumberAt(clean, m.index) });
104
+ }
105
+
106
+ if (rawContent.includes("@tauri-apps/api/event")) {
107
+ const emitRe = /\b(?:emit|emitTo)\s*\(\s*(?:[^,]+,\s*)?["'`]([A-Za-z0-9_.:-]+)["'`]/g;
108
+ for (const m of clean.matchAll(emitRe)) {
109
+ tauriEmits.push({ event: m[1], line: lineNumberAt(clean, m.index) });
110
+ }
111
+ }
112
+
113
+ return { tauriInvokes, tauriListens, tauriEmits };
114
+ }
115
+
116
+ export function extractRustTauri(clean) {
117
+ const tauriCommands = [];
118
+ const registeredHandlers = [];
119
+ const tauriEmits = [];
120
+ const tauriListens = [];
121
+ const eventConsts = new Map();
122
+
123
+ const constStrRe = /\bconst\s+(EVENT_[A-Z0-9_]+|[A-Z0-9_]*EVENT[A-Z0-9_]*)\s*:\s*&str\s*=\s*"([^"]+)"/g;
124
+ for (const m of clean.matchAll(constStrRe)) {
125
+ eventConsts.set(m[1], m[2]);
126
+ }
127
+
128
+ const cmdAttrRe = /#\[tauri::command(?:\(([^)]*)\))?\]/g;
129
+ for (const m of clean.matchAll(cmdAttrRe)) {
130
+ const attrArgs = m[1] || "";
131
+ const renameMatch = attrArgs.match(/rename_all\s*=\s*"([^"]+)"/);
132
+ const renameAll = renameMatch ? renameMatch[1] : "camelCase";
133
+ const after = clean.slice(m.index + m[0].length, m.index + m[0].length + 600);
134
+ const fnMatch = after.match(
135
+ /^(?:\s*#\[[^\]]*\])*\s*(?:pub(?:\([^)]*\))?\s+)?(?:async\s+)?fn\s+([A-Za-z0-9_]+)\s*(?:<[^>]*>)?\s*\(([\s\S]*?)\)/,
136
+ );
137
+ if (fnMatch) {
138
+ const fnName = fnMatch[1];
139
+ const line = lineNumberAt(clean, m.index + m[0].length + fnMatch.index);
140
+ tauriCommands.push({
141
+ name: fnName,
142
+ line,
143
+ renameAll,
144
+ params: parseRustParams(fnMatch[2], renameAll),
145
+ });
146
+ }
147
+ }
148
+
149
+ const genRe = /tauri::generate_handler!\s*\[([\s\S]*?)\]/g;
150
+ for (const m of clean.matchAll(genRe)) {
151
+ for (const rawItem of m[1].split(",")) {
152
+ const cleaned = rawItem.replace(/#\[[^\]]*\]/g, "").trim();
153
+ if (!cleaned) continue;
154
+ const segs = cleaned.split("::");
155
+ const name = segs[segs.length - 1].trim();
156
+ if (/^[A-Za-z0-9_]+$/.test(name)) registeredHandlers.push(name);
157
+ }
158
+ }
159
+
160
+ const rustEmitRe =
161
+ /\.\s*(?:emit|emit_to|emit_filter)\s*\(\s*(?:[^,]+,\s*)?(?:"([A-Za-z0-9_.:-]+)"|([A-Z][A-Z0-9_]+))/g;
162
+ for (const m of clean.matchAll(rustEmitRe)) {
163
+ if (m[1]) {
164
+ tauriEmits.push({ event: m[1], line: lineNumberAt(clean, m.index) });
165
+ } else if (m[2]) {
166
+ tauriEmits.push({
167
+ event: eventConsts.get(m[2]) || m[2],
168
+ constName: m[2],
169
+ line: lineNumberAt(clean, m.index),
170
+ });
171
+ }
172
+ }
173
+
174
+ const rustListenRe = /\.\s*listen(?:_any)?\s*\(\s*"([A-Za-z0-9_.:-]+)"/g;
175
+ for (const m of clean.matchAll(rustListenRe)) {
176
+ tauriListens.push({ event: m[1], line: lineNumberAt(clean, m.index) });
177
+ }
178
+
179
+ return { tauriCommands, registeredHandlers, tauriEmits, tauriListens, eventConsts };
180
+ }
181
+
182
+ export function analyzeTauriBridges({
183
+ parsed,
184
+ changedSet,
185
+ diffInfoByFile,
186
+ rangesOverlap,
187
+ addEdge,
188
+ }) {
189
+ const rustCommandMap = new Map();
190
+ const registeredHandlerSet = new Set();
191
+ const tsInvokeMap = new Map();
192
+ const eventPublishers = new Map();
193
+ const eventSubscribers = new Map();
194
+
195
+ // Resolve cross-file Rust event constants
196
+ const globalEventConsts = new Map();
197
+ for (const info of parsed.values()) {
198
+ if (info.eventConsts) {
199
+ for (const [k, v] of info.eventConsts.entries()) globalEventConsts.set(k, v);
200
+ }
201
+ }
202
+ for (const info of parsed.values()) {
203
+ if (info.lang === "rust" && info.tauriEmits) {
204
+ for (const ev of info.tauriEmits) {
205
+ if (ev.constName && globalEventConsts.has(ev.constName)) {
206
+ ev.event = globalEventConsts.get(ev.constName);
207
+ }
208
+ }
209
+ }
210
+ }
211
+
212
+ for (const [rel, info] of parsed.entries()) {
213
+ if (info.lang === "rust") {
214
+ for (const cmd of info.tauriCommands || []) {
215
+ if (!rustCommandMap.has(cmd.name)) rustCommandMap.set(cmd.name, []);
216
+ rustCommandMap.get(cmd.name).push({ file: rel, ...cmd });
217
+ }
218
+ for (const h of info.registeredHandlers || []) registeredHandlerSet.add(h);
219
+ for (const ev of info.tauriEmits || []) {
220
+ if (!eventPublishers.has(ev.event)) eventPublishers.set(ev.event, []);
221
+ eventPublishers.get(ev.event).push({ file: rel, line: ev.line, lang: "rust" });
222
+ }
223
+ for (const ev of info.tauriListens || []) {
224
+ if (!eventSubscribers.has(ev.event)) eventSubscribers.set(ev.event, []);
225
+ eventSubscribers.get(ev.event).push({ file: rel, line: ev.line, lang: "rust" });
226
+ }
227
+ } else if (info.lang === "ts") {
228
+ for (const inv of info.tauriInvokes || []) {
229
+ if (!tsInvokeMap.has(inv.command)) tsInvokeMap.set(inv.command, []);
230
+ tsInvokeMap.get(inv.command).push({ file: rel, ...inv });
231
+ }
232
+ for (const ev of info.tauriEmits || []) {
233
+ if (!eventPublishers.has(ev.event)) eventPublishers.set(ev.event, []);
234
+ eventPublishers.get(ev.event).push({ file: rel, line: ev.line, lang: "ts" });
235
+ }
236
+ for (const ev of info.tauriListens || []) {
237
+ if (!eventSubscribers.has(ev.event)) eventSubscribers.set(ev.event, []);
238
+ eventSubscribers.get(ev.event).push({ file: rel, line: ev.line, lang: "ts" });
239
+ }
240
+ }
241
+ }
242
+
243
+ const lineTouchedNear = (relPath, line, pad = 2) => {
244
+ const d = diffInfoByFile.get(relPath);
245
+ if (!d || d.added_lines.length === 0) return false;
246
+ return rangesOverlap(Math.max(1, line - pad), line + pad, d.added_lines);
247
+ };
248
+
249
+ const ipcBridges = [];
250
+ for (const [cmdName, invokes] of tsInvokeMap.entries()) {
251
+ const defs = rustCommandMap.get(cmdName) || [];
252
+ for (const inv of invokes) {
253
+ for (const def of defs) {
254
+ addEdge(inv.file, def.file);
255
+ const defInfo = parsed.get(def.file);
256
+ const defSym = defInfo?.symbols.find((s) => (s.shortName || s.name) === cmdName);
257
+ const defDiff = diffInfoByFile.get(def.file);
258
+ const defTouched =
259
+ changedSet.has(def.file) &&
260
+ defDiff &&
261
+ (defSym
262
+ ? rangesOverlap(defSym.startLine, defSym.endLine, defDiff.added_lines)
263
+ : lineTouchedNear(def.file, def.line, 15));
264
+ const invTouched = changedSet.has(inv.file) && lineTouchedNear(inv.file, inv.line, 3);
265
+ if (defTouched || invTouched) {
266
+ ipcBridges.push({
267
+ type: "tauri_command",
268
+ name: cmdName,
269
+ from_file: inv.file,
270
+ from_line: inv.line,
271
+ to_file: def.file,
272
+ to_line: def.line,
273
+ registered: registeredHandlerSet.has(cmdName),
274
+ });
275
+ }
276
+ }
277
+ }
278
+ }
279
+
280
+ for (const [eventName, pubs] of eventPublishers.entries()) {
281
+ const subs = eventSubscribers.get(eventName) || [];
282
+ for (const p of pubs) {
283
+ for (const s of subs) {
284
+ const pubTouched = changedSet.has(p.file) && lineTouchedNear(p.file, p.line, 3);
285
+ const subTouched = changedSet.has(s.file) && lineTouchedNear(s.file, s.line, 3);
286
+ if (pubTouched || subTouched) {
287
+ ipcBridges.push({
288
+ type: "tauri_event",
289
+ name: eventName,
290
+ from_file: p.file,
291
+ from_line: p.line,
292
+ to_file: s.file,
293
+ to_line: s.line,
294
+ });
295
+ }
296
+ }
297
+ }
298
+ }
299
+
300
+ const staticAlerts = [];
301
+ for (const rel of changedSet) {
302
+ const info = parsed.get(rel);
303
+ if (!info) continue;
304
+ if (info.lang === "rust") {
305
+ for (const cmd of info.tauriCommands || []) {
306
+ if (!registeredHandlerSet.has(cmd.name)) {
307
+ staticAlerts.push({
308
+ severity: "high",
309
+ code: "UNREGISTERED_TAURI_COMMAND",
310
+ file: rel,
311
+ line: cmd.line,
312
+ message: `\`#[tauri::command] fn ${cmd.name}\` is not registered in \`tauri::generate_handler![...]\`.`,
313
+ });
314
+ }
315
+ }
316
+ } else if (info.lang === "ts") {
317
+ for (const inv of info.tauriInvokes || []) {
318
+ const rustDefs = rustCommandMap.get(inv.command) || [];
319
+ if (rustDefs.length === 0 && !registeredHandlerSet.has(inv.command)) {
320
+ staticAlerts.push({
321
+ severity: "high",
322
+ code: "ORPHAN_TAURI_INVOKE",
323
+ file: rel,
324
+ line: inv.line,
325
+ message: `Frontend calls \`invoke("${inv.command}")\` with no matching \`#[tauri::command]\` or \`generate_handler![]\` entry.`,
326
+ });
327
+ } else if (rustDefs.length === 1 && inv.argKeys && !inv.hasSpread) {
328
+ const def = rustDefs[0];
329
+ const expectedJs = new Set(def.params.map((p) => p.jsName));
330
+ const unknownKeys = inv.argKeys.filter((k) => !expectedJs.has(k));
331
+ const provided = new Set(inv.argKeys);
332
+ const missingRequired = def.params
333
+ .filter((p) => !p.optional && !provided.has(p.jsName))
334
+ .map((p) => p.jsName);
335
+ if (unknownKeys.length > 0 || missingRequired.length > 0) {
336
+ const parts = [];
337
+ if (unknownKeys.length > 0) parts.push(`unknown keys: [${unknownKeys.join(", ")}]`);
338
+ if (missingRequired.length > 0) parts.push(`missing required keys: [${missingRequired.join(", ")}]`);
339
+ staticAlerts.push({
340
+ severity: "high",
341
+ code: "TAURI_IPC_ARG_MISMATCH",
342
+ file: rel,
343
+ line: inv.line,
344
+ message: `\`invoke("${inv.command}")\` argument mismatch against \`${def.file}:${def.line}\` (rename_all=${def.renameAll}): ${parts.join("; ")}.`,
345
+ });
346
+ }
347
+ }
348
+ }
349
+ }
350
+ }
351
+
352
+ const uniqueIpc = [];
353
+ const ipcSeen = new Set();
354
+ for (const b of ipcBridges) {
355
+ const k = `${b.type}:${b.name}:${b.from_file}:${b.to_file}`;
356
+ if (!ipcSeen.has(k)) {
357
+ ipcSeen.add(k);
358
+ uniqueIpc.push(b);
359
+ }
360
+ }
361
+
362
+ return { ipcBridges: uniqueIpc, staticAlerts, tsInvokeMap };
363
+ }