mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 11:26:18 -04:00
01c70368e3
* lsp: json-rpc example is working, a decent place to start... * lsp: vendor library * lsp: cleanup and time to get started * lsp: commit what i got so far * lsp: example `initialize` payload * lsp: switch to `stdio` * stash * modularize the lsp implementation * lsp: implement first actual LSP feature - function names in outline * lsp: produce document diagnostics * lsp: remove unused third-party lib * lsp: support hovering MIPS instructions in IR files * lsp: basic go-to all-types definition * stash * lsp: cleanup code, just need to add it to the release artifacts * fix some project configuration * fix linux build * lsp: add lsp to PR artifacts and release assets * lsp: address feedback
48 lines
1.6 KiB
C++
48 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
#include "lsp/state/app.h"
|
|
#include "lsp/state/workspace.h"
|
|
#include "lsp/transport/stdio.h"
|
|
|
|
#include "third-party/json.hpp"
|
|
|
|
using json = nlohmann::json;
|
|
|
|
enum class LSPRouteType { NOOP = 0, NOTIFICATION = 1, REQUEST_RESPONSE = 2 };
|
|
|
|
class LSPRoute {
|
|
public:
|
|
LSPRoute();
|
|
LSPRoute(std::function<void(Workspace&, json)> notification_handler);
|
|
LSPRoute(std::function<void(Workspace&, json)> notification_handler,
|
|
std::function<std::optional<json>(Workspace&, json)> post_notification_publish);
|
|
LSPRoute(std::function<std::optional<json>(Workspace&, int, json)> request_handler);
|
|
|
|
LSPRouteType m_route_type;
|
|
|
|
/// @brief Handle a notification -- this requires no response to the client
|
|
std::function<void(Workspace&, json)> m_notification_handler;
|
|
/// @brief Handle a new request from the client that expects a response
|
|
std::function<std::optional<json>(Workspace&, int, json)> m_request_handler;
|
|
/// @brief Prepares a notification response body to be published _after_ the main handler is
|
|
/// processed
|
|
std::optional<std::function<std::optional<json>(Workspace&, json)>> m_post_notification_publish;
|
|
/// @brief Generic function to perform some action after processing
|
|
std::optional<std::function<void(Workspace&)>> m_generic_post_action;
|
|
};
|
|
|
|
class LSPRouter {
|
|
public:
|
|
void init_routes();
|
|
std::optional<std::vector<std::string>> route_message(const MessageBuffer& message_buffer,
|
|
AppState& appstate);
|
|
std::string make_response(const json& result);
|
|
|
|
private:
|
|
std::unordered_map<std::string, LSPRoute> m_routes;
|
|
;
|
|
};
|