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