Skip to content

Hex1bDocumentWorkspace

Namespace: Hex1b.LanguageServer

Assembly: Hex1b.dll

A workspace rooted at a directory that manages documents and language server connections.

csharp
public sealed class Hex1bDocumentWorkspace : IAsyncDisposable

Inheritance

ObjectHex1bDocumentWorkspace

Implements

Constructors

Hex1bDocumentWorkspace(string)

Creates a workspace rooted at the specified directory path.

Parameters:

  • rootPath (String): The workspace root directory. Documents are resolved relative to this path.
csharp
public Hex1bDocumentWorkspace(string rootPath)

Properties

DirtyDocuments

Returns all documents with unsaved changes.

Returns: IEnumerable<Hex1bDocument>

csharp
public IEnumerable<Hex1bDocument> DirtyDocuments { get; }

OpenDocuments

Returns all currently open documents.

Returns: IReadOnlyCollection<Hex1bDocument>

csharp
public IReadOnlyCollection<Hex1bDocument> OpenDocuments { get; }

RootPath

The workspace root directory path.

Returns: String

csharp
public string RootPath { get; }

Methods

AddDecorationProvider(string, Func<ITextDecorationProvider>)

Registers an in-process decoration provider factory with a logical name. In-process providers run without an external language server process — ideal for simple syntax highlighting (e.g., diff files, log files, config files).

Parameters:

  • providerId (String): A logical name for this provider (e.g., "git-diff", "log-highlighter").
  • factory (Func<ITextDecorationProvider>): A factory that creates a new provider instance per document.
csharp
public void AddDecorationProvider(string providerId, Func<ITextDecorationProvider> factory)

AddLanguageServer(string, Action<LanguageServerConfiguration>)

Registers a language server configuration with a logical name. The server is not started until a matching document is opened.

Parameters:

csharp
public void AddLanguageServer(string serverId, Action<LanguageServerConfiguration> configure)

CreateDocument(string, string?)

Creates a new in-memory document. If relativePath is provided, the document is associated with that file path (for future saves) but the file is not created on disk until is called.

Parameters:

  • initialContent (String): Initial text content.
  • relativePath (String): Optional path relative to the workspace root.

Returns: Hex1bDocument

A document, optionally file-backed.

csharp
public Hex1bDocument CreateDocument(string initialContent = "", string? relativePath = null)

DisposeAsync()

Disposes all server connections and clears document tracking.

Returns: ValueTask

csharp
public ValueTask DisposeAsync()

GetAllDiagnostics()

Returns all current diagnostics aggregated across all open documents that have connected language servers, ordered by severity then file.

Returns: IReadOnlyList<DiagnosticInfo>

csharp
public IReadOnlyList<DiagnosticInfo> GetAllDiagnostics()

GetDecorationProvider(IHex1bDocument)

Gets a decoration provider for a document, checking in-process providers first, then falling back to language server providers. Returns null if no provider is mapped for this document type.

Parameters:

Returns: ITextDecorationProvider

A decoration provider, or null if no provider matches.

csharp
public ITextDecorationProvider? GetDecorationProvider(IHex1bDocument document)

GetDiagnosticSummary()

Returns a summary of diagnostic counts by severity across all open documents.

Returns: ValueTuple<Int32, Int32, Int32>

csharp
public (int Errors, int Warnings, int Info) GetDiagnosticSummary()

GetProvider(IHex1bDocument)

Gets a decoration provider for a document, using the workspace's language server mappings to resolve the appropriate server. Returns null if no server is mapped for this document type.

Parameters:

Returns: LanguageServerDecorationProvider

A decoration provider, or null if no server matches.

csharp
public LanguageServerDecorationProvider? GetProvider(IHex1bDocument document)

MapDecorationProvider(string, string)

Maps a file glob pattern to a registered in-process decoration provider. In-process mappings are checked before language server mappings.

Parameters:

  • glob (String): A glob pattern to match document file names (e.g., ".diff", ".patch", "*.log"). Matched against the file name only, not the full path.
  • providerId (String): The provider ID registered with .
csharp
public void MapDecorationProvider(string glob, string providerId)

MapLanguageServer(string, string)

Maps a file glob pattern to a registered language server. When a document matching the glob is opened, it automatically gets decorations from the associated language server.

Parameters:

  • glob (String): A glob pattern to match document file names (e.g., ".cs", ".{ts,tsx}", "Dockerfile"). Matched against the file name only, not the full path.
  • serverId (String): The server ID registered with .
csharp
public void MapLanguageServer(string glob, string serverId)

OpenDocumentAsync(string, CancellationToken)

Opens an existing file as a document. The document is associated with the file path, tracks dirty state, and supports .

Parameters:

Returns: Task<Hex1bDocument>

A file-backed document.

csharp
public Task<Hex1bDocument> OpenDocumentAsync(string relativePath, CancellationToken ct = default)

SaveAllAsync(CancellationToken)

Saves all documents with unsaved changes.

Parameters:

Returns: Task

csharp
public Task SaveAllAsync(CancellationToken ct = default)

Remarks

Documents can be created in-memory or opened from files. File-backed documents track dirty state and support .

Language servers are registered with and mapped to file patterns with . When a document is opened, the workspace resolves the appropriate server based on the document's URI. Multiple documents of the same language share a single server connection.

Usage:

csharp
var workspace = new Hex1bDocumentWorkspace("/my/project");

// Register and map a language server
workspace.AddLanguageServer("csharp-ls", lsp => lsp.WithServerCommand("csharp-ls"));
workspace.MapLanguageServer("*.cs", "csharp-ls");

// Open a file-backed document
var doc = await workspace.OpenDocumentAsync("src/Program.cs");
var state = new EditorState(doc);

// In the widget builder — workspace resolves the right server:
ctx.Editor(state).LanguageServer(workspace)

// Save changes
await doc.SaveAsync();

Released under the MIT License.