Files
jak-project/lsp/handlers/text_document/document_synchronization.h
T
Tyler Wilding 01c70368e3 LSP: initial LSP implementation for IR files to assist with decompilation (#1647)
* 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
2022-07-18 18:26:57 -04:00

68 lines
2.3 KiB
C++

#include <optional>
#include "lsp/protocol/document_diagnostics.h"
#include "lsp/protocol/document_synchronization.h"
#include "lsp/state/workspace.h"
#include "third-party/json.hpp"
using json = nlohmann::json;
void did_open_handler(Workspace& workspace, json raw_params) {
auto params = raw_params.get<LSPSpec::DidOpenTextDocumentParams>();
workspace.start_tracking_file(params.m_textDocument.m_uri, params.m_textDocument.m_languageId,
params.m_textDocument.m_text);
}
void did_change_handler(Workspace& workspace, json raw_params) {
auto params = raw_params.get<LSPSpec::DidChangeTextDocumentParams>();
for (const auto& change : params.m_contentChanges) {
workspace.update_tracked_file(params.m_textDocument.m_uri, change.m_text);
}
}
void did_close_handler(Workspace& workspace, json raw_params) {
auto params = raw_params.get<LSPSpec::DidCloseTextDocumentParams>();
workspace.stop_tracking_file(params.m_textDocument.m_uri);
}
std::optional<json> did_open_push_diagnostics(Workspace& workspace, json params) {
auto converted_params = params.get<LSPSpec::DidOpenTextDocumentParams>();
auto tracked_file = workspace.get_tracked_ir_file(converted_params.m_textDocument.m_uri);
if (!tracked_file) {
return {};
}
LSPSpec::PublishDiagnosticParams publish_params;
publish_params.m_uri = converted_params.m_textDocument.m_uri;
publish_params.m_diagnostics = tracked_file.value().m_diagnostics;
publish_params.m_version = converted_params.m_textDocument.m_version;
json response;
response["method"] = "textDocument/publishDiagnostics";
response["params"] = publish_params;
return response;
}
std::optional<json> did_change_push_diagnostics(Workspace& workspace, json raw_params) {
auto params = raw_params.get<LSPSpec::DidChangeTextDocumentParams>();
auto tracked_file = workspace.get_tracked_ir_file(params.m_textDocument.m_uri);
if (!tracked_file) {
return {};
}
LSPSpec::PublishDiagnosticParams publish_params;
publish_params.m_uri = params.m_textDocument.m_uri;
publish_params.m_diagnostics = tracked_file.value().m_diagnostics;
publish_params.m_version = params.m_textDocument.m_version;
json response;
response["method"] = "textDocument/publishDiagnostics";
response["params"] = publish_params;
return response;
}