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

Method create_node

codegraph-kernel/src/tsjs/mod.rs:516–618  ·  view source on GitHub ↗

createNode (tree-sitter.ts): id, qualified name from the scope stack, contains edge from the parent scope, value-ref bookkeeping.

(&mut self, kind: &'static str, name: &str, node: Node<'t>, extra: Extra)

Source from the content-addressed store, hash-verified

514 /// createNode (tree-sitter.ts): id, qualified name from the scope stack,
515 /// contains edge from the parent scope, value-ref bookkeeping.
516 fn create_node(&mut self, kind: &'static str, name: &str, node: Node<'t>, extra: Extra) -> Option<u32> {
517 if name.is_empty() {
518 return None;
519 }
520 let start_line = self.line_of(node);
521 let column = self.col_of(node);
522 let id = self.node_id_allocator.generate(self.file_path, kind, name, start_line, column);
523 let value_target = !extra.not_value_target;
524
525 // endLine body extension: resolveBody only (TS/JS: function-valued
526 // class fields whose body nests in the arrow / HOF-wrapped arrow).
527 let mut end_line = node.end_position().row as u32 + 1;
528 if (kind == "function" || kind == "method") && matches!(node.kind(), "public_field_definition" | "field_definition")
529 {
530 if let Some(body) = resolve_field_body(node) {
531 let be = body.end_position().row as u32 + 1;
532 if be > end_line {
533 end_line = be;
534 }
535 }
536 }
537
538 let qualified = extra.qualified_name.unwrap_or_else(|| {
539 let mut parts: Vec<&str> = Vec::new();
540 for s in &self.stack {
541 // A path-hung object literal qualifies what it holds by its
542 // path (`window.App::init`), which carries its own scope.
543 if let Some(path) = self.object_path_owners.get(&s.row) {
544 parts.clear();
545 parts.push(path);
546 continue;
547 }
548 if s.kind != "file" {
549 parts.push(&s.name);
550 }
551 }
552 let mut qn = parts.join("::");
553 if !qn.is_empty() {
554 qn.push_str("::");
555 }
556 qn.push_str(name);
557 qn
558 });
559
560 let mut flags = BoolFlags::default();
561 if let Some(v) = extra.is_exported {
562 flags.set(FLAG_IS_EXPORTED, v);
563 }
564 if let Some(v) = extra.is_async {
565 flags.set(FLAG_IS_ASYNC, v);
566 }
567 if let Some(v) = extra.is_static {
568 flags.set(FLAG_IS_STATIC, v);
569 }
570
571 let name_ref = self.arena.put(name);
572 let qn_ref = self.arena.put(&qualified);
573 let id_ref = self.arena.put(&id);

Callers 15

extract_functionMethod · 0.45
extract_classMethod · 0.45
extract_methodMethod · 0.45
extract_interfaceMethod · 0.45
extract_enumMethod · 0.45
extract_enum_membersMethod · 0.45
extract_propertyMethod · 0.45
extract_variableMethod · 0.45

Calls 15

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

Tested by

no test coverage detected