MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / resolve_module_source

Method resolve_module_source

src/compilation_pipeline.rs:388–451  ·  view source on GitHub ↗
(
        &self,
        path: &str,
        base_source_path: Option<&Path>,
    )

Source from the content-addressed store, hash-verified

386 raw_path.to_path_buf()
387 } else {
388 let base_dir = base_source_path
389 .and_then(Path::parent)
390 .map(Path::to_path_buf)
391 .unwrap_or_else(|| PathBuf::from("."));
392 base_dir.join(raw_path)
393 };
394
395 // Prefer the embedded table so bundled programs resolve identically on every
396 // platform (the browser cannot canonicalize); the virtual source_path re-derives.
397 let normalized = normalize_lexical(&candidate);
398 if let Some(key) = programs_key(&normalized)
399 && let Some(source) = crate::userspace::source_by_path(&key)
400 {
401 return Ok(Some(ResolvedModuleSource {
402 source: source.to_owned(),
403 source_path: Some(PathBuf::from(&key)),
404 key,
405 is_stdlib: false,
406 }));
407 }
408
409 // Native fallback: raw on-disk paths outside the bundled `programs/` tree.
410 let canonical = candidate.canonicalize().map_err(|err| {
411 format!(
412 "cannot resolve import(\"{path}\") from `{}`: {err}",
413 base_source_path
414 .map(|p| p.display().to_string())
415 .unwrap_or_else(|| ".".to_owned())
416 )
417 })?;
418 let source = fs::read_to_string(&canonical).map_err(|err| {
419 format!(
420 "cannot read import(\"{path}\") at `{}`: {err}",
421 canonical.display()
422 )
423 })?;
424 return Ok(Some(ResolvedModuleSource {
425 key: canonical.display().to_string(),
426 source,
427 source_path: Some(canonical),
428 is_stdlib: false,
429 }));
430 }
431
432 let key = Self::module_key(path);
433 Ok(self
434 .resolve_registry_module_source(key)
435 .map(|source| ResolvedModuleSource {
436 key: key.to_owned(),
437 source,
438 // A registry module keeps its repo-relative path so its compiled
439 // line table (and the debugger) can point at the real file.
440 source_path: self.registry_module_path(key).map(PathBuf::from),
441 is_stdlib: self.is_stdlib_module_for_target(key),
442 }))
443 }
444
445 fn registry_module_path(&self, key: &str) -> Option<&'static str> {

Calls 6

normalize_lexicalFunction · 0.85
programs_keyFunction · 0.85
module_keyFunction · 0.85
displayMethod · 0.80