LspService class

An in-process ApolloVM language service.

final lsp = LspService();

// One-shot: analyze a buffer and get its diagnostics.
final errors = await lsp.analyze('file:///Foo.dart', source);

// Or open once and issue many queries as the buffer changes.
lsp.open('file:///Foo.dart', source);
final hover = await lsp.hover('file:///Foo.dart', Position(2, 13));
lsp.change('file:///Foo.dart', edited);

await lsp.dispose();

Every query resolves against the current in-memory buffer, so results never observe a stale document. Diagnostics are also pushed to diagnostics as the server (re)analyzes.

Constructors

LspService()
Creates a service backed by a fresh in-process server — no transport, no dart:io. The initialize handshake runs lazily; await ready (or any query) to observe the server's InitializeResult.
factory
LspService.wrap(LspClient client)
Wraps an existing client (e.g. one connected to a remote server over a StreamLspEndpoint) with the same document-tracking convenience. The caller retains ownership: dispose will not dispose client.
factory

Properties

client LspClient
The underlying client, for advanced use (custom requests, lifecycle).
no setter
diagnostics Stream<PublishDiagnosticsParams>
Server-pushed diagnostics, published as documents are (re)analyzed.
no setter
hashCode int
The hash code for this object.
no setterinherited
ready Future<InitializeResult>
Completes with the server's capabilities once the handshake finishes.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

analyze(String uri, String text, {String? languageId}) Future<List<Diagnostic>>
Sets the buffer for uri to text (opening it if new, otherwise changing it) and returns the diagnostics from the resulting analysis.
change(String uri, String text) → void
Replaces the whole content of an open uri with text.
close(String uri) → void
Closes uri; the server clears its diagnostics.
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.
dispose() Future<void>
Shuts the service down. When this service created its own server (the default), the underlying client is disposed too.
documentHighlight(String uri, Position position) Future<List<DocumentHighlight>>
Occurrences to highlight for the symbol at position in uri.
documentSymbols(String uri) Future<List<DocumentSymbol>>
The document outline (hierarchical DocumentSymbols) for uri.
hover(String uri, Position position) Future<Hover?>
Hover information at position in uri, or null.
isOpen(String uri) bool
Whether uri is currently open in the service.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
open(String uri, String text, {String? languageId}) → void
Opens uri with text. languageId defaults to the language inferred from the URI extension (falling back to dart).
prepareRename(String uri, Position position) Future<PrepareRenameResult?>
Whether the symbol at position can be renamed (its range + placeholder), or null.
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.
toString() String
A string representation of this object.
inherited
workspaceSymbols(String query) Future<List<WorkspaceSymbol>>
Workspace-wide symbols matching query (empty matches all open docs).

Operators

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