Architecture¶
This document describes the major runtime pieces and the request flow.
Components¶
CRA::JsonRPC::Server: stdio transport, reads/writes LSP JSON-RPC.CRA::JsonRPC::Processor: dispatches requests; owns aWorkspace.CRA::Workspace: manages documents, indexing, completions, definitions, references, diagnostics.CRA::WorkspaceDocument: stores text, parsed AST, diagnostics, and NodeFinder context.CRA::Psi::SemanticIndex: semantic database for types, methods, vars, aliases, enums; call graph.- Completion providers:
SemanticIndex,KeywordCompletionProvider,RequirePathCompletionProvider. DocumentSymbolsIndex: AST visitor for document/workspace symbols.
Request flow¶
- Initialize -> Workspace.scan -> parse and index project, lib, and stdlib files.
- didOpen/didChange/didSave -> update document text -> parse -> Workspace.reindex_file.
- completion -> NodeFinder -> CompletionContext -> providers -> merged items.
- definition/declaration/implementation/typeDefinition -> NodeFinder -> SemanticIndex.find_definitions.
- references -> NodeFinder -> Workspace/SemanticIndex references.
- call hierarchy -> SemanticIndex call graph.
- diagnostics -> WorkspaceDocument parse + facet lints -> publish/pull.
Indexing and updates¶
- Full text sync (TextDocumentSyncKind::Full).
- Each change parses the full document with Crystal::Parser.
- Reindexing also reindexes dependent types based on include/extend and superclass relationships.
- stdlib lookup uses CRYSTAL_PATH or CRYSTAL_HOME, with /usr/share/crystal/src as fallback.