lsp: fix route handling json error (#2448)

This commit is contained in:
Tyler Wilding
2023-04-01 18:40:21 -05:00
committed by GitHub
parent b141871bd1
commit 57a3254668
2 changed files with 24 additions and 20 deletions
+3 -3
View File
@@ -64,7 +64,7 @@ std::optional<std::vector<std::string>> LSPRouter::route_message(
const MessageBuffer& message_buffer,
AppState& appstate) {
const json& body = message_buffer.body();
auto& method = body["method"];
const auto method = body.at("method").get<std::string>();
// If the workspace has not yet been initialized but the client sends a
// message that doesn't have method "initialize" then we'll return an error
@@ -76,7 +76,7 @@ std::optional<std::vector<std::string>> LSPRouter::route_message(
}
// Exit early if we can't handle the route
if (m_routes.count(method) == 0) {
if (m_routes.find(method) == m_routes.end()) {
lg::warn("Method not supported '{}'", method);
auto error = {make_response(
error_resp(ErrorCodes::MethodNotFound, fmt::format("Method '{}' not supported", method)))};
@@ -84,7 +84,7 @@ std::optional<std::vector<std::string>> LSPRouter::route_message(
}
try {
auto route = m_routes[method];
auto& route = m_routes.at(method);
std::vector<json> resp_bodies;
// Handle the request/notificiation
switch (route.m_route_type) {
+21 -17
View File
@@ -83,28 +83,32 @@ int main(int argc, char** argv) {
_setmode(_fileno(stdin), _O_BINARY);
#endif
char c;
MessageBuffer message_buffer;
while (std::cin.get(c)) {
message_buffer.handle_char(c);
try {
char c;
MessageBuffer message_buffer;
while (std::cin.get(c)) {
message_buffer.handle_char(c);
if (message_buffer.message_completed()) {
json body = message_buffer.body();
auto method_name = body["method"].get<std::string>();
lg::info(">>> Received message of method '{}'", method_name);
auto responses = lsp_router.route_message(message_buffer, appstate);
if (responses) {
for (const auto& response : responses.value()) {
std::cout << response.c_str() << std::flush;
if (appstate.verbose) {
lg::debug("<<< Sending message: {}", response);
} else {
lg::info("<<< Sending message of method '{}'", method_name);
if (message_buffer.message_completed()) {
json body = message_buffer.body();
auto method_name = body["method"].get<std::string>();
lg::info(">>> Received message of method '{}'", method_name);
auto responses = lsp_router.route_message(message_buffer, appstate);
if (responses) {
for (const auto& response : responses.value()) {
std::cout << response.c_str() << std::flush;
if (appstate.verbose) {
lg::debug("<<< Sending message: {}", response);
} else {
lg::info("<<< Sending message of method '{}'", method_name);
}
}
}
message_buffer.clear();
}
message_buffer.clear();
}
} catch (std::exception& e) {
lg::error("Unexpected LSP Exception occured - {}", e.what());
}
return 0;