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

Function script_candidates

atomic-semantic/src/relationships.rs:68–98  ·  view source on GitHub ↗

Standard explicit relative script import candidates. Full source inventory is consulted even when only matching files are parsed, preserving ambiguity.

(importer: &str, module: &str, paths: &BTreeSet<String>)

Source from the content-addressed store, hash-verified

66/// Standard explicit relative script import candidates. Full source inventory is
67/// consulted even when only matching files are parsed, preserving ambiguity.
68pub fn script_candidates(importer: &str, module: &str, paths: &BTreeSet<String>) -> Vec<String> {
69 let script = |path: &str| {
70 matches!(
71 Path::new(path)
72 .extension()
73 .and_then(|extension| extension.to_str()),
74 Some("ts" | "tsx" | "mts" | "cts" | "js" | "jsx" | "mjs" | "cjs")
75 )
76 };
77 if !script(importer) || !module.starts_with('.') {
78 return vec![];
79 }
80 let Some(requested) = Path::new(importer)
81 .parent()
82 .and_then(|base| normalize(base.join(module)))
83 else {
84 return vec![];
85 };
86 paths
87 .iter()
88 .filter(|target| {
89 if !script(target) {
90 return false;
91 }
92 let target = Path::new(target);
93 let stem = target.with_extension("");
94 target == requested || stem == requested || stem == requested.join("index")
95 })
96 .cloned()
97 .collect()
98}
99
100/// Declaration/import context needed to interpret a selected source file.
101/// This returns paths only; repository adapters own recorded-byte retrieval.

Callers 3

context_pathsFunction · 0.85
resolveMethod · 0.85
from_sourcesMethod · 0.85

Calls 4

normalizeFunction · 0.85
parentMethod · 0.80
collectMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected