Hex1bDocumentWorkspace
Namespace: Hex1b.LanguageServer
Assembly: Hex1b.dll
A workspace rooted at a directory that manages documents and language server connections.
public sealed class Hex1bDocumentWorkspace : IAsyncDisposableInheritance
Object → Hex1bDocumentWorkspace
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.
public Hex1bDocumentWorkspace(string rootPath)Properties
DirtyDocuments
Returns all documents with unsaved changes.
Returns: IEnumerable<Hex1bDocument>
public IEnumerable<Hex1bDocument> DirtyDocuments { get; }OpenDocuments
Returns all currently open documents.
Returns: IReadOnlyCollection<Hex1bDocument>
public IReadOnlyCollection<Hex1bDocument> OpenDocuments { get; }RootPath
The workspace root directory path.
Returns: String
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.
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:
serverId(String): A logical name for this server (e.g., "csharp-ls", "pyright").configure(Action<LanguageServerConfiguration>): Configuration callback.
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.
public Hex1bDocument CreateDocument(string initialContent = "", string? relativePath = null)DisposeAsync()
Disposes all server connections and clears document tracking.
Returns: ValueTask
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>
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:
document(IHex1bDocument): The document to get a provider for.
Returns: ITextDecorationProvider
A decoration provider, or null if no provider matches.
public ITextDecorationProvider? GetDecorationProvider(IHex1bDocument document)GetDiagnosticSummary()
Returns a summary of diagnostic counts by severity across all open documents.
Returns: ValueTuple<Int32, Int32, Int32>
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:
document(IHex1bDocument): The document to get a provider for.
Returns: LanguageServerDecorationProvider
A decoration provider, or null if no server matches.
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 .
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 .
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:
relativePath(String): Path relative to the workspace root.ct(CancellationToken): Cancellation token.
Returns: Task<Hex1bDocument>
A file-backed document.
public Task<Hex1bDocument> OpenDocumentAsync(string relativePath, CancellationToken ct = default)SaveAllAsync(CancellationToken)
Saves all documents with unsaved changes.
Parameters:
ct(CancellationToken):
Returns: Task
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:
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();