MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / dependencies

Function dependencies

atomic-audit/src/extract/languages.rs:542–637  ·  view source on GitHub ↗
(nodes: &[Node<'_>], source: &str, language: Language)

Source from the content-addressed store, hash-verified

540}
541
542pub(super) fn dependencies(nodes: &[Node<'_>], source: &str, language: Language) -> Measurement {
543 let mut units = BTreeSet::new();
544 let mut incomplete = false;
545 for &node in nodes {
546 let path = match (language, node.kind()) {
547 (Language::TypeScript | Language::Tsx, "import_statement" | "export_statement") => node
548 .child_by_field_name("source")
549 .map(|path| text(path, source).to_owned()),
550 (Language::Python, "import_from_statement") => node
551 .child_by_field_name("module_name")
552 .map(|path| text(path, source).into()),
553 (Language::Python, "import_statement") => {
554 for child in named(node) {
555 let child = child.child_by_field_name("name").unwrap_or(child);
556 units.insert(text(child, source).to_owned());
557 }
558 None
559 }
560 (Language::Rust, "use_declaration") => {
561 if let Some(path) = node.child_by_field_name("argument") {
562 rust_roots(path, source, &mut units);
563 }
564 None
565 }
566 (Language::Rust, "extern_crate_declaration") => node
567 .child_by_field_name("name")
568 .map(|path| text(path, source).into()),
569 (Language::Go, "import_spec") => node
570 .child_by_field_name("path")
571 .map(|path| text(path, source).into()),
572 (Language::Java, "import_declaration") => {
573 let raw = text(node, source)
574 .trim_start_matches("import")
575 .trim()
576 .trim_end_matches(';')
577 .trim();
578 Some(
579 raw.trim_start_matches("static ")
580 .trim_end_matches(".*")
581 .into(),
582 )
583 }
584 (Language::C | Language::Cpp, "preproc_include") => {
585 let path = node.child_by_field_name("path");
586 if path.is_none_or(|path| {
587 !matches!(path.kind(), "string_literal" | "system_lib_string")
588 }) {
589 incomplete = true;
590 None
591 } else {
592 path.map(|path| text(path, source).into())
593 }
594 }
595 (Language::Swift, "import_declaration") => named(node)
596 .into_iter()
597 .find(|child| child.kind() == "identifier")
598 .map(|path| {
599 text(path, source)

Callers 2

parseFunction · 0.85
ancestors_ofMethod · 0.85

Calls 9

rust_rootsFunction · 0.85
unquoteFunction · 0.85
textFunction · 0.70
namedFunction · 0.70
kindMethod · 0.45
insertMethod · 0.45
into_iterMethod · 0.45
nextMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected