@saluzi/codegraph 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.
Files changed (189) hide show
  1. package/dist/bin/codegraph.d.ts +25 -0
  2. package/dist/bin/node-version-check.d.ts +37 -0
  3. package/dist/bin/uninstall.d.ts +14 -0
  4. package/dist/context/formatter.d.ts +33 -0
  5. package/dist/context/formatter.js +244 -0
  6. package/dist/context/index.d.ts +117 -0
  7. package/dist/context/index.js +1050 -0
  8. package/dist/db/index.d.ts +101 -0
  9. package/dist/db/index.js +250 -0
  10. package/dist/db/migrations.d.ts +47 -0
  11. package/dist/db/migrations.js +131 -0
  12. package/dist/db/queries.d.ts +291 -0
  13. package/dist/db/queries.js +1349 -0
  14. package/dist/db/schema.sql +151 -0
  15. package/dist/db/sqlite-adapter.d.ts +49 -0
  16. package/dist/db/sqlite-adapter.js +141 -0
  17. package/dist/directory.d.ts +62 -0
  18. package/dist/directory.js +264 -0
  19. package/dist/errors.d.ts +149 -0
  20. package/dist/errors.js +219 -0
  21. package/dist/extraction/dfm-extractor.d.ts +31 -0
  22. package/dist/extraction/dfm-extractor.js +151 -0
  23. package/dist/extraction/grammars.d.ts +94 -0
  24. package/dist/extraction/grammars.js +357 -0
  25. package/dist/extraction/index.d.ts +148 -0
  26. package/dist/extraction/index.js +1286 -0
  27. package/dist/extraction/languages/c-cpp.d.ts +4 -0
  28. package/dist/extraction/languages/c-cpp.js +126 -0
  29. package/dist/extraction/languages/csharp.d.ts +3 -0
  30. package/dist/extraction/languages/csharp.js +72 -0
  31. package/dist/extraction/languages/dart.d.ts +3 -0
  32. package/dist/extraction/languages/dart.js +192 -0
  33. package/dist/extraction/languages/go.d.ts +3 -0
  34. package/dist/extraction/languages/go.js +58 -0
  35. package/dist/extraction/languages/index.d.ts +10 -0
  36. package/dist/extraction/languages/index.js +49 -0
  37. package/dist/extraction/languages/java.d.ts +3 -0
  38. package/dist/extraction/languages/java.js +64 -0
  39. package/dist/extraction/languages/javascript.d.ts +3 -0
  40. package/dist/extraction/languages/javascript.js +90 -0
  41. package/dist/extraction/languages/kotlin.d.ts +3 -0
  42. package/dist/extraction/languages/kotlin.js +253 -0
  43. package/dist/extraction/languages/lua.d.ts +3 -0
  44. package/dist/extraction/languages/lua.js +150 -0
  45. package/dist/extraction/languages/luau.d.ts +3 -0
  46. package/dist/extraction/languages/luau.js +37 -0
  47. package/dist/extraction/languages/pascal.d.ts +3 -0
  48. package/dist/extraction/languages/pascal.js +66 -0
  49. package/dist/extraction/languages/php.d.ts +3 -0
  50. package/dist/extraction/languages/php.js +107 -0
  51. package/dist/extraction/languages/python.d.ts +3 -0
  52. package/dist/extraction/languages/python.js +56 -0
  53. package/dist/extraction/languages/ruby.d.ts +3 -0
  54. package/dist/extraction/languages/ruby.js +114 -0
  55. package/dist/extraction/languages/rust.d.ts +3 -0
  56. package/dist/extraction/languages/rust.js +109 -0
  57. package/dist/extraction/languages/scala.d.ts +3 -0
  58. package/dist/extraction/languages/scala.js +139 -0
  59. package/dist/extraction/languages/swift.d.ts +3 -0
  60. package/dist/extraction/languages/swift.js +91 -0
  61. package/dist/extraction/languages/typescript.d.ts +3 -0
  62. package/dist/extraction/languages/typescript.js +129 -0
  63. package/dist/extraction/liquid-extractor.d.ts +52 -0
  64. package/dist/extraction/liquid-extractor.js +313 -0
  65. package/dist/extraction/parse-worker.d.ts +8 -0
  66. package/dist/extraction/parse-worker.js +94 -0
  67. package/dist/extraction/svelte-extractor.d.ts +56 -0
  68. package/dist/extraction/svelte-extractor.js +272 -0
  69. package/dist/extraction/tree-sitter-helpers.d.ts +39 -0
  70. package/dist/extraction/tree-sitter-helpers.js +103 -0
  71. package/dist/extraction/tree-sitter-types.d.ts +191 -0
  72. package/dist/extraction/tree-sitter-types.js +10 -0
  73. package/dist/extraction/tree-sitter.d.ts +238 -0
  74. package/dist/extraction/tree-sitter.js +2430 -0
  75. package/dist/extraction/vue-extractor.d.ts +36 -0
  76. package/dist/extraction/vue-extractor.js +163 -0
  77. package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  78. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  79. package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  80. package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  81. package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  82. package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  83. package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  84. package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  85. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  86. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  87. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  88. package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  89. package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  90. package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  91. package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  92. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  93. package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  94. package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  95. package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  96. package/dist/extraction/wasm-runtime-flags.d.ts +46 -0
  97. package/dist/extraction/wasm-runtime-flags.js +105 -0
  98. package/dist/graph/index.d.ts +8 -0
  99. package/dist/graph/index.js +13 -0
  100. package/dist/graph/queries.d.ts +109 -0
  101. package/dist/graph/queries.js +366 -0
  102. package/dist/graph/traversal.d.ts +137 -0
  103. package/dist/graph/traversal.js +528 -0
  104. package/dist/index.d.ts +509 -0
  105. package/dist/index.js +800 -0
  106. package/dist/installer/claude-md-template.d.ts +19 -0
  107. package/dist/installer/config-writer.d.ts +29 -0
  108. package/dist/installer/index.d.ts +140 -0
  109. package/dist/installer/instructions-template.d.ts +30 -0
  110. package/dist/installer/targets/claude.d.ts +55 -0
  111. package/dist/installer/targets/codex.d.ts +18 -0
  112. package/dist/installer/targets/cursor.d.ts +35 -0
  113. package/dist/installer/targets/hermes.d.ts +18 -0
  114. package/dist/installer/targets/opencode.d.ts +30 -0
  115. package/dist/installer/targets/registry.d.ts +38 -0
  116. package/dist/installer/targets/shared.d.ts +92 -0
  117. package/dist/installer/targets/toml.d.ts +64 -0
  118. package/dist/installer/targets/types.d.ts +122 -0
  119. package/dist/mcp/index.d.ts +98 -0
  120. package/dist/mcp/server-instructions.d.ts +20 -0
  121. package/dist/mcp/tools.d.ts +269 -0
  122. package/dist/mcp/transport.d.ts +117 -0
  123. package/dist/resolution/frameworks/cargo-workspace.d.ts +20 -0
  124. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  125. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  126. package/dist/resolution/frameworks/csharp.js +213 -0
  127. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  128. package/dist/resolution/frameworks/drupal.js +335 -0
  129. package/dist/resolution/frameworks/express.d.ts +8 -0
  130. package/dist/resolution/frameworks/express.js +225 -0
  131. package/dist/resolution/frameworks/go.d.ts +8 -0
  132. package/dist/resolution/frameworks/go.js +158 -0
  133. package/dist/resolution/frameworks/index.d.ts +52 -0
  134. package/dist/resolution/frameworks/index.js +137 -0
  135. package/dist/resolution/frameworks/java.d.ts +8 -0
  136. package/dist/resolution/frameworks/java.js +177 -0
  137. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  138. package/dist/resolution/frameworks/laravel.js +248 -0
  139. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  140. package/dist/resolution/frameworks/nestjs.js +374 -0
  141. package/dist/resolution/frameworks/python.d.ts +10 -0
  142. package/dist/resolution/frameworks/python.js +278 -0
  143. package/dist/resolution/frameworks/react.d.ts +8 -0
  144. package/dist/resolution/frameworks/react.js +272 -0
  145. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  146. package/dist/resolution/frameworks/ruby.js +198 -0
  147. package/dist/resolution/frameworks/rust.d.ts +8 -0
  148. package/dist/resolution/frameworks/rust.js +207 -0
  149. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  150. package/dist/resolution/frameworks/svelte.js +249 -0
  151. package/dist/resolution/frameworks/swift.d.ts +10 -0
  152. package/dist/resolution/frameworks/swift.js +376 -0
  153. package/dist/resolution/frameworks/vue.d.ts +9 -0
  154. package/dist/resolution/frameworks/vue.js +306 -0
  155. package/dist/resolution/import-resolver.d.ts +61 -0
  156. package/dist/resolution/import-resolver.js +663 -0
  157. package/dist/resolution/index.d.ts +118 -0
  158. package/dist/resolution/index.js +744 -0
  159. package/dist/resolution/lru-cache.d.ts +24 -0
  160. package/dist/resolution/lru-cache.js +62 -0
  161. package/dist/resolution/name-matcher.d.ts +50 -0
  162. package/dist/resolution/name-matcher.js +384 -0
  163. package/dist/resolution/path-aliases.d.ts +72 -0
  164. package/dist/resolution/path-aliases.js +238 -0
  165. package/dist/resolution/strip-comments.d.ts +40 -0
  166. package/dist/resolution/strip-comments.js +441 -0
  167. package/dist/resolution/types.d.ts +181 -0
  168. package/dist/resolution/types.js +8 -0
  169. package/dist/search/query-parser.d.ts +61 -0
  170. package/dist/search/query-parser.js +177 -0
  171. package/dist/search/query-utils.d.ts +59 -0
  172. package/dist/search/query-utils.js +383 -0
  173. package/dist/sync/git-hooks.d.ts +54 -0
  174. package/dist/sync/git-hooks.js +223 -0
  175. package/dist/sync/index.d.ts +25 -0
  176. package/dist/sync/index.js +28 -0
  177. package/dist/sync/watch-policy.d.ts +51 -0
  178. package/dist/sync/watch-policy.js +124 -0
  179. package/dist/sync/watcher.d.ts +83 -0
  180. package/dist/sync/watcher.js +192 -0
  181. package/dist/types.d.ts +433 -0
  182. package/dist/types.js +75 -0
  183. package/dist/ui/glyphs.d.ts +42 -0
  184. package/dist/ui/shimmer-progress.d.ts +11 -0
  185. package/dist/ui/shimmer-worker.d.ts +2 -0
  186. package/dist/ui/types.d.ts +20 -0
  187. package/dist/utils.d.ts +231 -0
  188. package/dist/utils.js +549 -0
  189. package/package.json +24 -0
@@ -0,0 +1,149 @@
1
+ /**
2
+ * CodeGraph Error Classes
3
+ *
4
+ * Custom error types for better error handling and debugging.
5
+ *
6
+ * @module errors
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { FileError, ParseError, setLogger, silentLogger } from 'codegraph';
11
+ *
12
+ * // Catch specific error types
13
+ * try {
14
+ * await cg.indexAll();
15
+ * } catch (error) {
16
+ * if (error instanceof FileError) {
17
+ * console.log(`File error at ${error.filePath}: ${error.message}`);
18
+ * } else if (error instanceof ParseError) {
19
+ * console.log(`Parse error at ${error.filePath}:${error.line}`);
20
+ * }
21
+ * }
22
+ *
23
+ * // Disable logging for tests
24
+ * setLogger(silentLogger);
25
+ * ```
26
+ */
27
+ /**
28
+ * Base error class for all CodeGraph errors.
29
+ *
30
+ * All CodeGraph-specific errors extend this class, allowing you to catch
31
+ * all CodeGraph errors with a single catch block.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * try {
36
+ * await cg.indexAll();
37
+ * } catch (error) {
38
+ * if (error instanceof CodeGraphError) {
39
+ * console.log(`CodeGraph error [${error.code}]: ${error.message}`);
40
+ * }
41
+ * }
42
+ * ```
43
+ */
44
+ export declare class CodeGraphError extends Error {
45
+ /** Error code for categorization (e.g., 'FILE_ERROR', 'PARSE_ERROR') */
46
+ readonly code: string
47
+ /** Additional context about the error */
48
+ readonly context?: Record<string, unknown>
49
+ constructor(message: string, code: string, context?: Record<string, unknown>)
50
+ }
51
+ /**
52
+ * Error reading or accessing files
53
+ */
54
+ export declare class FileError extends CodeGraphError {
55
+ readonly filePath: string
56
+ constructor(message: string, filePath: string, cause?: Error)
57
+ }
58
+ /**
59
+ * Error parsing source code
60
+ */
61
+ export declare class ParseError extends CodeGraphError {
62
+ readonly filePath: string
63
+ readonly line?: number
64
+ readonly column?: number
65
+ constructor(
66
+ message: string,
67
+ filePath: string,
68
+ options?: {
69
+ line?: number
70
+ column?: number
71
+ cause?: Error
72
+ },
73
+ )
74
+ }
75
+ /**
76
+ * Error with database operations
77
+ */
78
+ export declare class DatabaseError extends CodeGraphError {
79
+ readonly operation: string
80
+ constructor(message: string, operation: string, cause?: Error)
81
+ }
82
+ /**
83
+ * Error with search operations
84
+ */
85
+ export declare class SearchError extends CodeGraphError {
86
+ readonly query: string
87
+ constructor(message: string, query: string, cause?: Error)
88
+ }
89
+ /**
90
+ * Error with vector/embedding operations
91
+ */
92
+ export declare class VectorError extends CodeGraphError {
93
+ constructor(message: string, operation: string, cause?: Error)
94
+ }
95
+ /**
96
+ * Error with configuration
97
+ */
98
+ export declare class ConfigError extends CodeGraphError {
99
+ constructor(message: string, details?: Record<string, unknown>)
100
+ }
101
+ /**
102
+ * Simple logger for CodeGraph operations
103
+ *
104
+ * By default, logs to console.warn for warnings and console.error for errors.
105
+ * Can be configured to use custom logging.
106
+ */
107
+ export interface Logger {
108
+ debug(message: string, context?: Record<string, unknown>): void
109
+ warn(message: string, context?: Record<string, unknown>): void
110
+ error(message: string, context?: Record<string, unknown>): void
111
+ }
112
+ /**
113
+ * Default console-based logger
114
+ */
115
+ export declare const defaultLogger: Logger
116
+ /**
117
+ * Silent logger (no output) - useful for tests
118
+ */
119
+ export declare const silentLogger: Logger
120
+ /**
121
+ * Set the global logger
122
+ */
123
+ export declare function setLogger(logger: Logger): void
124
+ /**
125
+ * Get the current logger
126
+ */
127
+ export declare function getLogger(): Logger
128
+ /**
129
+ * Log a debug message
130
+ */
131
+ export declare function logDebug(
132
+ message: string,
133
+ context?: Record<string, unknown>,
134
+ ): void
135
+ /**
136
+ * Log a warning message
137
+ */
138
+ export declare function logWarn(
139
+ message: string,
140
+ context?: Record<string, unknown>,
141
+ ): void
142
+ /**
143
+ * Log an error message
144
+ */
145
+ export declare function logError(
146
+ message: string,
147
+ context?: Record<string, unknown>,
148
+ ): void
149
+ //# sourceMappingURL=errors.d.ts.map
package/dist/errors.js ADDED
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ /**
3
+ * CodeGraph Error Classes
4
+ *
5
+ * Custom error types for better error handling and debugging.
6
+ *
7
+ * @module errors
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { FileError, ParseError, setLogger, silentLogger } from 'codegraph';
12
+ *
13
+ * // Catch specific error types
14
+ * try {
15
+ * await cg.indexAll();
16
+ * } catch (error) {
17
+ * if (error instanceof FileError) {
18
+ * console.log(`File error at ${error.filePath}: ${error.message}`);
19
+ * } else if (error instanceof ParseError) {
20
+ * console.log(`Parse error at ${error.filePath}:${error.line}`);
21
+ * }
22
+ * }
23
+ *
24
+ * // Disable logging for tests
25
+ * setLogger(silentLogger);
26
+ * ```
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.silentLogger = exports.defaultLogger = exports.ConfigError = exports.VectorError = exports.SearchError = exports.DatabaseError = exports.ParseError = exports.FileError = exports.CodeGraphError = void 0;
30
+ exports.setLogger = setLogger;
31
+ exports.getLogger = getLogger;
32
+ exports.logDebug = logDebug;
33
+ exports.logWarn = logWarn;
34
+ exports.logError = logError;
35
+ /**
36
+ * Base error class for all CodeGraph errors.
37
+ *
38
+ * All CodeGraph-specific errors extend this class, allowing you to catch
39
+ * all CodeGraph errors with a single catch block.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * try {
44
+ * await cg.indexAll();
45
+ * } catch (error) {
46
+ * if (error instanceof CodeGraphError) {
47
+ * console.log(`CodeGraph error [${error.code}]: ${error.message}`);
48
+ * }
49
+ * }
50
+ * ```
51
+ */
52
+ class CodeGraphError extends Error {
53
+ /** Error code for categorization (e.g., 'FILE_ERROR', 'PARSE_ERROR') */
54
+ code;
55
+ /** Additional context about the error */
56
+ context;
57
+ constructor(message, code, context) {
58
+ super(message);
59
+ this.name = 'CodeGraphError';
60
+ this.code = code;
61
+ this.context = context;
62
+ // Maintain proper stack trace for V8
63
+ if (Error.captureStackTrace) {
64
+ Error.captureStackTrace(this, this.constructor);
65
+ }
66
+ }
67
+ }
68
+ exports.CodeGraphError = CodeGraphError;
69
+ /**
70
+ * Error reading or accessing files
71
+ */
72
+ class FileError extends CodeGraphError {
73
+ filePath;
74
+ constructor(message, filePath, cause) {
75
+ super(message, 'FILE_ERROR', { filePath, cause: cause?.message });
76
+ this.name = 'FileError';
77
+ this.filePath = filePath;
78
+ if (cause) {
79
+ this.cause = cause;
80
+ }
81
+ }
82
+ }
83
+ exports.FileError = FileError;
84
+ /**
85
+ * Error parsing source code
86
+ */
87
+ class ParseError extends CodeGraphError {
88
+ filePath;
89
+ line;
90
+ column;
91
+ constructor(message, filePath, options) {
92
+ super(message, 'PARSE_ERROR', {
93
+ filePath,
94
+ line: options?.line,
95
+ column: options?.column,
96
+ cause: options?.cause?.message,
97
+ });
98
+ this.name = 'ParseError';
99
+ this.filePath = filePath;
100
+ this.line = options?.line;
101
+ this.column = options?.column;
102
+ if (options?.cause) {
103
+ this.cause = options.cause;
104
+ }
105
+ }
106
+ }
107
+ exports.ParseError = ParseError;
108
+ /**
109
+ * Error with database operations
110
+ */
111
+ class DatabaseError extends CodeGraphError {
112
+ operation;
113
+ constructor(message, operation, cause) {
114
+ super(message, 'DATABASE_ERROR', { operation, cause: cause?.message });
115
+ this.name = 'DatabaseError';
116
+ this.operation = operation;
117
+ if (cause) {
118
+ this.cause = cause;
119
+ }
120
+ }
121
+ }
122
+ exports.DatabaseError = DatabaseError;
123
+ /**
124
+ * Error with search operations
125
+ */
126
+ class SearchError extends CodeGraphError {
127
+ query;
128
+ constructor(message, query, cause) {
129
+ super(message, 'SEARCH_ERROR', { query, cause: cause?.message });
130
+ this.name = 'SearchError';
131
+ this.query = query;
132
+ if (cause) {
133
+ this.cause = cause;
134
+ }
135
+ }
136
+ }
137
+ exports.SearchError = SearchError;
138
+ /**
139
+ * Error with vector/embedding operations
140
+ */
141
+ class VectorError extends CodeGraphError {
142
+ constructor(message, operation, cause) {
143
+ super(message, 'VECTOR_ERROR', { operation, cause: cause?.message });
144
+ this.name = 'VectorError';
145
+ if (cause) {
146
+ this.cause = cause;
147
+ }
148
+ }
149
+ }
150
+ exports.VectorError = VectorError;
151
+ /**
152
+ * Error with configuration
153
+ */
154
+ class ConfigError extends CodeGraphError {
155
+ constructor(message, details) {
156
+ super(message, 'CONFIG_ERROR', details);
157
+ this.name = 'ConfigError';
158
+ }
159
+ }
160
+ exports.ConfigError = ConfigError;
161
+ /**
162
+ * Default console-based logger
163
+ */
164
+ exports.defaultLogger = {
165
+ debug(message, context) {
166
+ if (process.env.CODEGRAPH_DEBUG) {
167
+ console.debug(`[CodeGraph] ${message}`, context ?? '');
168
+ }
169
+ },
170
+ warn(message, context) {
171
+ console.warn(`[CodeGraph] ${message}`, context ?? '');
172
+ },
173
+ error(message, context) {
174
+ console.error(`[CodeGraph] ${message}`, context ?? '');
175
+ },
176
+ };
177
+ /**
178
+ * Silent logger (no output) - useful for tests
179
+ */
180
+ exports.silentLogger = {
181
+ debug() { },
182
+ warn() { },
183
+ error() { },
184
+ };
185
+ /**
186
+ * Current logger instance (can be replaced)
187
+ */
188
+ let currentLogger = exports.defaultLogger;
189
+ /**
190
+ * Set the global logger
191
+ */
192
+ function setLogger(logger) {
193
+ currentLogger = logger;
194
+ }
195
+ /**
196
+ * Get the current logger
197
+ */
198
+ function getLogger() {
199
+ return currentLogger;
200
+ }
201
+ /**
202
+ * Log a debug message
203
+ */
204
+ function logDebug(message, context) {
205
+ currentLogger.debug(message, context);
206
+ }
207
+ /**
208
+ * Log a warning message
209
+ */
210
+ function logWarn(message, context) {
211
+ currentLogger.warn(message, context);
212
+ }
213
+ /**
214
+ * Log an error message
215
+ */
216
+ function logError(message, context) {
217
+ currentLogger.error(message, context);
218
+ }
219
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,31 @@
1
+ import { ExtractionResult } from '../types'
2
+ /**
3
+ * Custom extractor for Delphi DFM/FMX form files.
4
+ *
5
+ * DFM/FMX files describe the visual component hierarchy and event handler
6
+ * bindings. They use a simple text format (object/end blocks) that we parse
7
+ * with regex — no tree-sitter grammar exists for this format.
8
+ *
9
+ * Extracted information:
10
+ * - Components as NodeKind `component`
11
+ * - Nesting as EdgeKind `contains`
12
+ * - Event handlers (OnClick = MethodName) as UnresolvedReference → EdgeKind `references`
13
+ */
14
+ export declare class DfmExtractor {
15
+ private filePath
16
+ private source
17
+ private nodes
18
+ private edges
19
+ private unresolvedReferences
20
+ private errors
21
+ constructor(filePath: string, source: string)
22
+ /**
23
+ * Extract components and event handler references from DFM/FMX source
24
+ */
25
+ extract(): ExtractionResult
26
+ /** Create a file node for the DFM form file */
27
+ private createFileNode
28
+ /** Parse object/end blocks and extract components + event handlers */
29
+ private parseComponents
30
+ }
31
+ //# sourceMappingURL=dfm-extractor.d.ts.map
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DfmExtractor = void 0;
4
+ const tree_sitter_helpers_1 = require("./tree-sitter-helpers");
5
+ /**
6
+ * Custom extractor for Delphi DFM/FMX form files.
7
+ *
8
+ * DFM/FMX files describe the visual component hierarchy and event handler
9
+ * bindings. They use a simple text format (object/end blocks) that we parse
10
+ * with regex — no tree-sitter grammar exists for this format.
11
+ *
12
+ * Extracted information:
13
+ * - Components as NodeKind `component`
14
+ * - Nesting as EdgeKind `contains`
15
+ * - Event handlers (OnClick = MethodName) as UnresolvedReference → EdgeKind `references`
16
+ */
17
+ class DfmExtractor {
18
+ filePath;
19
+ source;
20
+ nodes = [];
21
+ edges = [];
22
+ unresolvedReferences = [];
23
+ errors = [];
24
+ constructor(filePath, source) {
25
+ this.filePath = filePath;
26
+ this.source = source;
27
+ }
28
+ /**
29
+ * Extract components and event handler references from DFM/FMX source
30
+ */
31
+ extract() {
32
+ const startTime = Date.now();
33
+ try {
34
+ const fileNode = this.createFileNode();
35
+ this.parseComponents(fileNode.id);
36
+ }
37
+ catch (error) {
38
+ this.errors.push({
39
+ message: `DFM extraction error: ${error instanceof Error ? error.message : String(error)}`,
40
+ severity: 'error',
41
+ code: 'parse_error',
42
+ });
43
+ }
44
+ return {
45
+ nodes: this.nodes,
46
+ edges: this.edges,
47
+ unresolvedReferences: this.unresolvedReferences,
48
+ errors: this.errors,
49
+ durationMs: Date.now() - startTime,
50
+ };
51
+ }
52
+ /** Create a file node for the DFM form file */
53
+ createFileNode() {
54
+ const lines = this.source.split('\n');
55
+ const id = (0, tree_sitter_helpers_1.generateNodeId)(this.filePath, 'file', this.filePath, 1);
56
+ const fileNode = {
57
+ id,
58
+ kind: 'file',
59
+ name: this.filePath.split('/').pop() || this.filePath,
60
+ qualifiedName: this.filePath,
61
+ filePath: this.filePath,
62
+ language: 'pascal',
63
+ startLine: 1,
64
+ endLine: lines.length,
65
+ startColumn: 0,
66
+ endColumn: lines[lines.length - 1]?.length || 0,
67
+ updatedAt: Date.now(),
68
+ };
69
+ this.nodes.push(fileNode);
70
+ return fileNode;
71
+ }
72
+ /** Parse object/end blocks and extract components + event handlers */
73
+ parseComponents(fileNodeId) {
74
+ const lines = this.source.split('\n');
75
+ const stack = [fileNodeId];
76
+ const objectPattern = /^\s*(object|inherited|inline)\s+(\w+)\s*:\s*(\w+)/;
77
+ const eventPattern = /^\s*(On\w+)\s*=\s*(\w+)\s*$/;
78
+ const endPattern = /^\s*end\s*$/;
79
+ const multiLineStart = /=\s*\(\s*$/;
80
+ const multiLineItemStart = /=\s*<\s*$/;
81
+ let inMultiLine = false;
82
+ let multiLineEndChar = ')';
83
+ for (let i = 0; i < lines.length; i++) {
84
+ const line = lines[i];
85
+ const lineNum = i + 1;
86
+ // Skip multi-line properties
87
+ if (inMultiLine) {
88
+ if (line.trimEnd().endsWith(multiLineEndChar))
89
+ inMultiLine = false;
90
+ continue;
91
+ }
92
+ if (multiLineStart.test(line)) {
93
+ inMultiLine = true;
94
+ multiLineEndChar = ')';
95
+ continue;
96
+ }
97
+ if (multiLineItemStart.test(line)) {
98
+ inMultiLine = true;
99
+ multiLineEndChar = '>';
100
+ continue;
101
+ }
102
+ // Component declaration
103
+ const objMatch = line.match(objectPattern);
104
+ if (objMatch) {
105
+ const [, , name, typeName] = objMatch;
106
+ const nodeId = (0, tree_sitter_helpers_1.generateNodeId)(this.filePath, 'component', name, lineNum);
107
+ this.nodes.push({
108
+ id: nodeId,
109
+ kind: 'component',
110
+ name: name,
111
+ qualifiedName: `${this.filePath}#${name}`,
112
+ filePath: this.filePath,
113
+ language: 'pascal',
114
+ startLine: lineNum,
115
+ endLine: lineNum,
116
+ startColumn: 0,
117
+ endColumn: line.length,
118
+ signature: typeName,
119
+ updatedAt: Date.now(),
120
+ });
121
+ this.edges.push({
122
+ source: stack[stack.length - 1],
123
+ target: nodeId,
124
+ kind: 'contains',
125
+ });
126
+ stack.push(nodeId);
127
+ continue;
128
+ }
129
+ // Event handler
130
+ const eventMatch = line.match(eventPattern);
131
+ if (eventMatch) {
132
+ const [, , methodName] = eventMatch;
133
+ this.unresolvedReferences.push({
134
+ fromNodeId: stack[stack.length - 1],
135
+ referenceName: methodName,
136
+ referenceKind: 'references',
137
+ line: lineNum,
138
+ column: 0,
139
+ });
140
+ continue;
141
+ }
142
+ // Block end
143
+ if (endPattern.test(line)) {
144
+ if (stack.length > 1)
145
+ stack.pop();
146
+ }
147
+ }
148
+ }
149
+ }
150
+ exports.DfmExtractor = DfmExtractor;
151
+ //# sourceMappingURL=dfm-extractor.js.map
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Grammar Loading and Caching
3
+ *
4
+ * Uses web-tree-sitter (WASM) for universal cross-platform support.
5
+ * Grammars are loaded lazily — only languages actually present in the project
6
+ * are compiled, keeping V8 WASM memory pressure low on large codebases.
7
+ */
8
+ import { Parser } from 'web-tree-sitter'
9
+ import { Language } from '../types'
10
+ export type GrammarLanguage = Exclude<
11
+ Language,
12
+ 'svelte' | 'vue' | 'liquid' | 'yaml' | 'twig' | 'unknown'
13
+ >
14
+ /**
15
+ * File extension to Language mapping
16
+ */
17
+ export declare const EXTENSION_MAP: Record<string, Language>
18
+ /**
19
+ * Whether a file is one CodeGraph can parse, based purely on its extension.
20
+ * This is the single source of truth for "should we index this file" — derived
21
+ * from EXTENSION_MAP so parser support and indexing selection never drift.
22
+ */
23
+ export declare function isSourceFile(filePath: string): boolean
24
+ /**
25
+ * Initialize the tree-sitter WASM runtime. Must be called before loading grammars.
26
+ * Does NOT load any grammar WASM files — use loadGrammarsForLanguages() for that.
27
+ * Idempotent — safe to call multiple times.
28
+ */
29
+ export declare function initGrammars(): Promise<void>
30
+ /**
31
+ * Load grammar WASM files for specific languages only.
32
+ * Skips languages that are already loaded or have no WASM grammar.
33
+ * Must be called after initGrammars().
34
+ */
35
+ export declare function loadGrammarsForLanguages(
36
+ languages: Language[],
37
+ ): Promise<void>
38
+ /**
39
+ * Load ALL grammar WASM files. Convenience function for tests and
40
+ * backward compatibility. Prefer loadGrammarsForLanguages() in production.
41
+ */
42
+ export declare function loadAllGrammars(): Promise<void>
43
+ /**
44
+ * Check if grammars have been initialized
45
+ */
46
+ export declare function isGrammarsInitialized(): boolean
47
+ /**
48
+ * Get a parser for the specified language.
49
+ * Returns synchronously from pre-loaded cache.
50
+ */
51
+ export declare function getParser(language: Language): Parser | null
52
+ /**
53
+ * Detect language from file extension
54
+ */
55
+ export declare function detectLanguage(
56
+ filePath: string,
57
+ source?: string,
58
+ ): Language
59
+ /**
60
+ * Check if a language is supported (has a grammar defined).
61
+ * Returns true if the grammar exists, even if not yet loaded.
62
+ */
63
+ export declare function isLanguageSupported(language: Language): boolean
64
+ /**
65
+ * Check if a grammar has been loaded and is ready for parsing.
66
+ */
67
+ export declare function isGrammarLoaded(language: Language): boolean
68
+ /**
69
+ * Get all supported languages (those with grammar definitions).
70
+ */
71
+ export declare function getSupportedLanguages(): Language[]
72
+ /**
73
+ * Reset the cached parser for a language to reclaim WASM heap memory.
74
+ * The tree-sitter WASM runtime accumulates fragmented memory over thousands
75
+ * of parses. Deleting and recreating the Parser instance forces the WASM
76
+ * heap to reset, preventing "memory access out of bounds" crashes in
77
+ * large repos.
78
+ */
79
+ export declare function resetParser(language: Language): void
80
+ /**
81
+ * Clear parser/grammar caches (useful for testing)
82
+ */
83
+ export declare function clearParserCache(): void
84
+ /**
85
+ * Report grammars that failed to load.
86
+ */
87
+ export declare function getUnavailableGrammarErrors(): Partial<
88
+ Record<Language, string>
89
+ >
90
+ /**
91
+ * Get language display name
92
+ */
93
+ export declare function getLanguageDisplayName(language: Language): string
94
+ //# sourceMappingURL=grammars.d.ts.map