Skip to content

Split ErrorCodes/LSPErrorCodes and enforce ResponseMessage result xor error#7

Merged
christiankissig merged 1 commit into
masterfrom
add-response-message-spec
Jun 3, 2026
Merged

Split ErrorCodes/LSPErrorCodes and enforce ResponseMessage result xor error#7
christiankissig merged 1 commit into
masterfrom
add-response-message-spec

Conversation

@christiankissig

Copy link
Copy Markdown
Owner

Summary

Implements ResponseMessage, ResponseError, and the error-code enums per LSP 3.17 — Response Message.

The spec defines two distinct error-code namespacesErrorCodes (JSON-RPC defined) and LSPErrorCodes (LSP defined) — but the library merged them into one ErrorCodes enum. It also documents that a response's result MUST NOT be present when there is an error, which was unenforced.

Changes

  • Split the enums to match the spec:
    • ErrorCodes keeps only the JSON-RPC codes (ParseError, InvalidRequest, MethodNotFound, InvalidParams, InternalError, ServerNotInitialized, UnknownErrorCode) and the JSON-RPC reserved-range markers (incl. the serverErrorStart/serverErrorEnd deprecated aliases).
    • New LSPErrorCodes enum carries the LSP-defined codes (RequestFailed, ServerCancelled, ContentModified, RequestCancelled) and the LSP reserved-range markers.
  • ResponseMessage gains a validator rejecting a message that carries both result and error.
  • Spec-accurate docstrings on ResponseError, ResponseMessage, and both enums; export LSPErrorCodes from lsp_client.

⚠️ Breaking change

The LSP-defined codes have moved off ErrorCodes onto LSPErrorCodes. Code referencing ErrorCodes.RequestCancelled / .ContentModified / .ServerCancelled / .RequestFailed (or the lspReserved* markers) must now use LSPErrorCodes.*. This matches the spec's namespace separation.

Testing

  • Updated test_error_codes_values and added tests for LSPErrorCodes values, namespace separation, a ResponseError built from an LSP code, and the new result-xor-error validator.
  • poetry run pytest (55 passed), ruff check, ruff format --check, and mypy all clean.

🤖 Generated with Claude Code

… error

The LSP responseMessage spec defines two distinct error-code namespaces:
ErrorCodes (JSON-RPC) and LSPErrorCodes (LSP-defined). They were merged
into a single ErrorCodes enum.

- Move RequestFailed / ServerCancelled / ContentModified / RequestCancelled
  and the LSP reserved-range markers into a new LSPErrorCodes enum; keep
  only JSON-RPC codes in ErrorCodes.
- Add a ResponseMessage validator rejecting a message that carries both
  result and error, per the spec's "result MUST NOT exist on error".
- Document ResponseError / ResponseMessage and both code enums; export
  LSPErrorCodes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@christiankissig christiankissig merged commit d23050d into master Jun 3, 2026
7 checks passed
@christiankissig christiankissig deleted the add-response-message-spec branch June 3, 2026 18:57
christiankissig added a commit that referenced this pull request Jul 7, 2026
Split ErrorCodes/LSPErrorCodes and enforce ResponseMessage result xor error
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