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

Method create_node

codegraph-kernel/src/ccpp/mod.rs:542–644  ·  view source on GitHub ↗
(&mut self, kind: &'static str, name: &str, node: Node<'t>, extra: Extra)

Source from the content-addressed store, hash-verified

540 }
541
542 fn create_node(&mut self, kind: &'static str, name: &str, node: Node<'t>, extra: Extra) -> Option<u32> {
543 if name.is_empty() {
544 return None;
545 }
546 let start_line = self.line_of(node);
547 let column = self.col_of(node);
548 let id = self.node_id_allocator.generate(self.file_path, kind, name, start_line, column);
549 // (c/cpp define no resolveBody hook, so createNode's endLine extension
550 // for sibling-body grammars never fires — endLine is the node's own,
551 // or the `}` of its body in brace scopes.)
552 let (end_line, end_column) =
553 extra.end.unwrap_or_else(|| (node.end_position().row as u32 + 1, self.end_col_of(node)));
554
555 let qualified = extra.qualified_name.unwrap_or_else(|| {
556 let mut parts: Vec<&str> = self.namespace_prefix.iter().map(|s| s.as_str()).collect();
557 for s in &self.stack {
558 if let Some(q) = &s.qualified {
559 parts.clear();
560 parts.push(q);
561 } else if s.kind != "file" {
562 parts.push(&s.name);
563 }
564 }
565 let mut qn = parts.join("::");
566 if !qn.is_empty() {
567 qn.push_str("::");
568 }
569 qn.push_str(name);
570 qn
571 });
572
573 let mut flags = BoolFlags::default();
574 if let Some(v) = extra.is_exported {
575 flags.set(FLAG_IS_EXPORTED, v);
576 }
577 if let Some(v) = extra.is_abstract {
578 flags.set(FLAG_IS_ABSTRACT, v);
579 }
580 let name_ref = self.arena.put(name);
581 let qn_ref = self.arena.put(&qualified);
582 let id_ref = self.arena.put(&id);
583 let doc_ref = opt_str(&mut self.arena, extra.docstring.as_deref());
584 let sig_ref = opt_str(&mut self.arena, extra.signature.as_deref());
585 let ret_ref = opt_str(&mut self.arena, extra.return_type.as_deref());
586 let row = self.tables.push_node(&NodeRow {
587 kind: node_kind_index(kind).unwrap(),
588 visibility: extra.visibility.unwrap_or(0),
589 flags,
590 start_line,
591 end_line,
592 start_column: self.col_of(node),
593 end_column,
594 name: name_ref,
595 qualified_name: qn_ref,
596 id: id_ref,
597 docstring: doc_ref,
598 signature: sig_ref,
599 decorators: NONE_STR,

Callers 10

dispatch_nodeMethod · 0.45
extract_functionMethod · 0.45
extract_methodMethod · 0.45
extract_classMethod · 0.45
extract_aggregateMethod · 0.45
extract_enumMethod · 0.45
extract_enum_membersMethod · 0.45
extract_type_aliasMethod · 0.45
extract_variableMethod · 0.45
extract_importMethod · 0.45

Calls 15

node_kind_indexFunction · 0.85
edge_kind_indexFunction · 0.85
utf16_lenFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80
push_nodeMethod · 0.80
push_edgeMethod · 0.80
opt_strFunction · 0.70
putMethod · 0.65
unwrapMethod · 0.60
line_ofMethod · 0.45
col_ofMethod · 0.45

Tested by

no test coverage detected