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

Method create_node

codegraph-kernel/src/tsjs/mod.rs:402–504  ·  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

400 /// createNode (tree-sitter.ts): id, qualified name from the scope stack,
401 /// contains edge from the parent scope, value-ref bookkeeping.
402 fn create_node(&mut self, kind: &'static str, name: &str, node: Node<'t>, extra: Extra) -> Option<u32> {
403 if name.is_empty() {
404 return None;
405 }
406 let start_line = self.line_of(node);
407 let column = self.col_of(node);
408 let id = self.node_id_allocator.generate(self.file_path, kind, name, start_line, column);
409 let value_target = !extra.not_value_target;
410
411 // endLine body extension: resolveBody only (TS/JS: function-valued
412 // class fields whose body nests in the arrow / HOF-wrapped arrow).
413 let mut end_line = node.end_position().row as u32 + 1;
414 if (kind == "function" || kind == "method") && matches!(node.kind(), "public_field_definition" | "field_definition")
415 {
416 if let Some(body) = resolve_field_body(node) {
417 let be = body.end_position().row as u32 + 1;
418 if be > end_line {
419 end_line = be;
420 }
421 }
422 }
423
424 let qualified = extra.qualified_name.unwrap_or_else(|| {
425 let mut parts: Vec<&str> = Vec::new();
426 for s in &self.stack {
427 // A path-hung object literal qualifies what it holds by its
428 // path (`window.App::init`), which carries its own scope.
429 if let Some(path) = self.object_path_owners.get(&s.row) {
430 parts.clear();
431 parts.push(path);
432 continue;
433 }
434 if s.kind != "file" {
435 parts.push(&s.name);
436 }
437 }
438 let mut qn = parts.join("::");
439 if !qn.is_empty() {
440 qn.push_str("::");
441 }
442 qn.push_str(name);
443 qn
444 });
445
446 let mut flags = BoolFlags::default();
447 if let Some(v) = extra.is_exported {
448 flags.set(FLAG_IS_EXPORTED, v);
449 }
450 if let Some(v) = extra.is_async {
451 flags.set(FLAG_IS_ASYNC, v);
452 }
453 if let Some(v) = extra.is_static {
454 flags.set(FLAG_IS_STATIC, v);
455 }
456
457 let name_ref = self.arena.put(name);
458 let qn_ref = self.arena.put(&qualified);
459 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