Skip to content

Hex1bLanguageServerWorkspace

Namespace: Hex1b.LanguageServer

Assembly: Hex1b.dll

Manages language server instances for a workspace root directory. Multiple documents in the same workspace share the same server connection per language. Documents register with the workspace and receive a that uses the shared connection.

csharp
public sealed class Hex1bLanguageServerWorkspace : IAsyncDisposable

Inheritance

ObjectHex1bLanguageServerWorkspace

Implements

Constructors

Hex1bLanguageServerWorkspace(string)

Creates a workspace rooted at the specified path.

Parameters:

  • rootPath (String): The workspace root directory path. Converted to a file:// URI for the LSP initialize request's rootUri parameter.
csharp
public Hex1bLanguageServerWorkspace(string rootPath)

Methods

DisposeAsync()

Disposes all active server connections.

Returns: ValueTask

csharp
public ValueTask DisposeAsync()

GetProvider(string, string?)

Gets or creates a decoration provider for a document, backed by the shared language server for that language. Call this from the

extension method.

Parameters:

  • documentUri (String): The document's URI (e.g., file:///path/to/file.cs).
  • languageId (String): The language ID. If null, inferred from the document URI extension.

Returns: LanguageServerDecorationProvider

A decoration provider wired to the shared server connection.

csharp
public LanguageServerDecorationProvider GetProvider(string documentUri, string? languageId = null)

RegisterServer(string, Action<LanguageServerConfiguration>)

Registers a language server configuration for a given language ID. The server is not started until a document of this language is opened.

Parameters:

csharp
public void RegisterServer(string languageId, Action<LanguageServerConfiguration> configure)

Remarks

In LSP, a single server process handles all documents in a workspace via textDocument/didOpen and textDocument/didChange notifications. This class manages that shared lifecycle — one per registered language, shared across all documents of that language.

Usage:

csharp
var workspace = new Hex1bLanguageServerWorkspace("/path/to/project");
workspace.RegisterServer("csharp", config => config
    .WithServerCommand("csharp-ls")
    .EnableSemanticHighlighting());

// In the widget builder:
ctx.Editor(state).LanguageServer(workspace, "file:///path/to/file.cs", "csharp")

Released under the MIT License.