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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

1146 // --- fn refs (GO_SPEC, with the literal_element/expression_list layers) --------
1147
1148 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1149 let (mode, field): (&str, &str) = match node.kind() {
1150 "argument_list" => ("args", ""),
1151 "assignment_statement" => ("rhs", "right"),
1152 "short_var_declaration" => ("rhs", "right"),
1153 "var_spec" => ("varinit", "value"),
1154 "keyed_element" => ("value", ""), // value = LAST named child
1155 "literal_value" => ("list", ""),
1156 _ => return,
1157 };
1158 if self.stack.is_empty() {
1159 return;
1160 }
1161 let from = self.top_row();
1162
1163 let mut values: Vec<Node> = Vec::new();
1164 match mode {
1165 "args" | "list" => {
1166 for c in node.named_children(&mut node.walk()) {
1167 values.push(c);
1168 }
1169 }
1170 "rhs" => {
1171 if let Some(rhs) = node.child_by_field_name(field) {
1172 let lhs_text = node
1173 .child_by_field_name("left")
1174 .map(|l| self.text(l))
1175 .unwrap_or("");
1176 let lhs_last = util::lhs_last_name()
1177 .captures(lhs_text)
1178 .and_then(|c| c.get(1))
1179 .map(|m| m.as_str());
1180 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
1181 values.push(rhs);
1182 }
1183 }
1184 }
1185 "value" => {
1186 let v = node
1187 .child_by_field_name("value")
1188 .or_else(|| {
1189 if node.named_child_count() > 0 {
1190 node.named_child(node.named_child_count() - 1)
1191 } else {
1192 None
1193 }
1194 });
1195 if let Some(v) = v {
1196 values.push(v);
1197 }
1198 }
1199 _ => {
1200 // varinit — Go var_spec names are plain identifiers (no
1201 // destructuring patterns to skip).
1202 if let Some(v) = node.child_by_field_name(field) {
1203 values.push(v);
1204 }
1205 }

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 7

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

Tested by

no test coverage detected