Files
Language-Server/docs/roadmap/02-lsp-protocol-lifecycle.md
faumaray ca04975d54 bootstrap
Signed-off-by: faumaray <faumaray@gmail.com>
2026-11-25 02:11:19 +03:00

33 lines
3.7 KiB
Markdown

# 02 — LSP framing, JSON envelope and lifecycle
Status: PARTIAL (T-001); implemented shell, final JSON acceptance blocked upstream
Requirements: R-002,R-003,R-004,R-005
Dependencies: 01, including the verified upstream JSON prerequisite.
## Ownership and boundaries
T-001 owns bootstrap protocol/source/tests. Later extraction into dedicated protocol directories requires a new exact ownership contract.
Future assignments must verify the then-current baseline and exact disjoint paths;
these proposed scopes do not authorize work in another repository.
## Contracts and data flow
LSP3.17 over stdio, UTF-8 JSON and byte-count Content-Length. Limits: header8192 bytes, body16777216 bytes, depth64. NEW frame reader and lifecycle processor are separately testable but main uses the same path. IDs are signed32-bit integers or strings; capability result is empty in milestone0.
## Implementation sequence
1. Read incremental headers/body with bounded allocation, support coalesced messages, reject missing/duplicate/overflow Content-Length and unsupported charset. Treat truncated/ambiguous framing as terminal rather than scan for a guessed next message.
2. Use upstream strict JSON plus required Unicode/protocol validation. Preserve string and signed32-bit ID values; accept finite integral values such as1.0 or1e0, rejecting fractional/out-of-range values before narrowing. Handle decimals in unknown/initialization fields. Invalid envelope/batch shapes receive InvalidRequest; malformed known-length JSON receives ParseError and permits the next frame. Ignore valid unmatched response envelopes, including null correlation IDs, without mutating lifecycle state; reject request/response hybrids.
3. Implement states before-initialize, initialized and shutdown. Pre-init requests receive ServerNotInitialized; repeated initialize is invalid; unknown initialized requests get MethodNotFound; unknown notifications produce no response.
4. Return serverInfo/version and capabilities:{}; shutdown returns null. Check shutdown-state errors before unknown-method handling. Exit0 follows shutdown, exit1 otherwise; broken writes/EOF cannot falsely report a completed exchange.
## Failure behavior and constraints
Keep diagnostics on stderr, even after malformed input. Avoid responses to notifications. Recover only when a valid frame length gives an unambiguous boundary. Allocation/stream errors terminate with a nonzero process status. Unsupported semantic methods remain unsupported rather than yielding empty fake results.
## Acceptance scenarios
1. Feed one byte at a time, split CRLF/body/UTF-8 sequences, concatenate frames and assert complete exact messages with no extra stdout.
2. Test lifecycle ordering, repeated initialize, pre-init/post-shutdown requests, unknown notifications, both exit statuses and premature EOF.
3. Exercise valid decimal/exponent options, integral-valued/fractional/out-of-range IDs, unmatched responses, escaped IDs/astral characters, raw controls, lone surrogates, invalid UTF-8, depth limits and length overflow; enforce subprocess deadlines. Review the actual upstream numeric representation before accepting its integration; current StrictJson cannot exercise decimal ID handling.
## Verification and integration
Run the documented configure/build/CTest commands from the repository README. Inspect ctest -N and test output for nonzero registration and real failures. Upstream main and local override use separate build trees.
Require fresh independent review of the implemented contract and affected integrations.
Keep the protocol library independent of future semantic services; added capabilities must be removable without changing lifecycle semantics. A failing JSON prerequisite blocks acceptance, not test execution.