* Create a Node object
(
kind: NodeKind,
name: string,
node: SyntaxNode,
extra?: Partial<Node>
)
| 1312 | * Create a Node object |
| 1313 | */ |
| 1314 | private createNode( |
| 1315 | kind: NodeKind, |
| 1316 | name: string, |
| 1317 | node: SyntaxNode, |
| 1318 | extra?: Partial<Node> |
| 1319 | ): Node | null { |
| 1320 | // Skip nodes with empty/missing names — they are not meaningful symbols |
| 1321 | // and would cause FK violations when edges reference them (see issue #42) |
| 1322 | if (!name) { |
| 1323 | return null; |
| 1324 | } |
| 1325 | |
| 1326 | const id = generateNodeId(this.filePath, kind, name, node.startPosition.row + 1); |
| 1327 | |
| 1328 | // Some grammars (e.g. Dart) model a function/method body as a *sibling* of |
| 1329 | // the signature node, so the declaration node's own range is just the |
| 1330 | // signature line. Extend endLine to the resolved body when it sits beyond |
| 1331 | // the node so the node spans its body — required for any body-level analysis |
| 1332 | // (callees, the callback synthesizer's body scan, context slices). Guarded to |
| 1333 | // only ever extend: for child-body grammars the body is within range (no-op). |
| 1334 | let endLine = node.endPosition.row + 1; |
| 1335 | if (kind === 'function' || kind === 'method') { |
| 1336 | const body = this.extractor?.resolveBody?.(node, this.extractor.bodyField); |
| 1337 | if (body && body.endPosition.row + 1 > endLine) { |
| 1338 | endLine = body.endPosition.row + 1; |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | const newNode: Node = { |
| 1343 | id, |
| 1344 | kind, |
| 1345 | name, |
| 1346 | qualifiedName: this.buildQualifiedName(name), |
| 1347 | filePath: this.filePath, |
| 1348 | language: this.language, |
| 1349 | startLine: node.startPosition.row + 1, |
| 1350 | endLine, |
| 1351 | startColumn: node.startPosition.column, |
| 1352 | endColumn: node.endPosition.column, |
| 1353 | updatedAt: Date.now(), |
| 1354 | ...extra, |
| 1355 | }; |
| 1356 | |
| 1357 | // Persist extra symbol-level modifiers (e.g. Kotlin `expect`/`actual`) onto |
| 1358 | // the node's decorators list so the resolver can pair multiplatform |
| 1359 | // declarations with their implementations. Merged, not overwritten, so a |
| 1360 | // language that also captures real annotations keeps both. |
| 1361 | const mods = this.extractor?.extractModifiers?.(node); |
| 1362 | if (mods && mods.length > 0) { |
| 1363 | newNode.decorators = [...(newNode.decorators ?? []), ...mods]; |
| 1364 | } |
| 1365 | |
| 1366 | this.nodes.push(newNode); |
| 1367 | |
| 1368 | // Add containment edge from parent |
| 1369 | if (this.nodeStack.length > 0) { |
| 1370 | const parentId = this.nodeStack[this.nodeStack.length - 1]; |
| 1371 | if (parentId) { |
no test coverage detected