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

Method extract_import

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

1195 /// extractImport via the c/cpp extractImport hook: `#include <sys.h>` /
1196 /// `#include "local.h"`. A hook miss (`#include MACRO`) extracts nothing.
1197 fn extract_import(&mut self, node: Node<'t>) {
1198 let import_text = self.text(node).trim().to_string();
1199 let module_name: Option<String> =
1200 if let Some(sys) = self.find_child_by_kind(node, "system_lib_string") {
1201 let t = self.text(sys);
1202 let t = t.strip_prefix('<').unwrap_or(t);
1203 let t = t.strip_suffix('>').unwrap_or(t);
1204 Some(t.to_string())
1205 } else if let Some(lit) = self.find_child_by_kind(node, "string_literal") {
1206 self.find_child_by_kind(lit, "string_content").map(|sc| self.text(sc).to_string())
1207 } else {
1208 None
1209 };
1210 let Some(module_name) = module_name else { return };
1211 self.create_node(
1212 "import",
1213 &module_name,
1214 node,
1215 Extra { signature: Some(import_text), ..Extra::default() },
1216 );
1217 if !module_name.is_empty() {
1218 let parent = self.top_row();
1219 self.push_ref_at(parent, &module_name, edge_kind_index("imports").unwrap(), node);
1220 }
1221 }
1222
1223 // --- calls / instantiation ----------------------------------------------
1224

Callers 1

visit_nodeMethod · 0.45

Calls 7

edge_kind_indexFunction · 0.85
find_child_by_kindMethod · 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