felixfbecker/language-server-protocol
PHP classes and data structures for the Microsoft Language Server Protocol (LSP). Use it to build language servers/clients in PHP with typed protocol messages and capabilities. Install via Composer: felixfbecker/language-server-protocol.
Install via composer require felixfbecker/language-server-protocol. This package provides only the protocol model classes (e.g., TextDocumentIdentifier, CompletionItem, Position, Diagnostic) — it does not implement a full language server or client. Your first step should be to examine the src/ directory structure in the repo: class names mirror LSP spec sections (e.g., TextDocument/, Workspace/, Window/). Begin by constructing a simple server skeleton that accepts JSON-RPC messages and instantiates the appropriate protocol objects to parse incoming requests (e.g., InitializeRequest, DidChangeTextDocumentParams). Use JSON_THROW_ON_ERROR (PHP ≥7.3) and json_decode($payload, true, 512, JSON_THROW_ON_ERROR) to safely decode payloads before hydrating protocol objects.
new CompletionParams(TextDocumentIdentifier::fromJson($json['textDocument']), Position::fromJson($json['position']), ...)).TypeError or JsonException.LanguageServerProtocol\*) from business logic. For example, a CompletionHandler class accepts CompletionParams and returns CompletionList, deferring PHP-level analysis (e.g., symbol resolution) to your own service layer.Stream (stdio or PSR-7 request body), parse JSON-RPC envelopes manually (or via a small wrapper), then dispatch to handler methods. Use ArrayObject or associative arrays temporarily for debugging before committing to typed model hydration.$additionalProperties (e.g., TextDocumentItem, CodeLens). Store LSP extension data in $additionalProperties arrays without modifying the core package.textDocument/implementation until v1.1.0, and typeDefinition added later). Check composer.lock to verify compatibility with your server’s expected capabilities. Prefer pinning to exact releases over ^1.0.Position, Range, Location have explicit __construct(), some nested objects (e.g., ParameterInformation) lack comprehensive defaults—always provide all required fields explicitly. Use get_class_vars() or IDE inspection to verify required vs optional properties.json_encode(), ensure properties are not null unless explicitly allowed—nulls may be omitted or cause schema mismatches. Consider implementing JsonSerializable in your own wrappers.reactphp/http, clue/php-stream-stdio, or your own PSR-15 handler.prophecy or simple arrays for param injection—most protocol classes are POPOs with no dependencies. Validate round-trips with json_encode($obj) === json_encode(Object::fromJson(json_decode(json_encode($obj), true))).How can I help you explore Laravel packages today?