Skip to content

Commit

Permalink
fix: Unknown requests were dropped without a proper response
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Mar 19, 2024
1 parent ea812ce commit 9366130
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
3 changes: 3 additions & 0 deletions clients/vscode-hlasmplugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
- New document outline implementation
- Fallback to WebAssembly language server automatically

#### Fixed
- Unknown requests were dropped without a proper response

## [1.12.0](https://github.com/eclipse-che4z/che-che4z-lsp-for-hlasm/compare/1.11.1...1.12.0) (2024-03-05)

#### Added
Expand Down
9 changes: 9 additions & 0 deletions language_server/src/lsp/lsp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ void server::message_received(const nlohmann::json& message)
{
LOG_ERROR(e.what());
send_telemetry_error("lsp_server/method_unknown_error");
if (id)
respond_error(id.value(),
"",
-32803,
"RequestFailed",
{
{ "method", method_found.value().get<std::string>() },
{ "exception", e.what() },
});
}
}
}
Expand Down
14 changes: 4 additions & 10 deletions language_server/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,7 @@ void server::call_method(const std::string& method, std::optional<request_id> id
// - notification can be ignored
// - requests should be responded to with MethodNotFound
if (id)
send_message_->reply(nlohmann::json {
{ "id", nlohmann ::json(*id) },
{
"error",
{
{ "code", -32601 },
{ "message", "MethodNotFound" },
},
},
});
respond_error(id.value(), method, -32601, "MethodNotFound", {});
}
else
{
Expand All @@ -96,6 +87,9 @@ void server::call_method(const std::string& method, std::optional<request_id> id
LOG_WARNING(ss.str());

send_telemetry_error("method_not_implemented", method);

if (id)
respond_error(id.value(), method, -32601, "MethodNotFound", {});
}
}

Expand Down
8 changes: 7 additions & 1 deletion language_server/test/lsp/lsp_server_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ TEST(lsp_server, not_implemented_method)
"method_name":"server_error/method_not_implemented",
"properties":{"error_details":"unknown_method"}
}})"_json;
auto expected_not_implemented =
R"({"jsonrpc":"2.0","id":47,"error":{
"code":-32601,
"message":"MethodNotFound",
"data":null
}})"_json;

// Only telemetry expected
EXPECT_CALL(smpm, reply(expected_not_implemented));
EXPECT_CALL(smpm, reply(expected_telemetry));

s.message_received(j);
Expand Down

0 comments on commit 9366130

Please sign in to comment.