MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / createNode

Method createNode

src/extraction/tree-sitter.ts:2089–2161  ·  view source on GitHub ↗

* Create a Node object

(
    kind: NodeKind,
    name: string,
    node: SyntaxNode,
    extra?: Partial<Node>,
    // False for a value no other scope names by this name — a local, or an
    // object hung on a dotted path (see captureValueRefScope).
    valueTarget = true
  )

Source from the content-addressed store, hash-verified

2087 * Create a Node object
2088 */
2089 private createNode(
2090 kind: NodeKind,
2091 name: string,
2092 node: SyntaxNode,
2093 extra?: Partial<Node>,
2094 // False for a value no other scope names by this name — a local, or an
2095 // object hung on a dotted path (see captureValueRefScope).
2096 valueTarget = true
2097 ): Node | null {
2098 // Skip nodes with empty/missing names — they are not meaningful symbols
2099 // and would cause FK violations when edges reference them (see issue #42)
2100 if (!name) {
2101 return null;
2102 }
2103
2104 const id = this.nodeIds.generate(this.filePath, kind, name, node.startPosition.row + 1, node.startPosition.column);
2105
2106 // Some grammars (e.g. Dart) model a function/method body as a *sibling* of
2107 // the signature node, so the declaration node's own range is just the
2108 // signature line. Extend endLine to the resolved body when it sits beyond
2109 // the node so the node spans its body — required for any body-level analysis
2110 // (callees, the callback synthesizer's body scan, context slices). Guarded to
2111 // only ever extend: for child-body grammars the body is within range (no-op).
2112 let endLine = node.endPosition.row + 1;
2113 if (kind === 'function' || kind === 'method') {
2114 const body = this.extractor?.resolveBody?.(node, this.extractor.bodyField);
2115 if (body && body.endPosition.row + 1 > endLine) {
2116 endLine = body.endPosition.row + 1;
2117 }
2118 }
2119
2120 const newNode: Node = {
2121 id,
2122 kind,
2123 name,
2124 qualifiedName: this.buildQualifiedName(name),
2125 filePath: this.filePath,
2126 language: this.language,
2127 startLine: node.startPosition.row + 1,
2128 endLine,
2129 startColumn: node.startPosition.column,
2130 endColumn: node.endPosition.column,
2131 updatedAt: Date.now(),
2132 ...extra,
2133 };
2134
2135 // Persist extra symbol-level modifiers (e.g. Kotlin `expect`/`actual`) onto
2136 // the node's decorators list so the resolver can pair multiplatform
2137 // declarations with their implementations. Merged, not overwritten, so a
2138 // language that also captures real annotations keeps both.
2139 const mods = this.extractor?.extractModifiers?.(node);
2140 if (mods && mods.length > 0) {
2141 newNode.decorators = [...(newNode.decorators ?? []), ...mods];
2142 }
2143
2144 this.nodes.push(newNode);
2145
2146 // Add containment edge from parent

Callers 15

dispatchNodeMethod · 0.95
extractFilePackageMethod · 0.95
extractFunctionMethod · 0.95
extractClassMethod · 0.95
extractMethodMethod · 0.95
extractInterfaceMethod · 0.95
extractAggregateMethod · 0.95
extractEnumMethod · 0.95
extractEnumMembersMethod · 0.95
extractPropertyMethod · 0.95
extractFieldMethod · 0.95

Calls 4

buildQualifiedNameMethod · 0.95
captureValueRefScopeMethod · 0.95
pushMethod · 0.80
generateMethod · 0.45

Tested by

no test coverage detected