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

Function extractClassMembers

src/extraction/languages/r.ts:110–163  ·  view source on GitHub ↗

* Extract a class call's methods. Two shapes: * - inside list() arguments — R5 `methods = list(deposit = function(x) …)`, * R6 `public = list(…)` / `private = list(…)`; * - DIRECT named function arguments — ggproto's style: * `ggproto("GeomPoint", Geom, draw_panel = function(…) …)`. * A

(classCall: SyntaxNode, classId: string, ctx: ExtractorContext)

Source from the content-addressed store, hash-verified

108 * `contains = "Parent"`.
109 */
110function extractClassMembers(classCall: SyntaxNode, classId: string, ctx: ExtractorContext): void {
111 const args = getChildByField(classCall, 'arguments');
112 if (!args) return;
113 let positional = 0;
114 for (let i = 0; i < args.namedChildCount; i++) {
115 const arg = args.namedChild(i);
116 if (arg?.type !== 'argument') continue;
117 const argName = getChildByField(arg, 'name');
118 const value = getChildByField(arg, 'value');
119 if (!argName) {
120 positional++;
121 // ggproto("Name", Parent, …) — the 2nd positional identifier is the parent.
122 if (positional === 2 && value?.type === 'identifier') {
123 ctx.addUnresolvedReference({
124 fromNodeId: classId,
125 referenceName: getNodeText(value, ctx.source),
126 referenceKind: 'extends',
127 line: value.startPosition.row + 1,
128 column: value.startPosition.column,
129 });
130 }
131 continue;
132 }
133 const argNameText = getNodeText(argName, ctx.source);
134 // R6 `inherit = Parent` / S4 `contains = "Parent"`.
135 if ((argNameText === 'inherit' || argNameText === 'contains') && value) {
136 const parent = literalOrIdentifier(value, ctx.source);
137 if (parent) {
138 ctx.addUnresolvedReference({
139 fromNodeId: classId,
140 referenceName: parent,
141 referenceKind: 'extends',
142 line: value.startPosition.row + 1,
143 column: value.startPosition.column,
144 });
145 }
146 continue;
147 }
148 // Direct named function argument (ggproto methods).
149 if (value?.type === 'function_definition') {
150 emitMethodArg(arg, ctx);
151 continue;
152 }
153 // list(…) of named function arguments (R5/R6 methods).
154 if (value?.type === 'call' && calleeName(value, ctx.source) === 'list') {
155 const listArgs = getChildByField(value, 'arguments');
156 if (!listArgs) continue;
157 for (let j = 0; j < listArgs.namedChildCount; j++) {
158 const entry = listArgs.namedChild(j);
159 if (entry?.type === 'argument') emitMethodArg(entry, ctx);
160 }
161 }
162 }
163}
164
165export const rExtractor: LanguageExtractor = {
166 functionTypes: [], // named functions are assignments — handled in visitNode

Callers 1

r.tsFile · 0.85

Calls 6

getChildByFieldFunction · 0.90
getNodeTextFunction · 0.90
literalOrIdentifierFunction · 0.85
emitMethodArgFunction · 0.85
calleeNameFunction · 0.85

Tested by

no test coverage detected