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

Method maybe_capture_fn_refs

codegraph-kernel/src/go.rs:1165–1230  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1163 // --- fn refs (GO_SPEC, with the literal_element/expression_list layers) --------
1164
1165 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1166 let (mode, field): (&str, &str) = match node.kind() {
1167 "argument_list" => ("args", ""),
1168 "assignment_statement" => ("rhs", "right"),
1169 "short_var_declaration" => ("rhs", "right"),
1170 "var_spec" => ("varinit", "value"),
1171 "keyed_element" => ("value", ""), // value = LAST named child
1172 "literal_value" => ("list", ""),
1173 _ => return,
1174 };
1175 if self.stack.is_empty() {
1176 return;
1177 }
1178 let from = self.top_row();
1179
1180 let mut values: Vec<Node> = Vec::new();
1181 match mode {
1182 "args" | "list" => {
1183 for i in 0..node.named_child_count() {
1184 if let Some(c) = node.named_child(i) {
1185 values.push(c);
1186 }
1187 }
1188 }
1189 "rhs" => {
1190 if let Some(rhs) = node.child_by_field_name(field) {
1191 let lhs_text = node
1192 .child_by_field_name("left")
1193 .map(|l| self.text(l))
1194 .unwrap_or("");
1195 let lhs_last = util::lhs_last_name()
1196 .captures(lhs_text)
1197 .and_then(|c| c.get(1))
1198 .map(|m| m.as_str());
1199 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
1200 values.push(rhs);
1201 }
1202 }
1203 }
1204 "value" => {
1205 let v = node
1206 .child_by_field_name("value")
1207 .or_else(|| {
1208 if node.named_child_count() > 0 {
1209 node.named_child(node.named_child_count() - 1)
1210 } else {
1211 None
1212 }
1213 });
1214 if let Some(v) = v {
1215 values.push(v);
1216 }
1217 }
1218 _ => {
1219 // varinit — Go var_spec names are plain identifiers (no
1220 // destructuring patterns to skip).
1221 if let Some(v) = node.child_by_field_name(field) {
1222 values.push(v);

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 6

pushMethod · 0.80
mapMethod · 0.80
textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected