ILSense
ILSense is an independent, embeddable language service for ILAsm and Common
Intermediate Language (CIL). It provides context-aware completion, diagnostics,
navigation, semantic tokens, and metadata-only assembly indexing for editors,
language servers, and custom tooling.
The NuGet package, library assembly, and root C# namespace are named
EleCho.ILSense. The product and repository name are ILSense. The project is
currently pre-release, so public APIs may change before the first stable version.
Highlights
- Context-aware completion for declarations, signatures, instructions,
operands, labels, assembly qualifiers, types, methods, fields, and
constructors.
- IL directives, keywords, primitive types, opcode families, arguments, locals,
workspace symbols, and imported metadata.
- Diagnostics with exact UTF-16 source ranges suitable for editor squiggles.
- Hover, signature help, definitions, symbols, folding, semantic tokens, and
code actions.
- Metadata-only assembly indexing from files, memory, streams, sequences, and
custom providers without
Assembly.Load.
- Configurable completion providers, filters, rankers, insert-text formatters,
diagnostic providers, compilers, and IL dialects.
- A Monaco-based Demo with LSP 3.17, IL compilation, PE inspection, and
decompiled C# output.
No assembly import is required for directives, IL keywords, primitive types, or
opcodes. Import assemblies only when external assembly, type, or member
completion is needed.
Projects
| Project |
Target frameworks |
Purpose |
EleCho.ILSense |
netstandard2.0;net10.0 |
Embeddable language engine and metadata catalog |
EleCho.ILSense.Demo |
net10.0 |
Monaco workbench, HTTP/LSP host, and IL build adapter |
Run the Demo
Install a .NET SDK that supports .NET 10 or later, then run:
dotnet restore ILSense.slnx
dotnet run --project .\src\EleCho.ILSense.Demo\EleCho.ILSense.Demo.csproj --urls http://127.0.0.1:5187
Open http://127.0.0.1:5187. The Demo provides one IL
editor with completion, diagnostics, build output, decompiled C#, PE metadata,
and imported assemblies.
The Demo never executes the generated user assembly. Assembly metadata is read
without loading the assembly, and compilation and artifact inspection run in
bounded child processes. Those processes provide failure and timeout
containment, not an operating-system sandbox.
Use the Library
After the package is published:
dotnet add package EleCho.ILSense --version 0.1.0
Create an engine and request completion from an immutable workspace snapshot:
using System.Collections.Immutable;
using EleCho.ILSense;
using EleCho.ILSense.Contracts;
var source = """
.method public static void M() cil managed
{
ld
}
""";
var document = DocumentSnapshot.Create("Program.il", version: 1, text: source);
var workspace = new WorkspaceSnapshot(
schemaVersion: CoreSchemaVersion.Current,
revision: 1,
selectionRevision: 1,
languageId: "il",
referenceSetId: "default",
activeFile: document.Id,
sourceOrder: ImmutableArray.Create(document.Id),
files: ImmutableArray.Create(document));
IILLanguageEngine engine = ILLanguageEngine.Create();
var result = engine.Complete(new CompletionRequest(
requestId: "example-1",
snapshot: workspace,
document: document.Id,
position: new SourcePosition(line: 2, character: 4),
trigger: CompletionTrigger.Explicit));
The same engine provides diagnostics, hover, signature help, semantic tokens,
symbols, folding ranges, navigation, and build abstractions.
Import Assembly Metadata
The built-in catalog accepts file and in-memory assemblies:
using EleCho.ILSense;
using EleCho.ILSense.Metadata;
using EleCho.ILSense.Metadata.Index;
var catalog = new ILMetadataCatalog();
await catalog.AddAsync(new AssemblySource.File(@"C:\references\Example.dll"));
ReadOnlyMemory<byte> image = await File.ReadAllBytesAsync("Contracts.dll");
await catalog.AddAsync(new AssemblySource.Bytes(image, "Contracts.dll"));
var engine = ILLanguageEngine.Create(new ILLanguageEngineOptions
{
MetadataCatalog = catalog,
});
Imported images are copied into catalog-owned immutable storage and read with
PEReader and MetadataReader. ILSense does not execute module initializers or
resolve runtime Type instances while indexing metadata.
Completion Behavior
Completion follows the syntactic and semantic slot at the cursor:
[| -> assemblies only
[System.Con| -> System.Console assembly
[System.Console]System.Con| -> System.Console type
[System.Console]System.Console::Write| -> Write/WriteLine methods
Explicit assembly scopes exclude primitive, workspace, and unrelated assembly
candidates. Array shapes such as string[|] are not treated as assembly
qualifiers.
Opcode families can offer both forms such as ldarg and ldarg.0. Opcode
completion inserts only the opcode by default; operand snippets and the optional
method marker for call can be enabled independently.
Extensibility
ILLanguageEngineOptions supports custom completion context rules, synchronous
and asynchronous completion providers, filters, rankers, insert-text formatters,
diagnostic providers, metadata catalogs, language services, compilers, and IL
dialects. Snippet shortcuts such as cw and postfix transformations such as
.await belong in host-provided completion extensions rather than the built-in
ILAsm grammar.
Build and Package
The repository does not pin a specific SDK version. Any SDK that supports .NET
10 or later may be used.
dotnet restore ILSense.slnx
dotnet build ILSense.slnx -c Release --no-restore
dotnet pack .\src\EleCho.ILSense\EleCho.ILSense.csproj -c Release --no-build --no-restore -o .\artifacts\packages
Licensing
ILSense is licensed under the MIT License. Third-party components
retain their respective upstream licenses.