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