summaryrefslogtreecommitdiff
path: root/lsp.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-30 11:05:19 -0500
committerpommicket <pommicket@gmail.com>2022-12-30 11:05:19 -0500
commit4232df89b50754779814a97f374451fce2e36447 (patch)
treec7bfa4bb445717cc34b24a905b3c4b8398126422 /lsp.c
parent61db5a1a07f4fbe953d7cab9b6714fe5157a1265 (diff)
global request IDs
Diffstat (limited to 'lsp.c')
-rw-r--r--lsp.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/lsp.c b/lsp.c
index f45603e..3efa830 100644
--- a/lsp.c
+++ b/lsp.c
@@ -15,6 +15,13 @@ static void lsp_response_free(LSPResponse *r);
#include "lsp-write.c"
#include "lsp-parse.c"
+// it's nice to have request IDs be totally unique, including across LSP servers.
+static LSPRequestID get_request_id(void) {
+ static _Atomic LSPRequestID last_request_id;
+ // it's important that this never returns 0, since that's reserved for "no ID"
+ return ++last_request_id;
+}
+
bool lsp_get_error(LSP *lsp, char *error, size_t error_size, bool clear) {
bool has_err = false;
SDL_LockMutex(lsp->error_mutex);
@@ -201,15 +208,12 @@ LSPRequestID lsp_send_request(LSP *lsp, LSPRequest *request) {
}
bool is_notification = request_type_is_notification(request->type);
- LSPRequestID id = 0;
- if (!is_notification) {
- id = ++lsp->request_id;
- request->id = id;
- }
+ if (!is_notification)
+ request->id = get_request_id();
LSPMessage message = {.type = LSP_REQUEST};
message.u.request = *request;
lsp_send_message(lsp, &message);
- return id;
+ return request->id;
}
void lsp_send_response(LSP *lsp, LSPResponse *response) {
@@ -434,7 +438,7 @@ LSP *lsp_create(const char *root_dir, Language language, const char *analyzer_co
LSPRequest initialize = {
.type = LSP_REQUEST_INITIALIZE
};
- initialize.id = ++lsp->request_id;
+ initialize.id = get_request_id();
// immediately send the request rather than queueing it.
// this is a small request, so it shouldn't be a problem.
write_request(lsp, &initialize);