summaryrefslogtreecommitdiff
path: root/lsp-write.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-27 13:13:49 -0500
committerpommicket <pommicket@gmail.com>2022-12-27 13:13:49 -0500
commit1379bfc2bfc8f96215d9187e72ac30dc5c94225f (patch)
treece23a710a70172593a97d04a14796bcbb10c1f1e /lsp-write.c
parent27b8b36aea3bb5913a600bc7e5b41f68557c2587 (diff)
fix LSP thread safety
Diffstat (limited to 'lsp-write.c')
-rw-r--r--lsp-write.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/lsp-write.c b/lsp-write.c
index 93bdd26..f633c2e 100644
--- a/lsp-write.c
+++ b/lsp-write.c
@@ -32,14 +32,6 @@ static const char *lsp_language_id(Language lang) {
return "text";
}
-static const char *lsp_document_path(LSP *lsp, LSPDocumentID document) {
- if (document >= arr_len(lsp->document_data)) {
- assert(0);
- return "";
- }
- return lsp->document_data[document].path;
-}
-
typedef struct {
LSP *lsp;
StrBuilder builder;
@@ -425,15 +417,15 @@ static void write_request(LSP *lsp, LSPRequest *request) {
} break;
case LSP_REQUEST_DID_CHANGE: {
LSPRequestDidChange *change = &request->data.change;
- if (change->document >= arr_len(lsp->document_data)) {
- assert(0);
- break;
- }
- LSPDocumentData *document = &lsp->document_data[change->document];
- ++document->version_number;
+ SDL_LockMutex(lsp->document_mutex);
+ assert(change->document < arr_len(lsp->document_data));
+ LSPDocumentData *document = &lsp->document_data[change->document];
+ u32 version = ++document->version_number;
+ SDL_UnlockMutex(lsp->document_mutex);
+
write_key_obj_start(o, "params");
write_key_obj_start(o, "textDocument");
- write_key_number(o, "version", (double)document->version_number);
+ write_key_number(o, "version", version);
write_key_file_uri(o, "uri", change->document);
write_obj_end(o);
write_key_arr_start(o, "contentChanges");