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

Function extractClassMembers

src/extraction/languages/r.ts:108–159  ·  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

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