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

Method extract_import

codegraph-kernel/src/ccpp/mod.rs:1639–1663  ·  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

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

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