MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / visit_function

Method visit_function

src/extraction/zig_extractor.rs:651–717  ·  view source on GitHub ↗

Extract a function or method declaration. If `class_depth > 0`, the function is a Method; otherwise it is a Function.

(state: &mut ExtractionState, node: TsNode<'_>)

Source from the content-addressed store, hash-verified

649 ///
650 /// If `class_depth > 0`, the function is a Method; otherwise it is a Function.
651 fn visit_function(state: &mut ExtractionState, node: TsNode<'_>) {
652 let name = node
653 .child_by_field_name("name")
654 .map_or_else(|| "<anonymous>".to_string(), |n| state.node_text(n));
655
656 let is_pub = Self::has_pub_keyword(state, node);
657 let visibility = if is_pub {
658 Visibility::Pub
659 } else {
660 Visibility::Private
661 };
662 let in_type = state.class_depth > 0;
663 let kind = if in_type {
664 NodeKind::Method
665 } else {
666 NodeKind::Function
667 };
668 let signature = Self::extract_function_signature(state, node);
669 let docstring = Self::extract_docstring(state, node);
670 let start_line = node.start_position().row as u32;
671 let end_line = node.end_position().row as u32;
672 let start_column = node.start_position().column as u32;
673 let end_column = node.end_position().column as u32;
674 let qualified_name = format!("{}::{}", state.qualified_prefix(), name);
675 let id = generate_node_id(&state.file_path, &kind, &name, start_line);
676 let metrics = count_complexity(node, &ZIG_COMPLEXITY, &state.source);
677
678 let graph_node = Node {
679 id: id.clone(),
680 kind,
681 name: name.clone(),
682 qualified_name,
683 file_path: state.file_path.clone(),
684 start_line,
685 attrs_start_line: start_line,
686 end_line,
687 start_column,
688 end_column,
689 signature,
690 docstring,
691 visibility,
692 is_async: false,
693 branches: metrics.branches,
694 loops: metrics.loops,
695 returns: metrics.returns,
696 max_nesting: metrics.max_nesting,
697 unsafe_blocks: metrics.unsafe_blocks,
698 unchecked_calls: metrics.unchecked_calls,
699 assertions: metrics.assertions,
700 updated_at: state.timestamp,
701 parent_id: None,
702 };
703 state.nodes.push(graph_node);
704
705 // Contains edge from parent.
706 if let Some(parent_id) = state.parent_node_id() {
707 state.edges.push(Edge {
708 source: parent_id.to_string(),

Callers

nothing calls this directly

Calls 5

generate_node_idFunction · 0.85
count_complexityFunction · 0.85
pushMethod · 0.80
node_textMethod · 0.45
parent_node_idMethod · 0.45

Tested by

no test coverage detected