summaryrefslogtreecommitdiff
path: root/lsp-write.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-23 12:17:34 -0500
committerpommicket <pommicket@gmail.com>2022-12-23 12:17:34 -0500
commitbc21923ba75a46693f6470f9bff903e0df46ac15 (patch)
tree0f6ab5a910142861773591ea3845d700119e21c5 /lsp-write.c
parente8ebc051bd606df22622c012d68804e275ef1dd5 (diff)
LSP document_data
Diffstat (limited to 'lsp-write.c')
-rw-r--r--lsp-write.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/lsp-write.c b/lsp-write.c
index 4a56543..87cb238 100644
--- a/lsp-write.c
+++ b/lsp-write.c
@@ -167,14 +167,19 @@ static void write_arr_elem_string(JSONWriter *o, const char *s) {
write_string(o, s);
}
-static void write_file_uri(JSONWriter *o, DocumentID document) {
- const char *path = o->lsp->document_paths[document];
+static void write_file_uri(JSONWriter *o, LSPDocumentID document) {
+ if (document >= arr_len(o->lsp->document_data)) {
+ assert(0);
+ str_builder_append(&o->builder, "\"\"");
+ return;
+ }
+ const char *path = o->lsp->document_data[document].path;
str_builder_append(&o->builder, "\"file:///");
write_escaped(o, path);
str_builder_append(&o->builder, "\"");
}
-static void write_key_file_uri(JSONWriter *o, const char *key, DocumentID document) {
+static void write_key_file_uri(JSONWriter *o, const char *key, LSPDocumentID document) {
write_key(o, key);
write_file_uri(o, document);
}
@@ -251,6 +256,8 @@ static bool request_type_is_notification(LSPRequestType type) {
return false;
}
+// NOTE: don't call lsp_request_free after calling this function.
+// I will do it for you.
static void write_request(LSP *lsp, LSPRequest *request) {
JSONWriter writer = json_writer_new(lsp);
JSONWriter *o = &writer;
@@ -332,7 +339,7 @@ static void write_request(LSP *lsp, LSPRequest *request) {
write_key_obj_start(o, "textDocument");
write_key_file_uri(o, "uri", open->document);
write_key_string(o, "languageId", lsp_language_id(open->language));
- write_key_number(o, "version", 1);
+ write_key_number(o, "version", 0);
write_key_string(o, "text", open->file_contents);
write_obj_end(o);
write_obj_end(o);
@@ -347,11 +354,15 @@ static void write_request(LSP *lsp, LSPRequest *request) {
} break;
case LSP_REQUEST_DID_CHANGE: {
LSPRequestDidChange *change = &request->data.change;
- static unsigned long long version_number = 1; // @TODO @TEMPORARY
- ++version_number;
+ if (change->document >= arr_len(lsp->document_data)) {
+ assert(0);
+ break;
+ }
+ LSPDocumentData *document = &lsp->document_data[change->document];
+ ++document->version_number;
write_key_obj_start(o, "params");
write_key_obj_start(o, "textDocument");
- write_key_number(o, "version", (double)version_number);
+ write_key_number(o, "version", (double)document->version_number);
write_key_file_uri(o, "uri", change->document);
write_obj_end(o);
write_key_arr_start(o, "contentChanges");