LspClient class

A client for the ApolloVM LspServer.

Send requests with the typed helpers (hover, definition, completion, …) or the low-level sendRequest/sendNotification, and listen for server-pushed diagnostics on diagnostics.

final client = LspClient.inProcess();     // client + server, same isolate
await client.initialize();
client.initialized();
client.diagnostics.listen((d) => print('${d.uri}: ${d.diagnostics.length}'));
client.didOpen('file:///Foo.dart', source);
final hover = await client.hover('file:///Foo.dart', Position(2, 13));

For an out-of-process server, wrap its transport instead:

final client = LspClient(StreamLspEndpoint(proc.stdout, proc.stdin))..start();

Constructors

LspClient(LspEndpoint _endpoint)
Wraps an existing endpoint. Call start before exchanging messages so a stream-based endpoint begins reading; message-based endpoints deliver incoming messages through their own receive.
LspClient.inProcess()
Creates a client wired to a fresh in-process LspServer over a linked pair of MessageLspEndpoints. Ideal for embedding (web IDE, AI agent) and tests — no subprocess, no dart:io.
factory

Properties

diagnostics Stream<PublishDiagnosticsParams>
Server-pushed textDocument/publishDiagnostics notifications.
no setter
done Future<void>
Completes when the transport closes.
no setter
endpoint LspEndpoint
The underlying transport.
no setter
hashCode int
The hash code for this object.
no setterinherited
onNotification NotificationHandler?
Optional sink for every incoming notification, called after built-in handling (e.g. diagnostics are still delivered to diagnostics).
getter/setter pair
onServerRequest ServerRequestHandler?
Optional handler for requests the server sends to the client. When null, such requests are answered with a methodNotFound error.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

completion(String uri, Position position) Future<CompletionList>
Completion proposals at position in uri.
definition(String uri, Position position) Future<Location?>
The declaration location for the symbol at position, or null.
didChange(String uri, String text, {int? version}) → void
Replaces the whole content of uri with text (a full-document change).
didClose(String uri) → void
Closes uri; the server clears its diagnostics.
didOpen(String uri, String text, {String languageId = 'dart', int version = 1}) → void
Opens uri with text. Diagnostics arrive on diagnostics.
dispose() Future<void>
Releases resources: fails any in-flight requests and closes diagnostics. Does not itself send shutdown/exit — call those first for a clean stop.
documentHighlight(String uri, Position position) Future<List<DocumentHighlight>>
Every occurrence to highlight for the symbol at position in uri.
documentSymbol(String uri) Future<List<DocumentSymbol>>
The document outline (hierarchical DocumentSymbols) for uri.
exit() → void
Tells the server to exit.
hover(String uri, Position position) Future<Hover?>
Hover information at position in uri, or null if none.
initialize({Map<String, Object?>? capabilities, String? rootUri, Map<String, Object?>? initializationOptions}) Future<InitializeResult>
Performs the initialize handshake and returns the server's capabilities. Follow with initialized once ready.
initialized() → void
Notifies the server the client is ready (sent after initialize).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prepareRename(String uri, Position position) Future<PrepareRenameResult?>
Checks whether the symbol at position can be renamed, returning its range and current text, or null if it cannot (no identifier under the cursor).
references(String uri, Position position, {bool includeDeclaration = true}) Future<List<Location>>
All references to the symbol at position in uri.
rename(String uri, Position position, String newName) Future<WorkspaceEdit?>
A WorkspaceEdit renaming the symbol at position to newName, or null.
sendNotification(String method, [Object? params]) → void
Sends a fire-and-forget notification.
sendRequest(String method, [Object? params]) Future<Object?>
Sends a request and completes with its result, or completes with a ResponseError if the server replied with an error.
shutdown() Future<void>
Requests a graceful shutdown; pair with exit.
start() → void
Begins consuming the transport (no-op for message-based endpoints).
toString() String
A string representation of this object.
inherited
workspaceSymbol(String query) Future<List<WorkspaceSymbol>>
Workspace-wide symbols matching query (empty matches all).

Operators

operator ==(Object other) bool
The equality operator.
inherited