summaryrefslogtreecommitdiff
path: root/lsp-write.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-26 20:41:43 -0500
committerpommicket <pommicket@gmail.com>2022-12-26 20:41:43 -0500
commit9a5cad47fe6a8b84892f62e110ca887c95df5eff (patch)
tree48f5bcdf4d36d11716d233e98f52d1a9cb583143 /lsp-write.c
parent44d607df5d5a9a1c892fe56c4874fbef7f209464 (diff)
workspace/workspaceFolders request
Diffstat (limited to 'lsp-write.c')
-rw-r--r--lsp-write.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/lsp-write.c b/lsp-write.c
index ef60b91..5d402c4 100644
--- a/lsp-write.c
+++ b/lsp-write.c
@@ -463,9 +463,9 @@ static void write_request(LSP *lsp, LSPRequest *request) {
if (is_notification) {
lsp_request_free(request);
} else {
- SDL_LockMutex(lsp->requests_mutex);
+ SDL_LockMutex(lsp->messages_mutex);
arr_add(lsp->requests_sent, *request);
- SDL_UnlockMutex(lsp->requests_mutex);
+ SDL_UnlockMutex(lsp->messages_mutex);
}
}
@@ -477,24 +477,38 @@ static void write_response(LSP *lsp, LSPResponse *response) {
JSONWriter *o = &writer;
LSPRequest *request = &response->request;
- if (request->id_string)
- write_key_string(o, "id", request->id_string);
- else
- write_key_number(o, "id", request->id);
- write_key_obj_start(o, "result");
-
- switch (response->request.type) {
- case LSP_REQUEST_WORKSPACE_FOLDERS:
- write_workspace_folders(o, lsp->workspace_folders);
- break;
- default:
- // this is not a valid client-to-server response.
- assert(0);
- break;
- }
+ write_obj_start(o);
+ if (request->id_string)
+ write_key_string(o, "id", request->id_string);
+ else
+ write_key_number(o, "id", request->id);
+ write_key_string(o, "jsonrpc", "2.0");
+ write_key(o, "result");
+ switch (response->request.type) {
+ case LSP_REQUEST_WORKSPACE_FOLDERS:
+ write_workspace_folders(o, lsp->workspace_folders);
+ break;
+ default:
+ // this is not a valid client-to-server response.
+ assert(0);
+ break;
+ }
write_obj_end(o);
message_writer_write_and_free(lsp, o);
-
lsp_response_free(response);
}
+
+static void write_message(LSP *lsp, LSPMessage *message) {
+ switch (message->type) {
+ case LSP_REQUEST:
+ write_request(lsp, &message->u.request);
+ break;
+ case LSP_RESPONSE:
+ write_response(lsp, &message->u.response);
+ break;
+ }
+ // it's okay to free the message here since the request/response part has been zeroed.
+ // (as i'm writing this, this won't do anything but it might in the future)
+ lsp_message_free(message);
+}