Skip to content

API Host FileSystemScriptSourceResolver

Liu.Yandong.Hanks edited this page Aug 21, 2026 · 3 revisions

FileSystemScriptSourceResolver

Default file-system source resolver rooted at a directory.

Namespace: AuroraScript.Source. Kind: class.

Back to .NET Host API Reference

Overview

FileSystemScriptSourceResolver reads scripts from disk. Entry paths resolve from Root; import and include dependencies resolve from the directory of the importing file. Create one directly or through ScriptSources.FileSystem(root).

Note

  • Dependency resolution follows importer.FullPath and may resolve outside Root if the relative path points there and the file exists.
  • References returned by this resolver still use this resolver Root as BaseDirectory, so GetSourceAsync routes back here.

Quick Reference

A minimal use of FileSystemScriptSourceResolver.

var resolver = ScriptSources.FileSystem("./scripts");

var options = EngineOptions.Default.WithCompiler(builder =>
    builder.SourceResolver = resolver);

Constructors

FileSystemScriptSourceResolver

FileSystemScriptSourceResolver(string root = null, Encoding encoding = null)

Creates a resolver rooted at a directory.

Parameters

Name Type Required Description
root string No Script root directory.
encoding Encoding No Text encoding used to read source files.

Returns

A new FileSystemScriptSourceResolver instance.

var resolver = new FileSystemScriptSourceResolver("./scripts");

Properties

Root

string Root

Normalized root directory of this resolver.

Parameters

None.

Returns

Returns string.

Console.WriteLine(resolver.Root);

Methods

ResolveAsync

ValueTask<ScriptSourceReference?> ResolveAsync(ScriptSourceReference? importer, string requestedPath, ScriptResolveContext context, CancellationToken cancellationToken = default)

Resolves an entry from Root or a dependency from the importing file path.

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.
context ScriptResolveContext Yes Resolution context carrying extension and encoding.
cancellationToken CancellationToken No Token that cancels the operation.

Returns

A ScriptSourceReference when the file exists; otherwise null.

var reference = await resolver.ResolveAsync(
    null,
    "main.as",
    new ScriptResolveContext(".as"));

GetSourceAsync

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

Returns ScriptSource.

if (reference is not null)
{
    var source = await resolver.GetSourceAsync(reference.Value);
    Console.WriteLine(source.SourcePath);
}

GetAllSourcesAsync

IAsyncEnumerable<ScriptSource> GetAllSourcesAsync(ScriptSourceQuery query, CancellationToken cancellationToken = default)

Enumerates script files under Root for BuildAsync().

Parameters

Name Type Required Description
query ScriptSourceQuery Yes Query carrying the script extension and encoding.
cancellationToken CancellationToken No Token that cancels enumeration.

Returns

Returns IAsyncEnumerable<ScriptSource>.

Behavior

The file-system resolver does not apply language-server workspace directory filters such as bin, obj, or node_modules.

await foreach (var source in resolver.GetAllSourcesAsync(new ScriptSourceQuery(".as")))
{
    Console.WriteLine(source.FullPath);
}

Clone this wiki locally