pub struct ModuleLoader { /* private fields */ }Expand description
Module loader manages loading and caching of modules
Implementations§
Source§impl ModuleLoader
impl ModuleLoader
Sourcepub fn clone_without_cache(&self) -> Self
pub fn clone_without_cache(&self) -> Self
Clone loader configuration (search paths + resolver payloads) without cache state.
Sourcepub fn add_module_path(&mut self, path: PathBuf)
pub fn add_module_path(&mut self, path: PathBuf)
Add a module search path
Sourcepub fn set_project_root(&mut self, root: &Path, extra_paths: &[PathBuf])
pub fn set_project_root(&mut self, root: &Path, extra_paths: &[PathBuf])
Set the project root and prepend its configured module paths
Inserts the project root directory itself plus any extra paths (typically resolved from shape.toml [modules].paths) at the front of the search list so project modules take priority.
Sourcepub fn configure_for_context(
&mut self,
current_file: &Path,
workspace_root: Option<&Path>,
)
pub fn configure_for_context( &mut self, current_file: &Path, workspace_root: Option<&Path>, )
Configure module paths and dependency paths from workspace/file context.
Sourcepub fn configure_for_context_with_source(
&mut self,
current_file: &Path,
workspace_root: Option<&Path>,
current_source: Option<&str>,
)
pub fn configure_for_context_with_source( &mut self, current_file: &Path, workspace_root: Option<&Path>, current_source: Option<&str>, )
Configure module loader for context and register declared extension artifacts.
This is the canonical context setup path for tooling (LSP/CLI) so extension module namespaces are resolved through the same loader.
Sourcepub fn set_dependency_paths(&mut self, deps: HashMap<String, PathBuf>)
pub fn set_dependency_paths(&mut self, deps: HashMap<String, PathBuf>)
Register resolved dependency paths from [dependencies] in shape.toml.
Each entry maps a package name to its resolved local path. When a module
import matches a dependency name, the loader searches that path first.
If a dependency path points to a .shapec bundle file, the bundle is
loaded and its modules are registered in the bundle resolver.
Sourcepub fn register_extension_module(
&mut self,
module_path: impl Into<String>,
code: ModuleCode,
)
pub fn register_extension_module( &mut self, module_path: impl Into<String>, code: ModuleCode, )
Register an extension-provided in-memory module artifact.
Sourcepub fn register_embedded_stdlib_module(
&mut self,
module_path: impl Into<String>,
code: ModuleCode,
)
pub fn register_embedded_stdlib_module( &mut self, module_path: impl Into<String>, code: ModuleCode, )
Register an embedded stdlib in-memory module artifact.
Sourcepub fn load_bundle(&mut self, bundle: &PackageBundle, prefix: Option<&str>)
pub fn load_bundle(&mut self, bundle: &PackageBundle, prefix: Option<&str>)
Register modules from a package bundle, optionally prefixed with a dependency name.
If the bundle contains content-addressed manifests (v2+), those are
registered as ContentAddressed modules. Otherwise, legacy compiled
modules are registered as Compiled.
Sourcepub fn register_content_addressed_module(
&mut self,
module_path: impl Into<String>,
manifest: &ModuleManifest,
blobs: HashMap<[u8; 32], Vec<u8>>,
)
pub fn register_content_addressed_module( &mut self, module_path: impl Into<String>, manifest: &ModuleManifest, blobs: HashMap<[u8; 32], Vec<u8>>, )
Register a content-addressed module from a manifest and its blob data.
The manifest describes the module’s exports and type schemas, each
identified by a content hash. The blobs map provides pre-fetched
blob data keyed by hash so the loader doesn’t need to hit a remote
store.
Sourcepub fn register_bundle_modules(&mut self, modules: Vec<(String, ModuleCode)>)
pub fn register_bundle_modules(&mut self, modules: Vec<(String, ModuleCode)>)
Register bundle modules directly from path/code pairs.
Sourcepub fn set_blob_store(&mut self, store: Arc<dyn BlobStore>)
pub fn set_blob_store(&mut self, store: Arc<dyn BlobStore>)
Set an external blob store for lazy-fetching content-addressed blobs on cache miss during module loading.
Sourcepub fn has_extension_module(&self, module_path: &str) -> bool
pub fn has_extension_module(&self, module_path: &str) -> bool
Check whether an extension in-memory module is registered.
Sourcepub fn extension_module_paths(&self) -> Vec<String>
pub fn extension_module_paths(&self) -> Vec<String>
List all registered extension in-memory module paths.
Sourcepub fn embedded_stdlib_module_paths(&self) -> Vec<String>
pub fn embedded_stdlib_module_paths(&self) -> Vec<String>
List all registered embedded stdlib module paths.
Sourcepub fn get_dependency_paths(&self) -> &HashMap<String, PathBuf>
pub fn get_dependency_paths(&self) -> &HashMap<String, PathBuf>
Get the resolved dependency paths.
Sourcepub fn get_module_paths(&self) -> &[PathBuf]
pub fn get_module_paths(&self) -> &[PathBuf]
Get all module search paths
Sourcepub fn get_stdlib_path(&self) -> &PathBuf
pub fn get_stdlib_path(&self) -> &PathBuf
Get the stdlib path
Sourcepub fn set_stdlib_path(&mut self, path: PathBuf)
pub fn set_stdlib_path(&mut self, path: PathBuf)
Set the stdlib path
Sourcepub fn set_keychain(&mut self, keychain: Keychain)
pub fn set_keychain(&mut self, keychain: Keychain)
Set the keychain used for module signature verification.
When set, content-addressed modules are verified against the keychain before loading. If the keychain requires signatures, unsigned modules are rejected.
Sourcepub fn keychain(&self) -> Option<&Keychain>
pub fn keychain(&self) -> Option<&Keychain>
Get a reference to the configured keychain, if any.
Sourcepub fn clear_module_paths(&mut self)
pub fn clear_module_paths(&mut self)
Clear all module search paths (except stdlib)
Sourcepub fn reset_module_paths(&mut self)
pub fn reset_module_paths(&mut self)
Reset module paths to defaults
Sourcepub fn resolve_module_path(&self, module_path: &str) -> Result<PathBuf>
pub fn resolve_module_path(&self, module_path: &str) -> Result<PathBuf>
Resolve a module path to an absolute file path.
Sourcepub fn resolve_module_path_with_context(
&self,
module_path: &str,
context_path: Option<&PathBuf>,
) -> Result<PathBuf>
pub fn resolve_module_path_with_context( &self, module_path: &str, context_path: Option<&PathBuf>, ) -> Result<PathBuf>
Resolve a module path with an optional importer context directory.
Sourcepub fn load_module_with_context(
&mut self,
module_path: &str,
context_path: Option<&PathBuf>,
) -> Result<Arc<Module>>
pub fn load_module_with_context( &mut self, module_path: &str, context_path: Option<&PathBuf>, ) -> Result<Arc<Module>>
Load a module with optional context path
Sourcepub fn load_module_from_file(&mut self, file_path: &Path) -> Result<Arc<Module>>
pub fn load_module_from_file(&mut self, file_path: &Path) -> Result<Arc<Module>>
Load and compile a module directly from an absolute/relative file path.
Uses the same parsing/export/dependency logic as load_module(...),
but keys the cache by canonical file path.
Sourcepub fn list_core_stdlib_module_imports(&self) -> Result<Vec<String>>
pub fn list_core_stdlib_module_imports(&self) -> Result<Vec<String>>
List all std::core::... import paths available in the configured stdlib.
Sourcepub fn list_stdlib_module_imports(&self) -> Result<Vec<String>>
pub fn list_stdlib_module_imports(&self) -> Result<Vec<String>>
List all std::... import paths available in the configured stdlib.
Sourcepub fn list_importable_modules_with_context(
&self,
current_file: &Path,
workspace_root: Option<&Path>,
) -> Vec<String>
pub fn list_importable_modules_with_context( &self, current_file: &Path, workspace_root: Option<&Path>, ) -> Vec<String>
List all importable modules for a given workspace/file context.
Includes:
std::...modules from stdlib- project root modules
[modules].pathsentries fromshape.toml- path dependencies from
shape.toml([dependencies]) - local fallback modules near
current_filewhen outside a project
Sourcepub fn load_core_stdlib_modules(&mut self) -> Result<Vec<Arc<Module>>>
pub fn load_core_stdlib_modules(&mut self) -> Result<Vec<Arc<Module>>>
Load std::core::... modules via the canonical module resolution pipeline.
Sourcepub fn load_stdlib(&mut self) -> Result<()>
pub fn load_stdlib(&mut self) -> Result<()>
Load the standard library modules
Sourcepub fn loaded_modules(&self) -> Vec<&str>
pub fn loaded_modules(&self) -> Vec<&str>
Get all loaded modules
Sourcepub fn get_export(
&self,
module_path: &str,
export_name: &str,
) -> Option<&Export>
pub fn get_export( &self, module_path: &str, export_name: &str, ) -> Option<&Export>
Get a specific export from a module
Sourcepub fn resolve_import(
&mut self,
import_stmt: &ImportStmt,
) -> Result<HashMap<String, Export>>
pub fn resolve_import( &mut self, import_stmt: &ImportStmt, ) -> Result<HashMap<String, Export>>
Resolve an import statement to actual exports
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clear the module cache
Sourcepub fn get_dependencies(&self, module_path: &str) -> Option<&Vec<String>>
pub fn get_dependencies(&self, module_path: &str) -> Option<&Vec<String>>
Get module dependencies
Sourcepub fn get_all_dependencies(&self, module_path: &str) -> Vec<String>
pub fn get_all_dependencies(&self, module_path: &str) -> Vec<String>
Get all module dependencies recursively
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ModuleLoader
impl !RefUnwindSafe for ModuleLoader
impl Send for ModuleLoader
impl Sync for ModuleLoader
impl Unpin for ModuleLoader
impl UnsafeUnpin for ModuleLoader
impl !UnwindSafe for ModuleLoader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more