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

Method extract_import

codegraph-kernel/src/ccpp/mod.rs:1637–1661  ·  view source on GitHub ↗

extractImport via the c/cpp extractImport hook: `#include ` / `#include "local.h"`. A hook miss (`#include MACRO`) extracts nothing.

(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1635 /// extractImport via the c/cpp extractImport hook: `#include <sys.h>` /
1636 /// `#include "local.h"`. A hook miss (`#include MACRO`) extracts nothing.
1637 fn extract_import(&mut self, node: Node<'t>) {
1638 let import_text = self.text(node).trim().to_string();
1639 let module_name: Option<String> =
1640 if let Some(sys) = self.find_child_by_kind(node, "system_lib_string") {
1641 let t = self.text(sys);
1642 let t = t.strip_prefix('<').unwrap_or(t);
1643 let t = t.strip_suffix('>').unwrap_or(t);
1644 Some(t.to_string())
1645 } else if let Some(lit) = self.find_child_by_kind(node, "string_literal") {
1646 self.find_child_by_kind(lit, "string_content").map(|sc| self.text(sc).to_string())
1647 } else {
1648 None
1649 };
1650 let Some(module_name) = module_name else { return };
1651 self.create_node(
1652 "import",
1653 &module_name,
1654 node,
1655 Extra { signature: Some(import_text), ..Extra::default() },
1656 );
1657 if !module_name.is_empty() {
1658 let parent = self.top_row();
1659 self.push_ref_at(parent, &module_name, edge_kind_index("imports").unwrap(), node);
1660 }
1661 }
1662
1663 // --- calls / instantiation ----------------------------------------------
1664

Callers 1

dispatch_nodeMethod · 0.45

Calls 8

edge_kind_indexFunction · 0.85
find_child_by_kindMethod · 0.80
mapMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60
create_nodeMethod · 0.45
top_rowMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected