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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

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