Skip to content

Language-feature requests: typed params/results + request-response correlation#14

Merged
christiankissig merged 1 commit into
masterfrom
language-feature-requests
Jun 5, 2026
Merged

Language-feature requests: typed params/results + request-response correlation#14
christiankissig merged 1 commit into
masterfrom
language-feature-requests

Conversation

@christiankissig

Copy link
Copy Markdown
Owner

Implements #13 — the general LSP pieces downstream clients need for language features (hover, completion, definition, documentSymbol, documentHighlight).

1. Request/response correlation (client.py)

  • LSPClient tracks in-flight requests in _pending_requests: dict[id, asyncio.Future].
  • New request(request, timeout=...) coroutine sends a request and awaits its result, correlating the response by id. Raises LSPError on a ResponseError; on timeout it fires $/cancelRequest and raises asyncio.TimeoutError.
  • New cancel_request(id) sends a spec-correct $/cancelRequest notification (no top-level id).
  • _handle_response resolves/rejects the matching future and still forwards server-initiated requests, notifications, and unmatched responses to the existing response_handler.
  • Default timeout configurable via request_timeout on __init__ / from_command. send_request stays fire-and-forget for backward compatibility.

2. Request types + typed params (protocol.py)

  • New DocumentSymbolRequest and DocumentHighlightRequest.
  • Hover/Completion/Definition (and the two new requests) accept a typed params model or a raw dict, via a shared _coerce_params helper — existing dict-based callers are unaffected.
  • CompletionParams with optional CompletionContext { triggerKind, triggerCharacter? }.

3. Result models + union parsers (protocol.py)

  • Hover: Hover, MarkupContent, MarkupKind, MarkedString.
  • Completion: CompletionList, CompletionItem, CompletionItemKind, InsertTextFormat, TextEdit, InsertReplaceEdit, CompletionTriggerKind.
  • Definition: LocationLink (alongside existing Location).
  • DocumentSymbol: DocumentSymbol (recursive), SymbolInformation, SymbolKind, SymbolTag.
  • DocumentHighlight: DocumentHighlight, DocumentHighlightKind.
  • Five parse_*_result helpers that validate and normalise each runtime union (bare CompletionItem[]CompletionList, single Location[Location], LocationLink vs Location by targetUri, DocumentSymbol vs SymbolInformation by location).

All new names are exported from lsp_client/__init__.py.

Acceptance

  • ✅ A caller can issue each request and await a typed, validated result (or None).
  • ✅ Result-union parsing helpers for definition/completion/documentSymbol (+ hover/highlight).
  • ✅ Correlation covered by tests: resolve-by-id, error propagation, timeout+cancel, default timeout, unmatched-response passthrough.

Checks

  • poetry run pytest — 101 passed
  • poetry run ruff check . / ruff format --check . — clean
  • poetry run mypy . — clean

🤖 Generated with Claude Code

…orrelation

Implements #13.

Request/response correlation (client.py):
- Track in-flight requests in a dict[id, asyncio.Future].
- New `request()` coroutine awaits a response result, correlating by id,
  raising `LSPError` on a ResponseError and TimeoutError (after sending
  `$/cancelRequest`) on timeout. Configurable via `request_timeout`.
- New `cancel_request()` sends a spec-correct `$/cancelRequest` notification.
- `_handle_response` resolves/rejects the matching future and forwards
  server-initiated and unmatched messages to `response_handler`.

Typed params (protocol.py):
- New `DocumentSymbolRequest` / `DocumentHighlightRequest`.
- Hover/Completion/Definition accept typed params models or a raw dict.
- `CompletionParams` with optional `CompletionContext`.

Result models + union parsers (protocol.py):
- Hover, Completion, Definition, DocumentSymbol, DocumentHighlight models
  per LSP 3.17, plus five `parse_*_result` helpers that validate and
  normalise each runtime union.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@christiankissig christiankissig merged commit e06b399 into master Jun 5, 2026
7 checks passed
@christiankissig christiankissig deleted the language-feature-requests branch June 5, 2026 05:36
christiankissig added a commit that referenced this pull request Jul 7, 2026
Language-feature requests: typed params/results + request-response correlation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant