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

Method extract_import

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

1179 /// extractImport via the c/cpp extractImport hook: `#include <sys.h>` /
1180 /// `#include "local.h"`. A hook miss (`#include MACRO`) extracts nothing.
1181 fn extract_import(&mut self, node: Node<'t>) {
1182 let import_text = self.text(node).trim().to_string();
1183 let module_name: Option<String> =
1184 if let Some(sys) = self.find_child_by_kind(node, "system_lib_string") {
1185 let t = self.text(sys);
1186 let t = t.strip_prefix('<').unwrap_or(t);
1187 let t = t.strip_suffix('>').unwrap_or(t);
1188 Some(t.to_string())
1189 } else if let Some(lit) = self.find_child_by_kind(node, "string_literal") {
1190 self.find_child_by_kind(lit, "string_content").map(|sc| self.text(sc).to_string())
1191 } else {
1192 None
1193 };
1194 let Some(module_name) = module_name else { return };
1195 self.create_node(
1196 "import",
1197 &module_name,
1198 node,
1199 Extra { signature: Some(import_text), ..Extra::default() },
1200 );
1201 if !module_name.is_empty() {
1202 let parent = self.top_row();
1203 self.push_ref_at(parent, &module_name, edge_kind_index("imports").unwrap(), node);
1204 }
1205 }
1206
1207 // --- calls / instantiation ----------------------------------------------
1208

Callers 1

visit_nodeMethod · 0.45

Calls 7

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

Tested by

no test coverage detected