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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

911 // --- fn refs (GO_SPEC, with the literal_element/expression_list layers) --------
912
913 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
914 let (mode, field): (&str, &str) = match node.kind() {
915 "argument_list" => ("args", ""),
916 "assignment_statement" => ("rhs", "right"),
917 "short_var_declaration" => ("rhs", "right"),
918 "var_spec" => ("varinit", "value"),
919 "keyed_element" => ("value", ""), // value = LAST named child
920 "literal_value" => ("list", ""),
921 _ => return,
922 };
923 if self.stack.is_empty() {
924 return;
925 }
926 let from = self.top_row();
927
928 let mut values: Vec<Node> = Vec::new();
929 match mode {
930 "args" | "list" => {
931 for i in 0..node.named_child_count() {
932 if let Some(c) = node.named_child(i) {
933 values.push(c);
934 }
935 }
936 }
937 "rhs" => {
938 if let Some(rhs) = node.child_by_field_name(field) {
939 let lhs_text = node
940 .child_by_field_name("left")
941 .map(|l| self.text(l))
942 .unwrap_or("");
943 let lhs_last = util::lhs_last_name()
944 .captures(lhs_text)
945 .and_then(|c| c.get(1))
946 .map(|m| m.as_str());
947 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
948 values.push(rhs);
949 }
950 }
951 }
952 "value" => {
953 let v = node
954 .child_by_field_name("value")
955 .or_else(|| {
956 if node.named_child_count() > 0 {
957 node.named_child(node.named_child_count() - 1)
958 } else {
959 None
960 }
961 });
962 if let Some(v) = v {
963 values.push(v);
964 }
965 }
966 _ => {
967 // varinit — Go var_spec names are plain identifiers (no
968 // destructuring patterns to skip).
969 if let Some(v) = node.child_by_field_name(field) {
970 values.push(v);

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 4

getMethod · 0.65
top_rowMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected