fix: omit params field when None in JSON-RPC requests/notifications

According to JSON-RPC 2.0 specification, the params field must be a
structured value (object or array) if present. Sending "params": null
violates the spec and causes strict implementations to reject the request.

This fix modifies make_request() and make_notification() to omit the
params field entirely when params is None, instead of including it as null.
This commit is contained in:
zen010101 committed 2025-12-17 20:17:34 +08:00
1 parent 984e43d03e
commit 7eda0750a0
1 file changed
+6 -2
+6 -2
View File
@@ -92,11 +92,15 @@ def make_error_response(request_id: Any, err: LSPError) -> StringDict:
def make_notification(method: str, params: PayloadLike) -> StringDict:
return {"jsonrpc": "2.0", "method": method, "params": params}
# JSON-RPC 2.0: params must be object or array if present, cannot be null
# Some language servers require params to be present, so we send empty object instead of omitting
return {"jsonrpc": "2.0", "method": method, "params": params if params is not None else {}}
def make_request(method: str, request_id: Any, params: PayloadLike) -> StringDict:
return {"jsonrpc": "2.0", "method": method, "id": request_id, "params": params}
# JSON-RPC 2.0: params must be object or array if present, cannot be null
# Some language servers require params to be present, so we send empty object instead of omitting
return {"jsonrpc": "2.0", "method": method, "id": request_id, "params": params if params is not None else {}}
class StopLoopException(Exception):