codemaxxing 0.4.4 → 0.4.6

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/dist/auth-cli.js CHANGED
File without changes
package/dist/cli.js CHANGED
File without changes
package/dist/index.js CHANGED
@@ -16,7 +16,9 @@ import { listServers, addServer, removeServer, getConnectedServers } from "./uti
16
16
  import { detectHardware, formatBytes } from "./utils/hardware.js";
17
17
  import { getRecommendationsWithLlmfit, getFitIcon, isLlmfitAvailable } from "./utils/models.js";
18
18
  import { isOllamaInstalled, isOllamaRunning, getOllamaInstallCommand, startOllama, stopOllama, pullModel, listInstalledModelsDetailed, deleteModel, getGPUMemoryUsage } from "./utils/ollama.js";
19
- const VERSION = require("../package.json").version;
19
+ import { createRequire } from "module";
20
+ const _require = createRequire(import.meta.url);
21
+ const VERSION = _require("../package.json").version;
20
22
  // ── Helpers ──
21
23
  function formatTimeAgo(date) {
22
24
  const secs = Math.floor((Date.now() - date.getTime()) / 1000);
@@ -1468,7 +1470,7 @@ function App() {
1468
1470
  try {
1469
1471
  // Use pipe instead of inherit — Ink TUI conflicts with inherit stdio
1470
1472
  const parts = installCmd.split(" ");
1471
- const result = require("child_process").spawnSync(parts[0], parts.slice(1), {
1473
+ const result = _require("child_process").spawnSync(parts[0], parts.slice(1), {
1472
1474
  stdio: "pipe",
1473
1475
  timeout: 180000,
1474
1476
  shell: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codemaxxing",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "Open-source terminal coding agent. Connect any LLM. Max your code.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/index.tsx CHANGED
@@ -17,7 +17,9 @@ import { detectHardware, formatBytes, type HardwareInfo } from "./utils/hardware
17
17
  import { getRecommendations, getRecommendationsWithLlmfit, getFitIcon, isLlmfitAvailable, type ScoredModel } from "./utils/models.js";
18
18
  import { isOllamaInstalled, isOllamaRunning, getOllamaInstallCommand, startOllama, stopOllama, pullModel, listInstalledModelsDetailed, deleteModel, getGPUMemoryUsage, type PullProgress } from "./utils/ollama.js";
19
19
 
20
- const VERSION = require("../package.json").version;
20
+ import { createRequire } from "module";
21
+ const _require = createRequire(import.meta.url);
22
+ const VERSION = _require("../package.json").version;
21
23
 
22
24
  // ── Helpers ──
23
25
  function formatTimeAgo(date: Date): string {
@@ -1492,7 +1494,7 @@ function App() {
1492
1494
  try {
1493
1495
  // Use pipe instead of inherit — Ink TUI conflicts with inherit stdio
1494
1496
  const parts = installCmd.split(" ");
1495
- const result = require("child_process").spawnSync(parts[0], parts.slice(1), {
1497
+ const result = _require("child_process").spawnSync(parts[0], parts.slice(1), {
1496
1498
  stdio: "pipe",
1497
1499
  timeout: 180000,
1498
1500
  shell: true,
@@ -1,20 +0,0 @@
1
- export interface Signature {
2
- kind: "function" | "class" | "method" | "interface" | "type" | "enum" | "struct" | "trait" | "impl" | "variable" | "const" | "module" | "package" | "export";
3
- name: string;
4
- detail: string;
5
- startLine: number;
6
- endLine: number;
7
- children?: Signature[];
8
- }
9
- /**
10
- * Get the language name for a file extension
11
- */
12
- export declare function getLanguageForExt(ext: string): string | null;
13
- /**
14
- * Get all supported extensions
15
- */
16
- export declare function getSupportedExtensions(): string[];
17
- /**
18
- * Parse a file and extract signatures using tree-sitter queries
19
- */
20
- export declare function extractSignatures(source: string, langName: string): Promise<Signature[]>;
@@ -1,710 +0,0 @@
1
- import { Parser, Language } from "web-tree-sitter";
2
- import { join, dirname } from "path";
3
- import { createRequire } from "module";
4
- const LANGUAGES = {
5
- javascript: {
6
- extensions: [".js", ".jsx", ".mjs", ".cjs"],
7
- wasmFile: "tree-sitter-javascript.wasm",
8
- query: `
9
- ;; Function declarations
10
- (function_declaration
11
- name: (identifier) @fn.name) @fn.def
12
-
13
- ;; Arrow functions assigned to const/let/var
14
- (lexical_declaration
15
- (variable_declarator
16
- name: (identifier) @fn.name
17
- value: (arrow_function) @fn.arrow)) @fn.def
18
-
19
- ;; Variable declarations (non-arrow)
20
- (lexical_declaration
21
- (variable_declarator
22
- name: (identifier) @var.name
23
- value: (_) @var.value)) @var.def
24
-
25
- ;; Class declarations
26
- (class_declaration
27
- name: (identifier) @class.name) @class.def
28
-
29
- ;; Method definitions inside classes
30
- (method_definition
31
- name: (property_identifier) @method.name) @method.def
32
-
33
- ;; Export statements
34
- (export_statement) @export.stmt
35
- `,
36
- },
37
- typescript: {
38
- extensions: [".ts", ".tsx"],
39
- wasmFile: "tree-sitter-typescript.wasm",
40
- query: `
41
- ;; Function declarations
42
- (function_declaration
43
- name: (identifier) @fn.name) @fn.def
44
-
45
- ;; Arrow functions assigned to const/let/var
46
- (lexical_declaration
47
- (variable_declarator
48
- name: (identifier) @fn.name
49
- value: (arrow_function) @fn.arrow)) @fn.def
50
-
51
- ;; Variable declarations (non-arrow)
52
- (lexical_declaration
53
- (variable_declarator
54
- name: (identifier) @var.name)) @var.def
55
-
56
- ;; Class declarations
57
- (class_declaration
58
- name: (type_identifier) @class.name) @class.def
59
-
60
- ;; Method definitions
61
- (method_definition
62
- name: (property_identifier) @method.name) @method.def
63
-
64
- ;; Interface declarations
65
- (interface_declaration
66
- name: (type_identifier) @iface.name) @iface.def
67
-
68
- ;; Type alias declarations
69
- (type_alias_declaration
70
- name: (type_identifier) @type.name) @type.def
71
-
72
- ;; Enum declarations
73
- (enum_declaration
74
- name: (identifier) @enum.name) @enum.def
75
-
76
- ;; Export statements
77
- (export_statement) @export.stmt
78
- `,
79
- },
80
- python: {
81
- extensions: [".py"],
82
- wasmFile: "tree-sitter-python.wasm",
83
- query: `
84
- ;; Function definitions
85
- (function_definition
86
- name: (identifier) @fn.name) @fn.def
87
-
88
- ;; Class definitions
89
- (class_definition
90
- name: (identifier) @class.name) @class.def
91
-
92
- ;; Decorated definitions
93
- (decorated_definition) @decorated.def
94
-
95
- ;; Assignments at module level
96
- (expression_statement
97
- (assignment
98
- left: (identifier) @var.name)) @var.def
99
- `,
100
- },
101
- go: {
102
- extensions: [".go"],
103
- wasmFile: "tree-sitter-go.wasm",
104
- query: `
105
- ;; Function declarations
106
- (function_declaration
107
- name: (identifier) @fn.name) @fn.def
108
-
109
- ;; Method declarations
110
- (method_declaration
111
- name: (field_identifier) @method.name) @method.def
112
-
113
- ;; Type declarations (struct, interface, alias)
114
- (type_declaration
115
- (type_spec
116
- name: (type_identifier) @type.name
117
- type: (_) @type.body)) @type.def
118
-
119
- ;; Package clause
120
- (package_clause
121
- (package_identifier) @pkg.name) @pkg.def
122
-
123
- ;; Const/var declarations
124
- (const_declaration) @const.def
125
- (var_declaration) @var.def
126
- `,
127
- },
128
- rust: {
129
- extensions: [".rs"],
130
- wasmFile: "tree-sitter-rust.wasm",
131
- query: `
132
- ;; Function declarations
133
- (function_item
134
- name: (identifier) @fn.name) @fn.def
135
-
136
- ;; Struct declarations
137
- (struct_item
138
- name: (type_identifier) @struct.name) @struct.def
139
-
140
- ;; Enum declarations
141
- (enum_item
142
- name: (type_identifier) @enum.name) @enum.def
143
-
144
- ;; Impl blocks
145
- (impl_item
146
- type: (_) @impl.type) @impl.def
147
-
148
- ;; Trait declarations
149
- (trait_item
150
- name: (type_identifier) @trait.name) @trait.def
151
-
152
- ;; Type alias
153
- (type_item
154
- name: (type_identifier) @type.name) @type.def
155
-
156
- ;; Const/static declarations
157
- (const_item
158
- name: (identifier) @const.name) @const.def
159
- (static_item
160
- name: (identifier) @static.name) @static.def
161
-
162
- ;; Mod declarations
163
- (mod_item
164
- name: (identifier) @mod.name) @mod.def
165
- `,
166
- },
167
- };
168
- // ── Tree-Sitter Manager ──
169
- let parserInitialized = false;
170
- const loadedLanguages = new Map();
171
- /**
172
- * Get the language name for a file extension
173
- */
174
- export function getLanguageForExt(ext) {
175
- for (const [lang, config] of Object.entries(LANGUAGES)) {
176
- if (config.extensions.includes(ext))
177
- return lang;
178
- }
179
- return null;
180
- }
181
- /**
182
- * Get all supported extensions
183
- */
184
- export function getSupportedExtensions() {
185
- return Object.values(LANGUAGES).flatMap((c) => c.extensions);
186
- }
187
- /**
188
- * Initialize the tree-sitter WASM runtime
189
- */
190
- async function ensureInit() {
191
- if (parserInitialized)
192
- return;
193
- const require = createRequire(import.meta.url);
194
- const wasmPath = require.resolve("web-tree-sitter/web-tree-sitter.wasm");
195
- await Parser.init({
196
- locateFile: () => wasmPath,
197
- });
198
- parserInitialized = true;
199
- }
200
- /**
201
- * Load a language grammar (cached)
202
- */
203
- async function loadLanguage(langName) {
204
- if (loadedLanguages.has(langName))
205
- return loadedLanguages.get(langName);
206
- const config = LANGUAGES[langName];
207
- if (!config)
208
- throw new Error(`Unsupported language: ${langName}`);
209
- const require = createRequire(import.meta.url);
210
- const wasmDir = join(dirname(require.resolve("tree-sitter-wasms/package.json")), "out");
211
- const wasmPath = join(wasmDir, config.wasmFile);
212
- const lang = await Language.load(wasmPath);
213
- loadedLanguages.set(langName, lang);
214
- return lang;
215
- }
216
- /**
217
- * Extract a concise one-line signature from a node's text
218
- */
219
- function extractSignatureLine(node, kind, langName) {
220
- const text = node.text;
221
- const firstLine = text.split("\n")[0].trim();
222
- // For functions — show up to the opening brace or body
223
- if (kind === "function" || kind === "method") {
224
- // Remove body (everything from { onward) for a clean signature
225
- const braceIdx = firstLine.indexOf("{");
226
- if (braceIdx > 0)
227
- return firstLine.slice(0, braceIdx).trim();
228
- // Python: remove the colon at end
229
- if (langName === "python" && firstLine.endsWith(":")) {
230
- return firstLine.slice(0, -1).trim();
231
- }
232
- return firstLine;
233
- }
234
- // For classes/structs/interfaces — just the declaration line
235
- if (["class", "struct", "interface", "trait", "enum", "impl"].includes(kind)) {
236
- const braceIdx = firstLine.indexOf("{");
237
- if (braceIdx > 0)
238
- return firstLine.slice(0, braceIdx).trim();
239
- if (firstLine.endsWith(":"))
240
- return firstLine.slice(0, -1).trim();
241
- return firstLine;
242
- }
243
- // For types/consts — show the whole first line
244
- return firstLine.length > 120 ? firstLine.slice(0, 117) + "..." : firstLine;
245
- }
246
- /**
247
- * Parse a file and extract signatures using tree-sitter queries
248
- */
249
- export async function extractSignatures(source, langName) {
250
- await ensureInit();
251
- const config = LANGUAGES[langName];
252
- if (!config)
253
- return [];
254
- const lang = await loadLanguage(langName);
255
- const parser = new Parser();
256
- parser.setLanguage(lang);
257
- const tree = parser.parse(source);
258
- if (!tree) {
259
- parser.delete();
260
- return [];
261
- }
262
- const signatures = [];
263
- // We'll walk the tree manually to get structured output
264
- // since query matching gives us flat captures
265
- const rootNode = tree.rootNode;
266
- for (let i = 0; i < rootNode.childCount; i++) {
267
- const node = rootNode.child(i);
268
- const sigs = extractNodeSignatures(node, langName, 0);
269
- signatures.push(...sigs);
270
- }
271
- parser.delete();
272
- tree.delete();
273
- return signatures;
274
- }
275
- /**
276
- * Recursively extract signatures from a node
277
- */
278
- function extractNodeSignatures(node, langName, depth) {
279
- const sigs = [];
280
- const type = node.type;
281
- // ── JavaScript / TypeScript ──
282
- if (langName === "javascript" || langName === "typescript") {
283
- // Function declaration
284
- if (type === "function_declaration") {
285
- const nameNode = node.childForFieldName("name");
286
- const sig = extractSignatureLine(node, "function", langName);
287
- sigs.push({
288
- kind: "function",
289
- name: nameNode?.text ?? "anonymous",
290
- detail: sig,
291
- startLine: node.startPosition.row + 1,
292
- endLine: node.endPosition.row + 1,
293
- });
294
- return sigs;
295
- }
296
- // Variable/const declarations (arrow functions, constants)
297
- if (type === "lexical_declaration" || type === "variable_declaration") {
298
- for (let c = 0; c < node.childCount; c++) {
299
- const declarator = node.child(c);
300
- if (declarator?.type === "variable_declarator") {
301
- const nameNode = declarator.childForFieldName("name");
302
- const valueNode = declarator.childForFieldName("value");
303
- const name = nameNode?.text ?? "unknown";
304
- if (valueNode?.type === "arrow_function" || valueNode?.type === "function") {
305
- sigs.push({
306
- kind: "function",
307
- name,
308
- detail: extractSignatureLine(node, "function", langName),
309
- startLine: node.startPosition.row + 1,
310
- endLine: node.endPosition.row + 1,
311
- });
312
- }
313
- else {
314
- sigs.push({
315
- kind: "variable",
316
- name,
317
- detail: extractSignatureLine(node, "variable", langName),
318
- startLine: node.startPosition.row + 1,
319
- endLine: node.endPosition.row + 1,
320
- });
321
- }
322
- }
323
- }
324
- return sigs;
325
- }
326
- // Class declaration
327
- if (type === "class_declaration") {
328
- const nameNode = node.childForFieldName("name");
329
- const name = nameNode?.text ?? "anonymous";
330
- const children = [];
331
- // Find class body and extract methods
332
- const body = node.childForFieldName("body");
333
- if (body) {
334
- for (let c = 0; c < body.childCount; c++) {
335
- const member = body.child(c);
336
- if (member?.type === "method_definition" || member?.type === "public_field_definition") {
337
- const methodName = member.childForFieldName("name");
338
- children.push({
339
- kind: "method",
340
- name: methodName?.text ?? "unknown",
341
- detail: extractSignatureLine(member, "method", langName),
342
- startLine: member.startPosition.row + 1,
343
- endLine: member.endPosition.row + 1,
344
- });
345
- }
346
- }
347
- }
348
- sigs.push({
349
- kind: "class",
350
- name,
351
- detail: extractSignatureLine(node, "class", langName),
352
- startLine: node.startPosition.row + 1,
353
- endLine: node.endPosition.row + 1,
354
- children,
355
- });
356
- return sigs;
357
- }
358
- // TypeScript-specific
359
- if (langName === "typescript") {
360
- if (type === "interface_declaration") {
361
- const nameNode = node.childForFieldName("name");
362
- sigs.push({
363
- kind: "interface",
364
- name: nameNode?.text ?? "unknown",
365
- detail: extractSignatureLine(node, "interface", langName),
366
- startLine: node.startPosition.row + 1,
367
- endLine: node.endPosition.row + 1,
368
- });
369
- return sigs;
370
- }
371
- if (type === "type_alias_declaration") {
372
- const nameNode = node.childForFieldName("name");
373
- sigs.push({
374
- kind: "type",
375
- name: nameNode?.text ?? "unknown",
376
- detail: extractSignatureLine(node, "type", langName),
377
- startLine: node.startPosition.row + 1,
378
- endLine: node.endPosition.row + 1,
379
- });
380
- return sigs;
381
- }
382
- if (type === "enum_declaration") {
383
- const nameNode = node.childForFieldName("name");
384
- sigs.push({
385
- kind: "enum",
386
- name: nameNode?.text ?? "unknown",
387
- detail: extractSignatureLine(node, "enum", langName),
388
- startLine: node.startPosition.row + 1,
389
- endLine: node.endPosition.row + 1,
390
- });
391
- return sigs;
392
- }
393
- }
394
- // Export statement — unwrap and recurse into the declaration
395
- if (type === "export_statement") {
396
- for (let c = 0; c < node.childCount; c++) {
397
- const child = node.child(c);
398
- const childSigs = extractNodeSignatures(child, langName, depth);
399
- // Mark them as exported by prepending "export " to detail
400
- for (const s of childSigs) {
401
- if (!s.detail.startsWith("export")) {
402
- s.detail = "export " + s.detail;
403
- }
404
- s.kind = s.kind === "variable" ? "export" : s.kind;
405
- }
406
- sigs.push(...childSigs);
407
- }
408
- return sigs;
409
- }
410
- }
411
- // ── Python ──
412
- if (langName === "python") {
413
- if (type === "function_definition") {
414
- const nameNode = node.childForFieldName("name");
415
- const children = [];
416
- // Check for methods inside (nested functions)
417
- const body = node.childForFieldName("body");
418
- // Don't recurse into function bodies for top-level map
419
- sigs.push({
420
- kind: "function",
421
- name: nameNode?.text ?? "unknown",
422
- detail: extractSignatureLine(node, "function", langName),
423
- startLine: node.startPosition.row + 1,
424
- endLine: node.endPosition.row + 1,
425
- });
426
- return sigs;
427
- }
428
- if (type === "class_definition") {
429
- const nameNode = node.childForFieldName("name");
430
- const name = nameNode?.text ?? "unknown";
431
- const children = [];
432
- const body = node.childForFieldName("body");
433
- if (body) {
434
- for (let c = 0; c < body.childCount; c++) {
435
- const member = body.child(c);
436
- if (member?.type === "function_definition") {
437
- const methodName = member.childForFieldName("name");
438
- children.push({
439
- kind: "method",
440
- name: methodName?.text ?? "unknown",
441
- detail: extractSignatureLine(member, "method", langName),
442
- startLine: member.startPosition.row + 1,
443
- endLine: member.endPosition.row + 1,
444
- });
445
- }
446
- }
447
- }
448
- sigs.push({
449
- kind: "class",
450
- name,
451
- detail: extractSignatureLine(node, "class", langName),
452
- startLine: node.startPosition.row + 1,
453
- endLine: node.endPosition.row + 1,
454
- children,
455
- });
456
- return sigs;
457
- }
458
- if (type === "decorated_definition") {
459
- // Unwrap and process the inner definition
460
- for (let c = 0; c < node.childCount; c++) {
461
- const child = node.child(c);
462
- if (child.type === "function_definition" || child.type === "class_definition") {
463
- const innerSigs = extractNodeSignatures(child, langName, depth);
464
- sigs.push(...innerSigs);
465
- }
466
- }
467
- return sigs;
468
- }
469
- if (type === "expression_statement") {
470
- const assignment = node.child(0);
471
- if (assignment?.type === "assignment") {
472
- const left = assignment.childForFieldName("left");
473
- if (left?.type === "identifier") {
474
- sigs.push({
475
- kind: "variable",
476
- name: left.text,
477
- detail: extractSignatureLine(node, "variable", langName),
478
- startLine: node.startPosition.row + 1,
479
- endLine: node.endPosition.row + 1,
480
- });
481
- }
482
- }
483
- return sigs;
484
- }
485
- }
486
- // ── Go ──
487
- if (langName === "go") {
488
- if (type === "function_declaration") {
489
- const nameNode = node.childForFieldName("name");
490
- sigs.push({
491
- kind: "function",
492
- name: nameNode?.text ?? "unknown",
493
- detail: extractSignatureLine(node, "function", langName),
494
- startLine: node.startPosition.row + 1,
495
- endLine: node.endPosition.row + 1,
496
- });
497
- return sigs;
498
- }
499
- if (type === "method_declaration") {
500
- const nameNode = node.childForFieldName("name");
501
- const receiverNode = node.childForFieldName("receiver");
502
- const receiverText = receiverNode ? `(${receiverNode.text}) ` : "";
503
- sigs.push({
504
- kind: "method",
505
- name: nameNode?.text ?? "unknown",
506
- detail: extractSignatureLine(node, "method", langName),
507
- startLine: node.startPosition.row + 1,
508
- endLine: node.endPosition.row + 1,
509
- });
510
- return sigs;
511
- }
512
- if (type === "type_declaration") {
513
- for (let c = 0; c < node.childCount; c++) {
514
- const spec = node.child(c);
515
- if (spec?.type === "type_spec") {
516
- const nameNode = spec.childForFieldName("name");
517
- const typeNode = spec.childForFieldName("type");
518
- const typeName = typeNode?.type ?? "";
519
- const kind = typeName === "struct_type" ? "struct"
520
- : typeName === "interface_type" ? "interface"
521
- : "type";
522
- const children = [];
523
- // Extract struct fields or interface methods
524
- if (typeNode && (typeName === "struct_type" || typeName === "interface_type")) {
525
- const fieldList = typeNode.child(1); // The field list between braces
526
- if (fieldList) {
527
- for (let f = 0; f < fieldList.childCount; f++) {
528
- const field = fieldList.child(f);
529
- if (field && field.type !== "{" && field.type !== "}" && field.type !== ",") {
530
- const fieldText = field.text.split("\n")[0].trim();
531
- if (fieldText) {
532
- children.push({
533
- kind: typeName === "interface_type" ? "method" : "variable",
534
- name: fieldText.split(/\s+/)[0],
535
- detail: fieldText,
536
- startLine: field.startPosition.row + 1,
537
- endLine: field.endPosition.row + 1,
538
- });
539
- }
540
- }
541
- }
542
- }
543
- }
544
- sigs.push({
545
- kind,
546
- name: nameNode?.text ?? "unknown",
547
- detail: extractSignatureLine(node, kind, langName),
548
- startLine: node.startPosition.row + 1,
549
- endLine: node.endPosition.row + 1,
550
- children: children.length > 0 ? children : undefined,
551
- });
552
- }
553
- }
554
- return sigs;
555
- }
556
- if (type === "package_clause") {
557
- const nameNode = node.child(1);
558
- sigs.push({
559
- kind: "package",
560
- name: nameNode?.text ?? "unknown",
561
- detail: node.text,
562
- startLine: node.startPosition.row + 1,
563
- endLine: node.endPosition.row + 1,
564
- });
565
- return sigs;
566
- }
567
- if (type === "const_declaration" || type === "var_declaration") {
568
- sigs.push({
569
- kind: "const",
570
- name: "",
571
- detail: extractSignatureLine(node, "const", langName),
572
- startLine: node.startPosition.row + 1,
573
- endLine: node.endPosition.row + 1,
574
- });
575
- return sigs;
576
- }
577
- }
578
- // ── Rust ──
579
- if (langName === "rust") {
580
- if (type === "function_item") {
581
- const nameNode = node.childForFieldName("name");
582
- sigs.push({
583
- kind: "function",
584
- name: nameNode?.text ?? "unknown",
585
- detail: extractSignatureLine(node, "function", langName),
586
- startLine: node.startPosition.row + 1,
587
- endLine: node.endPosition.row + 1,
588
- });
589
- return sigs;
590
- }
591
- if (type === "struct_item") {
592
- const nameNode = node.childForFieldName("name");
593
- sigs.push({
594
- kind: "struct",
595
- name: nameNode?.text ?? "unknown",
596
- detail: extractSignatureLine(node, "struct", langName),
597
- startLine: node.startPosition.row + 1,
598
- endLine: node.endPosition.row + 1,
599
- });
600
- return sigs;
601
- }
602
- if (type === "enum_item") {
603
- const nameNode = node.childForFieldName("name");
604
- sigs.push({
605
- kind: "enum",
606
- name: nameNode?.text ?? "unknown",
607
- detail: extractSignatureLine(node, "enum", langName),
608
- startLine: node.startPosition.row + 1,
609
- endLine: node.endPosition.row + 1,
610
- });
611
- return sigs;
612
- }
613
- if (type === "trait_item") {
614
- const nameNode = node.childForFieldName("name");
615
- const children = [];
616
- const body = node.childForFieldName("body");
617
- if (body) {
618
- for (let c = 0; c < body.childCount; c++) {
619
- const member = body.child(c);
620
- if (member?.type === "function_item") {
621
- const methodName = member.childForFieldName("name");
622
- children.push({
623
- kind: "method",
624
- name: methodName?.text ?? "unknown",
625
- detail: extractSignatureLine(member, "method", langName),
626
- startLine: member.startPosition.row + 1,
627
- endLine: member.endPosition.row + 1,
628
- });
629
- }
630
- }
631
- }
632
- sigs.push({
633
- kind: "trait",
634
- name: nameNode?.text ?? "unknown",
635
- detail: extractSignatureLine(node, "trait", langName),
636
- startLine: node.startPosition.row + 1,
637
- endLine: node.endPosition.row + 1,
638
- children: children.length > 0 ? children : undefined,
639
- });
640
- return sigs;
641
- }
642
- if (type === "impl_item") {
643
- const typeNode = node.childForFieldName("type");
644
- const traitNode = node.childForFieldName("trait");
645
- const name = traitNode
646
- ? `${traitNode.text} for ${typeNode?.text ?? "?"}`
647
- : typeNode?.text ?? "unknown";
648
- const children = [];
649
- const body = node.childForFieldName("body");
650
- if (body) {
651
- for (let c = 0; c < body.childCount; c++) {
652
- const member = body.child(c);
653
- if (member?.type === "function_item") {
654
- const methodName = member.childForFieldName("name");
655
- children.push({
656
- kind: "method",
657
- name: methodName?.text ?? "unknown",
658
- detail: extractSignatureLine(member, "method", langName),
659
- startLine: member.startPosition.row + 1,
660
- endLine: member.endPosition.row + 1,
661
- });
662
- }
663
- }
664
- }
665
- sigs.push({
666
- kind: "impl",
667
- name,
668
- detail: extractSignatureLine(node, "impl", langName),
669
- startLine: node.startPosition.row + 1,
670
- endLine: node.endPosition.row + 1,
671
- children: children.length > 0 ? children : undefined,
672
- });
673
- return sigs;
674
- }
675
- if (type === "type_item") {
676
- const nameNode = node.childForFieldName("name");
677
- sigs.push({
678
- kind: "type",
679
- name: nameNode?.text ?? "unknown",
680
- detail: extractSignatureLine(node, "type", langName),
681
- startLine: node.startPosition.row + 1,
682
- endLine: node.endPosition.row + 1,
683
- });
684
- return sigs;
685
- }
686
- if (type === "const_item" || type === "static_item") {
687
- const nameNode = node.childForFieldName("name");
688
- sigs.push({
689
- kind: "const",
690
- name: nameNode?.text ?? "unknown",
691
- detail: extractSignatureLine(node, "const", langName),
692
- startLine: node.startPosition.row + 1,
693
- endLine: node.endPosition.row + 1,
694
- });
695
- return sigs;
696
- }
697
- if (type === "mod_item") {
698
- const nameNode = node.childForFieldName("name");
699
- sigs.push({
700
- kind: "module",
701
- name: nameNode?.text ?? "unknown",
702
- detail: extractSignatureLine(node, "module", langName),
703
- startLine: node.startPosition.row + 1,
704
- endLine: node.endPosition.row + 1,
705
- });
706
- return sigs;
707
- }
708
- }
709
- return sigs;
710
- }