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

Method extract_import

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

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

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