diff options
-rw-r--r-- | buffer.c | 16 | ||||
-rw-r--r-- | lsp-write-request.c | 2 | ||||
-rw-r--r-- | lsp.c | 10 | ||||
-rw-r--r-- | lsp.h | 3 |
4 files changed, 23 insertions, 8 deletions
@@ -1370,6 +1370,12 @@ static Status buffer_insert_lines(TextBuffer *buffer, u32 where, u32 number) { return false; } +static void buffer_send_lsp_did_change_request(LSP *lsp, TextBuffer *buffer, BufferPos pos, + u32 nchars_deleted, String32 new_text) { + // @TODO + abort(); +} + // inserts the given text, returning the position of the end of the text BufferPos buffer_insert_text_at_pos(TextBuffer *buffer, BufferPos pos, String32 str) { buffer_pos_validate(buffer, &pos); @@ -1404,6 +1410,10 @@ BufferPos buffer_insert_text_at_pos(TextBuffer *buffer, BufferPos pos, String32 str32_remove_all_instances_of_char(&str, '\r'); + LSP *lsp = buffer_lsp(buffer); + if (lsp) + buffer_send_lsp_did_change_request(lsp, buffer, pos, 0, str); + if (buffer->store_undo_events) { BufferEdit *last_edit = arr_lastp(buffer->undo_history); i64 where_in_last_edit = last_edit ? buffer_pos_diff(buffer, last_edit->pos, pos) : -1; @@ -1650,6 +1660,10 @@ void buffer_delete_chars_at_pos(TextBuffer *buffer, BufferPos pos, i64 nchars_) // Not doing this might also cause other bugs, best to keep it here just in case. nchars = (u32)buffer_get_text_at_pos(buffer, pos, NULL, nchars); + LSP *lsp = buffer_lsp(buffer); + if (lsp) + buffer_send_lsp_did_change_request(lsp, buffer, pos, nchars, (String32){0}); + if (buffer->store_undo_events) { // we need to make sure the undo history keeps track of the edit. // we will either combine it with the previous BufferEdit, or create a new @@ -2135,7 +2149,7 @@ Status buffer_load_file(TextBuffer *buffer, char const *filename) { LSPRequest request = {.type = LSP_REQUEST_DID_OPEN}; LSPRequestDidOpen *open = &request.data.open; open->file_contents = (char *)file_contents; - open->path = str_dup(filename); + open->document = str_dup(filename); open->language = buffer_language(buffer); lsp_send_request(lsp, &request); file_contents = NULL; // don't free diff --git a/lsp-write-request.c b/lsp-write-request.c index 121392d..b7ce148 100644 --- a/lsp-write-request.c +++ b/lsp-write-request.c @@ -229,7 +229,7 @@ static void write_request(LSP *lsp, LSPRequest *request) { const LSPRequestDidOpen *open = &request->data.open; write_key_obj_start(o, "params"); write_key_obj_start(o, "textDocument"); - write_key_file_uri(o, "uri", open->path); + 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_string(o, "text", open->file_contents); @@ -42,7 +42,7 @@ static void lsp_request_free(LSPRequest *r) { } break; case LSP_REQUEST_DID_OPEN: { LSPRequestDidOpen *open = &r->data.open; - free(open->path); + free(open->document); free(open->file_contents); } break; case LSP_REQUEST_SHOW_MESSAGE: @@ -618,7 +618,9 @@ void lsp_free(LSP *lsp) { void lsp_document_changed(LSP *lsp, const char *document, LSPDocumentChangeEvent change) { // @TODO(optimization, eventually): batch changes (using the contentChanges array) - //LSPRequest request = {.type = LSP_REQUEST_DID_CHANGE}; - //LSPRequestDidChange *change = &request.change; - abort(); // @TODO + LSPRequest request = {.type = LSP_REQUEST_DID_CHANGE}; + LSPRequestDidChange *c = &request.data.change; + c->document = str_dup(document); + arr_add(c->changes, change); + lsp_send_request(lsp, &request); } @@ -1,5 +1,4 @@ // @TODO: -// - make a real JSON output library // - use document IDs instead of strings (also lets us use real document version numbers) // - document this and lsp.c. // - maximum queue size for requests/responses just in case? @@ -48,7 +47,7 @@ typedef struct { // buffer language Language language; // freed by lsp_request_free - char *path; + char *document; // freed by lsp_request_free char *file_contents; } LSPRequestDidOpen; |