kodingo-cli 1.0.7 → 1.0.8
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.
|
@@ -145,41 +145,130 @@ class GitListenerAdapter {
|
|
|
145
145
|
this.lastProcessedCommit = latestCommit.hash;
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
|
-
|
|
149
|
-
*
|
|
148
|
+
/**
|
|
149
|
+
* Extract touched function/class/method names from changed files.
|
|
150
|
+
* Supports: JS, TS, JSX, TSX (AST), PHP, Python, Go, Rust, Java, Kotlin, Ruby, C/C++ (regex).
|
|
150
151
|
*/
|
|
151
152
|
extractTouchedSymbols(diffFiles) {
|
|
152
153
|
const symbols = [];
|
|
153
154
|
for (const file of diffFiles) {
|
|
154
155
|
if (file.binary)
|
|
155
156
|
continue;
|
|
156
|
-
const isTsOrJs = file.file.endsWith(".ts") || file.file.endsWith(".js");
|
|
157
|
-
if (!isTsOrJs)
|
|
158
|
-
continue;
|
|
159
157
|
const absFilePath = path_1.default.join(this.repoPath, file.file);
|
|
160
158
|
if (!fs_1.default.existsSync(absFilePath))
|
|
161
159
|
continue;
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
160
|
+
const src = fs_1.default.readFileSync(absFilePath, "utf-8");
|
|
161
|
+
const ext = file.file.split(".").pop()?.toLowerCase() ?? "";
|
|
162
|
+
// JS / TS / JSX / TSX — AST parser
|
|
163
|
+
if (["ts", "tsx", "js", "jsx", "mjs", "cjs"].includes(ext)) {
|
|
164
|
+
try {
|
|
165
|
+
const ast = (0, parser_1.parse)(src, {
|
|
166
|
+
sourceType: "module",
|
|
167
|
+
plugins: ["typescript", "classProperties", "jsx", "decorators-legacy", "classStaticBlock"],
|
|
168
|
+
});
|
|
169
|
+
(0, traverse_1.default)(ast, {
|
|
170
|
+
FunctionDeclaration(p) {
|
|
171
|
+
const name = p?.node?.id?.name;
|
|
172
|
+
if (name)
|
|
173
|
+
symbols.push(`function:${name}`);
|
|
174
|
+
},
|
|
175
|
+
ArrowFunctionExpression(p) {
|
|
176
|
+
const parent = p?.parent;
|
|
177
|
+
if (parent?.type === "VariableDeclarator" && parent?.id?.name) {
|
|
178
|
+
symbols.push(`function:${parent.id.name}`);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
ClassDeclaration(p) {
|
|
182
|
+
const name = p?.node?.id?.name;
|
|
183
|
+
if (name)
|
|
184
|
+
symbols.push(`class:${name}`);
|
|
185
|
+
},
|
|
186
|
+
ClassMethod(p) {
|
|
187
|
+
const name = p?.node?.key?.name;
|
|
188
|
+
if (name && name !== "constructor")
|
|
189
|
+
symbols.push(`method:${name}`);
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
for (const m of src.matchAll(/(?:function\s+(\w+)|const\s+(\w+)\s*=\s*(?:async\s*)?\()/g)) {
|
|
195
|
+
const name = m[1] || m[2];
|
|
171
196
|
if (name)
|
|
172
197
|
symbols.push(`function:${name}`);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
// PHP
|
|
203
|
+
if (ext === "php") {
|
|
204
|
+
for (const m of src.matchAll(/(?:function\s+(\w+)\s*\(|class\s+(\w+)(?:\s+extends|\s+implements|\s*\{))/g)) {
|
|
205
|
+
const name = m[1] || m[2];
|
|
206
|
+
if (name)
|
|
207
|
+
symbols.push(m[1] ? `function:${name}` : `class:${name}`);
|
|
208
|
+
}
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
// Python
|
|
212
|
+
if (ext === "py") {
|
|
213
|
+
for (const m of src.matchAll(/^(?:async\s+)?def\s+(\w+)\s*\(|^class\s+(\w+)/gm)) {
|
|
214
|
+
const name = m[1] || m[2];
|
|
215
|
+
if (name)
|
|
216
|
+
symbols.push(m[1] ? `function:${name}` : `class:${name}`);
|
|
217
|
+
}
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
// Go
|
|
221
|
+
if (ext === "go") {
|
|
222
|
+
for (const m of src.matchAll(/^func\s+(?:\(\w+\s+\*?\w+\)\s+)?(\w+)\s*\(/gm)) {
|
|
223
|
+
if (m[1])
|
|
224
|
+
symbols.push(`function:${m[1]}`);
|
|
225
|
+
}
|
|
226
|
+
continue;
|
|
180
227
|
}
|
|
181
|
-
|
|
182
|
-
|
|
228
|
+
// Rust
|
|
229
|
+
if (ext === "rs") {
|
|
230
|
+
for (const m of src.matchAll(/^(?:pub\s+)?(?:async\s+)?fn\s+(\w+)|^(?:pub\s+)?struct\s+(\w+)|^(?:pub\s+)?impl\s+(\w+)/gm)) {
|
|
231
|
+
const name = m[1] || m[2] || m[3];
|
|
232
|
+
if (name)
|
|
233
|
+
symbols.push(m[1] ? `function:${name}` : m[2] ? `struct:${name}` : `impl:${name}`);
|
|
234
|
+
}
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
// Java
|
|
238
|
+
if (ext === "java") {
|
|
239
|
+
for (const m of src.matchAll(/(?:public|private|protected|static|\s)+[\w<>\[\]]+\s+(\w+)\s*\([^)]*\)\s*(?:throws\s+\w+\s*)?\{|(?:public|private|protected)?\s*(?:abstract\s+)?class\s+(\w+)/g)) {
|
|
240
|
+
const name = m[1] || m[2];
|
|
241
|
+
if (name)
|
|
242
|
+
symbols.push(m[1] ? `method:${name}` : `class:${name}`);
|
|
243
|
+
}
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
// Kotlin
|
|
247
|
+
if (ext === "kt" || ext === "kts") {
|
|
248
|
+
for (const m of src.matchAll(/(?:fun\s+(\w+)\s*\(|class\s+(\w+)|object\s+(\w+))/g)) {
|
|
249
|
+
const name = m[1] || m[2] || m[3];
|
|
250
|
+
if (name)
|
|
251
|
+
symbols.push(m[1] ? `function:${name}` : `class:${name}`);
|
|
252
|
+
}
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
// Ruby
|
|
256
|
+
if (ext === "rb") {
|
|
257
|
+
for (const m of src.matchAll(/^(?:def\s+(\w+)|class\s+(\w+))/gm)) {
|
|
258
|
+
const name = m[1] || m[2];
|
|
259
|
+
if (name)
|
|
260
|
+
symbols.push(m[1] ? `function:${name}` : `class:${name}`);
|
|
261
|
+
}
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
// C / C++
|
|
265
|
+
if (["c", "cpp", "cc", "cxx", "h", "hpp"].includes(ext)) {
|
|
266
|
+
for (const m of src.matchAll(/^[\w:*&<>\s]+\s+(\w+)\s*\([^)]*\)\s*(?:const\s*)?\{/gm)) {
|
|
267
|
+
if (m[1] && !["if", "for", "while", "switch", "catch"].includes(m[1])) {
|
|
268
|
+
symbols.push(`function:${m[1]}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
continue;
|
|
183
272
|
}
|
|
184
273
|
}
|
|
185
274
|
return Array.from(new Set(symbols));
|