-
Notifications
You must be signed in to change notification settings - Fork 0
API Host IScriptSourceResolver
Host extension point for loading scripts from files, memory, databases, virtual directories, embedded resources, or remote stores.
Namespace: AuroraScript.Source. Kind: interface.
Back to .NET Host API Reference
Implement IScriptSourceResolver to load scripts from a database, object storage, embedded resources, or virtual directories. Use stable normalized references and retain the importer context when resolving relative imports and includes.
The build pipeline is: parser raw path, then ModuleGraph calls ResolveAsync, then GetSourceAsync.
Note
- A resolver only defines the compiler source universe. It does not decide whether a source is open in an editor.
- A resolver should not hard-code language-server workspace directory filtering; editor and indexing policies belong outside the core resolver.
- Use
/internally for virtual paths and normalized file-system paths.
Important
The examples below show interface shape only. A production resolver must normalize paths, honor cancellation, and route GetSourceAsync by reference.BaseDirectory.
Built-in implementations cover the common cases; implement the interface only for a custom store.
| Need | Use |
|---|---|
| Files on disk | FileSystemScriptSourceResolver |
| Generated or unsaved sources | MemorySourceResolver |
| Layered lookup | CompositeScriptSourceResolver |
string RootNormalized source root represented by this resolver.
Parameters
None.
Returns
Returns string.
Behavior
The root is part of resolver identity. ScriptSourceReference.BaseDirectory must identify the resolver root that can later read the source.
public string Root => "mem://tenant-a/";ValueTask<ScriptSourceReference?> ResolveAsync(ScriptSourceReference? importer, string requestedPath, ScriptResolveContext context, CancellationToken cancellationToken = default)Resolves an entry, import, or include path to a stable source reference.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
importer |
ScriptSourceReference? |
Yes | Importing source, or null for an entry path. |
requestedPath |
string |
Yes | Raw path written in the script. The parser does not normalize it. |
context |
ScriptResolveContext |
Yes | Resolution context carrying extension and encoding. |
cancellationToken |
CancellationToken |
No | Token that cancels the operation. |
Returns
A stable ScriptSourceReference, or null.
Behavior
- When
importerisnull, resolverequestedPathfromRootas an entry path. - When
importeris present, resolverequestedPathfrom the directory ofimporter.FullPath. - Return
nullwhen the source does not exist or the resolved target is not owned by this resolver namespace. - Normalize roots and indexed source keys when the resolver is built, not during every comparison.
public ValueTask<ScriptSourceReference?> ResolveAsync(
ScriptSourceReference? importer,
string requestedPath,
ScriptResolveContext context,
CancellationToken cancellationToken = default)
{
var fullPath = Root + requestedPath;
return ValueTask.FromResult<ScriptSourceReference?>(new ScriptSourceReference(Root, fullPath));
}ValueTask<ScriptSource> GetSourceAsync(ScriptSourceReference reference, CancellationToken cancellationToken = default)Returns source text for a resolved reference.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
reference |
ScriptSourceReference |
Yes | Reference previously produced for this resolver root. |
cancellationToken |
CancellationToken |
No | Token that cancels the operation. |
Returns
The matching ScriptSource.
Behavior
Read only references produced for this resolver root. Composite resolvers route by exact normalized BaseDirectory before calling GetSourceAsync.
public ValueTask<ScriptSource> GetSourceAsync(
ScriptSourceReference reference,
CancellationToken cancellationToken = default) =>
ValueTask.FromResult<ScriptSource>(new MemorySource(Root, reference.FullPath, "@module(MAIN);"));IAsyncEnumerable<ScriptSource> GetAllSourcesAsync(ScriptSourceQuery query, CancellationToken cancellationToken = default)Enumerates sources visible to BuildAsync().
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
query |
ScriptSourceQuery |
Yes | Enumeration filter carrying extension and encoding. |
cancellationToken |
CancellationToken |
No | Token that cancels enumeration. |
Returns
An async sequence of ScriptSource values visible to BuildAsync().
Behavior
- Returned sources should use normalized
FullPathvalues so CompositeScriptSourceResolver can de-duplicate overlays by source identity. - The compiler also uses resolver-visible project sources to discover optional
@global()declaration files before module analysis.
public async IAsyncEnumerable<ScriptSource> GetAllSourcesAsync(
ScriptSourceQuery query,
[System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
{
yield return new MemorySource(Root, Root + "main.as", "@module(MAIN);");
await Task.CompletedTask;
}AuroraScript.JIT 4.0.0 · Documentation Home · Repository · MIT License