Skip to main content

ModuleLoader

Struct ModuleLoader 

Source
pub struct ModuleLoader { /* private fields */ }
Expand description

Module loader manages loading and caching of modules

Implementations§

Source§

impl ModuleLoader

Source

pub fn new() -> Self

Create a new module loader

Source

pub fn clone_without_cache(&self) -> Self

Clone loader configuration (search paths + resolver payloads) without cache state.

Source

pub fn add_module_path(&mut self, path: PathBuf)

Add a module search path

Source

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.

Source

pub fn configure_for_context( &mut self, current_file: &Path, workspace_root: Option<&Path>, )

Configure module paths and dependency paths from workspace/file context.

Source

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.

Source

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.

Source

pub fn register_extension_module( &mut self, module_path: impl Into<String>, code: ModuleCode, )

Register an extension-provided in-memory module artifact.

Source

pub fn register_embedded_stdlib_module( &mut self, module_path: impl Into<String>, code: ModuleCode, )

Register an embedded stdlib in-memory module artifact.

Source

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.

Source

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.

Source

pub fn register_bundle_modules(&mut self, modules: Vec<(String, ModuleCode)>)

Register bundle modules directly from path/code pairs.

Source

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.

Source

pub fn has_extension_module(&self, module_path: &str) -> bool

Check whether an extension in-memory module is registered.

Source

pub fn extension_module_paths(&self) -> Vec<String>

List all registered extension in-memory module paths.

Source

pub fn embedded_stdlib_module_paths(&self) -> Vec<String>

List all registered embedded stdlib module paths.

Source

pub fn get_dependency_paths(&self) -> &HashMap<String, PathBuf>

Get the resolved dependency paths.

Source

pub fn get_module_paths(&self) -> &[PathBuf]

Get all module search paths

Source

pub fn get_stdlib_path(&self) -> &PathBuf

Get the stdlib path

Source

pub fn set_stdlib_path(&mut self, path: PathBuf)

Set the stdlib path

Source

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.

Source

pub fn keychain(&self) -> Option<&Keychain>

Get a reference to the configured keychain, if any.

Source

pub fn clear_module_paths(&mut self)

Clear all module search paths (except stdlib)

Source

pub fn reset_module_paths(&mut self)

Reset module paths to defaults

Source

pub fn load_module(&mut self, module_path: &str) -> Result<Arc<Module>>

Load a module by path

Source

pub fn resolve_module_path(&self, module_path: &str) -> Result<PathBuf>

Resolve a module path to an absolute file path.

Source

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.

Source

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

Source

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.

Source

pub fn list_core_stdlib_module_imports(&self) -> Result<Vec<String>>

List all std::core::... import paths available in the configured stdlib.

Source

pub fn list_stdlib_module_imports(&self) -> Result<Vec<String>>

List all std::... import paths available in the configured stdlib.

Source

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].paths entries from shape.toml
  • path dependencies from shape.toml ([dependencies])
  • local fallback modules near current_file when outside a project
Source

pub fn load_core_stdlib_modules(&mut self) -> Result<Vec<Arc<Module>>>

Load std::core::... modules via the canonical module resolution pipeline.

Source

pub fn load_stdlib(&mut self) -> Result<()>

Load the standard library modules

Source

pub fn loaded_modules(&self) -> Vec<&str>

Get all loaded modules

Source

pub fn get_export( &self, module_path: &str, export_name: &str, ) -> Option<&Export>

Get a specific export from a module

Source

pub fn get_module(&self, module_path: &str) -> Option<&Arc<Module>>

Get a module by path

Source

pub fn resolve_import( &mut self, import_stmt: &ImportStmt, ) -> Result<HashMap<String, Export>>

Resolve an import statement to actual exports

Source

pub fn clear_cache(&mut self)

Clear the module cache

Source

pub fn get_dependencies(&self, module_path: &str) -> Option<&Vec<String>>

Get module dependencies

Source

pub fn get_all_dependencies(&self, module_path: &str) -> Vec<String>

Get all module dependencies recursively

Trait Implementations§

Source§

impl Default for ModuleLoader

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more