mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 00:57:44 -04:00
53277a65ad
- Integrate the AST into the LSP, this makes parsing and tokenizing the files much easier - Consolidate most of the symbol info tracking in `goalc` to a single map. Fixed some issues where the old map would never evict symbols when re-compiling files. There is still some more to cleanup, but this now can be used as an incrementally updated source-of-truth for the LSP - re-compile files when they are saved. Ideally this would be done everytime they are changed but that: - may be too aggressive - goalc doesn't compile incrementally yet so it likely would be a worse UX Features added, see https://github.com/open-goal/opengoal-vscode/issues/256 - Hover ![image](https://github.com/open-goal/jak-project/assets/13153231/58dadb5d-582c-4c1f-9ffe-eaa4c85a0255) ![image](https://github.com/open-goal/jak-project/assets/13153231/b383adde-57fc-462c-a256-b2de5c30ca9a) - LSP Status fixed - Type Hierarchy ![image](https://github.com/open-goal/jak-project/assets/13153231/8e681377-1d4e-4336-ad70-1695a4607340) - Document Color ![image](https://github.com/open-goal/jak-project/assets/13153231/4e48ccd8-0ed1-4459-a133-5277561e4201) - Document Symbols ![Screenshot 2024-03-27 004105](https://github.com/open-goal/jak-project/assets/13153231/8e655034-43c4-4261-b6e0-85de00cbfc7f) - Completions ![Screenshot 2024-03-30 004504](https://github.com/open-goal/jak-project/assets/13153231/d123a187-af90-466b-9eb7-561b2ee97cd1) --------- Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
91 lines
3.4 KiB
C++
91 lines
3.4 KiB
C++
#include "lsp_requester.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include "common/log/log.h"
|
|
#include "common/util/string_util.h"
|
|
|
|
#include "lsp/protocol/progress_report.h"
|
|
|
|
void LSPRequester::send_request(const json& params, const std::string& method) {
|
|
json req;
|
|
req["id"] = str_util::uuid();
|
|
req["method"] = method;
|
|
req["params"] = params;
|
|
req["jsonrpc"] = "2.0";
|
|
|
|
std::string request;
|
|
request.append("Content-Length: " + std::to_string(req.dump().size()) + "\r\n");
|
|
request.append("Content-Type: application/vscode-jsonrpc;charset=utf-8\r\n");
|
|
request.append("\r\n");
|
|
request += req.dump();
|
|
|
|
// Send requests immediately, as they may be done during the handling of a client request
|
|
lg::info("Sending Request {}", method);
|
|
std::cout << request.c_str() << std::flush;
|
|
}
|
|
|
|
void LSPRequester::send_notification(const json& params, const std::string& method) {
|
|
json notification;
|
|
notification["method"] = method;
|
|
notification["params"] = params;
|
|
notification["jsonrpc"] = "2.0";
|
|
|
|
std::string request;
|
|
request.append("Content-Length: " + std::to_string(notification.dump().size()) + "\r\n");
|
|
request.append("Content-Type: application/vscode-jsonrpc;charset=utf-8\r\n");
|
|
request.append("\r\n");
|
|
request += notification.dump();
|
|
|
|
// Send requests immediately, as they may be done during the handling of a client request
|
|
lg::info("Sending Notification {}", method);
|
|
std::cout << request.c_str() << std::flush;
|
|
}
|
|
|
|
void LSPRequester::send_progress_create_request(const std::string& title,
|
|
const std::string& message,
|
|
const int percentage) {
|
|
const std::string token = fmt::format("opengoal/{}", title);
|
|
LSPSpec::WorkDoneProgressCreateParams createRequest;
|
|
createRequest.token = token;
|
|
send_request(createRequest, "window/workDoneProgress/create");
|
|
LSPSpec::WorkDoneProgressBegin beginPayload;
|
|
beginPayload.title = title;
|
|
beginPayload.cancellable = false; // TODO - maybe one day
|
|
beginPayload.message = message;
|
|
if (percentage > 0) {
|
|
beginPayload.percentage = percentage;
|
|
}
|
|
LSPSpec::ProgressNotificationPayload notification;
|
|
notification.token = token;
|
|
notification.beginValue = beginPayload;
|
|
send_notification(notification, "$/progress");
|
|
}
|
|
|
|
void LSPRequester::send_progress_update_request(const std::string& title,
|
|
const std::string& message,
|
|
const int percentage) {
|
|
const std::string token = fmt::format("opengoal/{}", title);
|
|
LSPSpec::WorkDoneProgressReport reportPayload;
|
|
reportPayload.cancellable = false; // TODO - maybe one day
|
|
reportPayload.message = message;
|
|
if (percentage > 0) {
|
|
reportPayload.percentage = percentage;
|
|
}
|
|
LSPSpec::ProgressNotificationPayload notification;
|
|
notification.token = token;
|
|
notification.reportValue = reportPayload;
|
|
send_notification(notification, "$/progress");
|
|
}
|
|
|
|
void LSPRequester::send_progress_finish_request(const std::string& title,
|
|
const std::string& message) {
|
|
const std::string token = fmt::format("opengoal/{}", title);
|
|
LSPSpec::WorkDoneProgressEnd endPayload;
|
|
endPayload.message = message;
|
|
LSPSpec::ProgressNotificationPayload notification;
|
|
notification.token = token;
|
|
notification.endValue = endPayload;
|
|
send_notification(notification, "$/progress");
|
|
}
|