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

Method create_node

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

Source from the content-addressed store, hash-verified

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