apollovm_lsp library
ApolloVM Language Server (LSP 3.17) — editor/agent tooling for ApolloVM sources.
This library is part of the apollovm package but kept separate from
package:apollovm/apollovm.dart so importing the VM does not pull in the
language-server surface, and vice-versa.
It is web-safe: nothing here imports dart:io, so a browser-based IDE or
an AI agent can embed the server directly. Wire it up with:
-
MessageLspEndpoint — a host that already exchanges decoded JSON-RPC objects (web
postMessage/MessageChannel, an in-process agent bridge):final endpoint = MessageLspEndpoint((msg) => port.postMessage(msg)); final server = LspServer(endpoint); // deliver incoming messages: endpoint.receive(incomingJsonRpcMap); -
StreamLspEndpoint — byte streams with
Content-Lengthframing (stdio, sockets). The CLI exposes this viaapollovm lsp.
To consume the server, use LspClient, which correlates responses, streams diagnostics, and exposes typed helpers (LspClient.hover, LspClient.definition, …). LspClient.inProcess pairs a client with a fresh server in the same isolate:
final client = LspClient.inProcess();
await client.initialize();
client.didOpen('file:///Foo.dart', source);
final hover = await client.hover('file:///Foo.dart', Position(2, 13));
For the simplest embedding — no transport, no socket, no handshake to run by hand — use LspService, a document-oriented facade ideal for a web app or an AI agent:
final lsp = LspService();
final errors = await lsp.analyze('file:///Foo.dart', source);
final hover = await lsp.hover('file:///Foo.dart', Position(2, 13));
Classes
- AnalyzedUnit
- The cached analysis of one document version.
- Analyzer
- CompletionItem
-
LSP
CompletionItem.sortTextdrives ranking (lower sorts first). - CompletionItemKind
-
LSP
CompletionItemKind(subset). - CompletionList
-
Result of
textDocument/completion: the items and whether the list is isIncomplete (should be recomputed as the user keeps typing). - DeclSite
- A declaration recognised in the source, carrying its name span (for selection/definition) and full span (for the symbol's outer range).
- Diagnostic
- A single diagnostic (error/warning/…) at a range.
- DiagnosticSeverity
-
LSP
DiagnosticSeverity. - DocExtractor
- DocumentHighlight
-
A range to highlight in a document (
textDocument/documentHighlight), e.g. every occurrence of the identifier under the cursor. - DocumentHighlightKind
-
LSP
DocumentHighlightKind. - DocumentStore
- DocumentSymbol
-
LSP hierarchical
DocumentSymbol. - DocumentSymbolBuilder
- Mutable builder so nested DocumentSymbol children can be attached in a second pass before the immutable tree is produced.
- Hover
-
LSP
Hoverresponse. - IdentToken
-
An identifier occurrence in the source, with its
[start, end)UTF-16 span. - InitializeResult
-
Result of the
initializerequest: the server's advertised capabilities and optional serverInfo. - LineIndex
- Location
-
A location inside a document (
uri+range). - LspClient
- A client for the ApolloVM LspServer.
- LspEndpoint
- Transport-agnostic JSON-RPC 2.0 endpoint. Subclasses supply the wire by implementing writeMessage and feeding decoded messages to handleMessage.
- LspServer
- LspService
- An in-process ApolloVM language service.
- MarkupContent
-
LSP
MarkupContent(plaintextormarkdown). - MessageLspEndpoint
-
A message-level endpoint for embedding the server in a host that already
exchanges decoded JSON-RPC objects — a web IDE (over
postMessage/ aMessageChannel), an AI agent, or an in-process bridge. - OpenDocument
- ParseErrorLocation
-
The chosen error location: a
[rangeStart, rangeEnd)span to underline and an optional human hint about the structural cause. - Position
-
A zero-based
(line, character)position.charactercounts UTF-16 code units within the line. - PrepareRenameResult
-
Result of
textDocument/prepareRename: the range of the symbol that would be renamed and a placeholder (its current text). - PublishDiagnosticsParams
-
Parameters of a
textDocument/publishDiagnosticsnotification. - Range
-
A half-open
[start, end)text range. - ServerInfo
-
The server's self-description returned by
initialize. - StreamLspEndpoint
-
A byte-stream endpoint using LSP
Content-Lengthframing. Suitable for stdio (see theapollovm lspCLI command) or a socket/WebSocket byte channel. - SymbolInfo
- Semantic facts about one declaration, independent of its source position.
- SymbolKind
-
LSP
SymbolKind(subset used by this server). - TextEdit
-
LSP
TextEdit. - TokenIndex
- The result of scanning one document: all identifier occurrences (for cursor→symbol mapping) and all recognised declaration sites.
- WorkspaceEdit
-
LSP
WorkspaceEdit(document-scopedchangesmap). - WorkspaceSymbol
-
An entry returned by
workspace/symbol: a named declaration and where it lives.
Enums
- DeclKind
- The kind of a recognised declaration site.
- IdentRole
- The lexical category of a scanned identifier occurrence.
- SymbolCategory
- The semantic category of a collected symbol.
Functions
-
collectSymbols(
ASTRoot root) → List< SymbolInfo> -
Walks
rootand returns every top-level and class-member declaration. -
formatInvocable(
ASTInvocableDeclaration< dynamic, ASTParameterDeclaration, ASTParametersDeclaration< f) → StringASTParameterDeclaration> > -
Formats an invocable declaration as
Ret name(T1 a, T2 b). -
locateParseError(
String text, {int? parserPosition, String? parserMessage, String? language}) → ParseErrorLocation -
Picks the best error location for
text, given the parser's ownparserPosition/parserMessage(which may be unreliable).languageenables language-specific recovery (e.g. a missing;).
Typedefs
- NotificationHandler = void Function(String method, Object? params)
- Handles an incoming notification (no reply).
-
RequestHandler
= FutureOr<
Object?> Function(String method, Object? params) - Handles an incoming request; returns the result or throws ResponseError.
-
ResponseHandler
= void Function(Map<
String, Object?> message) -
Handles an incoming response to a request we sent (client role). Receives the
full decoded message, including its
idand eitherresultorerror. -
ServerRequestHandler
= FutureOr<
Object?> Function(String method, Object? params) -
Handles a server->client request (rare; e.g.
window/showMessageRequest). Return the result, or throw ResponseError; returning null replies with a null result.
Exceptions / Errors
- ResponseError
-
An error returned in a JSON-RPC response
errorobject.