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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

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

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 4

textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected