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

Method createNode

src/extraction/tree-sitter.ts:2121–2196  ·  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

2119 * Create a Node object
2120 */
2121 private createNode(
2122 kind: NodeKind,
2123 name: string,
2124 node: SyntaxNode,
2125 extra?: Partial<Node>,
2126 // False for a value no other scope names by this name — a local, or an
2127 // object hung on a dotted path (see captureValueRefScope).
2128 valueTarget = true
2129 ): Node | null {
2130 // Skip nodes with empty/missing names — they are not meaningful symbols
2131 // and would cause FK violations when edges reference them (see issue #42)
2132 if (!name) {
2133 return null;
2134 }
2135
2136 const id = this.nodeIds.generate(this.filePath, kind, name, node.startPosition.row + 1, node.startPosition.column);
2137
2138 // Some grammars (e.g. Dart) model a function/method body as a *sibling* of
2139 // the signature node, so the declaration node's own range is just the
2140 // signature line. Extend endLine to the resolved body when it sits beyond
2141 // the node so the node spans its body — required for any body-level analysis
2142 // (callees, the callback synthesizer's body scan, context slices). Guarded to
2143 // only ever extend: for child-body grammars the body is within range (no-op).
2144 let endLine = node.endPosition.row + 1;
2145 if (kind === 'function' || kind === 'method') {
2146 const body = this.extractor?.resolveBody?.(node, this.extractor.bodyField);
2147 if (body && body.endPosition.row + 1 > endLine) {
2148 endLine = body.endPosition.row + 1;
2149 }
2150 }
2151
2152 const newNode: Node = {
2153 id,
2154 kind,
2155 name,
2156 qualifiedName: this.buildQualifiedName(name),
2157 filePath: this.filePath,
2158 language: this.language,
2159 startLine: node.startPosition.row + 1,
2160 endLine,
2161 startColumn: node.startPosition.column,
2162 endColumn: node.endPosition.column,
2163 updatedAt: Date.now(),
2164 ...extra,
2165 };
2166
2167 // Persist extra symbol-level modifiers (e.g. Kotlin `expect`/`actual`) onto
2168 // the node's decorators list so the resolver can pair multiplatform
2169 // declarations with their implementations. Merged, not overwritten, so a
2170 // language that also captures real annotations keeps both.
2171 const mods = this.extractor?.extractModifiers?.(node);
2172 if (mods && mods.length > 0) {
2173 newNode.decorators = [...(newNode.decorators ?? []), ...mods];
2174 }
2175
2176 this.nodes.push(newNode);
2177
2178 // 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

Calls 6

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

Tested by

no test coverage detected