diff options
-rw-r--r-- | autocomplete.c | 5 | ||||
-rw-r--r-- | buffer.c | 9 | ||||
-rw-r--r-- | lsp-write-request.c | 13 | ||||
-rw-r--r-- | lsp.c | 1 | ||||
-rw-r--r-- | lsp.h | 6 | ||||
-rw-r--r-- | main.c | 4 |
6 files changed, 34 insertions, 4 deletions
diff --git a/autocomplete.c b/autocomplete.c index 2d1574e..1421201 100644 --- a/autocomplete.c +++ b/autocomplete.c @@ -123,6 +123,7 @@ static void autocomplete_find_completions(Ted *ted) { static void autocomplete_process_lsp_response(Ted *ted, const LSPResponse *response) { Autocomplete *ac = &ted->autocomplete; + bool was_waiting = ac->waiting_for_lsp; ac->waiting_for_lsp = false; if (!ac->open) { // user hit escape before completions arrived. @@ -149,7 +150,9 @@ static void autocomplete_process_lsp_response(Ted *ted, const LSPResponse *respo autocomplete_no_suggestions(ted); return; case 1: - autocomplete_complete(ted, ac->completions[ac->suggested[0]]); + // if we just finished loading suggestions, and there's only one suggestion, use it + if (was_waiting) + autocomplete_complete(ted, ac->completions[ac->suggested[0]]); return; } } @@ -746,6 +746,15 @@ static void buffer_line_free(Line *line) { // Free a buffer. Once a buffer is freed, you can call buffer_create on it again. // Does not free the pointer `buffer` (buffer might not have even been allocated with malloc) void buffer_free(TextBuffer *buffer) { + LSP *lsp = buffer_lsp(buffer); + if (lsp) { + LSPRequest did_close = {.type = LSP_REQUEST_DID_CLOSE}; + did_close.data.close = (LSPRequestDidClose){ + .document = lsp_document_id(lsp, buffer->filename) + }; + lsp_send_request(lsp, &did_close); + } + Line *lines = buffer->lines; u32 nlines = buffer->nlines; for (u32 i = 0; i < nlines; ++i) { diff --git a/lsp-write-request.c b/lsp-write-request.c index f375559..28b19d3 100644 --- a/lsp-write-request.c +++ b/lsp-write-request.c @@ -77,7 +77,7 @@ static void write_arr_elem(JSONWriter *o) { static void write_escaped(JSONWriter *o, const char *string) { StrBuilder *b = &o->builder; size_t output_index = str_builder_len(b); - size_t capacity = 2 * strlen(string) + 1; + size_t capacity = 2 * strlen(string) + 1; // append a bunch of null bytes which will hold the escaped string str_builder_append_null(b, capacity); char *out = str_builder_get_ptr(b, output_index); @@ -181,6 +181,8 @@ static const char *lsp_request_method(LSPRequest *request) { return "initialized"; case LSP_REQUEST_DID_OPEN: return "textDocument/didOpen"; + case LSP_REQUEST_DID_CLOSE: + return "textDocument/didClose"; case LSP_REQUEST_DID_CHANGE: return "textDocument/didChange"; case LSP_REQUEST_COMPLETION: @@ -200,6 +202,7 @@ static bool request_type_is_notification(LSPRequestType type) { case LSP_REQUEST_INITIALIZED: case LSP_REQUEST_EXIT: case LSP_REQUEST_DID_OPEN: + case LSP_REQUEST_DID_CLOSE: case LSP_REQUEST_DID_CHANGE: return true; case LSP_REQUEST_INITIALIZE: @@ -264,6 +267,14 @@ static void write_request(LSP *lsp, LSPRequest *request) { write_obj_end(o); write_obj_end(o); } break; + case LSP_REQUEST_DID_CLOSE: { + const LSPRequestDidClose *close = &request->data.close; + write_key_obj_start(o, "params"); + write_key_obj_start(o, "textDocument"); + write_key_file_uri(o, "uri", close->document); + write_obj_end(o); + write_obj_end(o); + } break; case LSP_REQUEST_DID_CHANGE: { LSPRequestDidChange *change = &request->data.change; static unsigned long long version_number = 1; // @TODO @TEMPORARY @@ -32,6 +32,7 @@ static void lsp_request_free(LSPRequest *r) { case LSP_REQUEST_SHUTDOWN: case LSP_REQUEST_EXIT: case LSP_REQUEST_COMPLETION: + case LSP_REQUEST_DID_CLOSE: break; case LSP_REQUEST_DID_OPEN: { LSPRequestDidOpen *open = &r->data.open; @@ -36,6 +36,7 @@ typedef enum { LSP_REQUEST_INITIALIZE, LSP_REQUEST_INITIALIZED, LSP_REQUEST_DID_OPEN, + LSP_REQUEST_DID_CLOSE, LSP_REQUEST_DID_CHANGE, LSP_REQUEST_COMPLETION, LSP_REQUEST_SHUTDOWN, @@ -53,6 +54,10 @@ typedef struct { char *file_contents; } LSPRequestDidOpen; +typedef struct { + DocumentID document; +} LSPRequestDidClose; + // see TextDocumentContentChangeEvent in the LSP spec typedef struct { LSPRange range; @@ -93,6 +98,7 @@ typedef struct { LSPRequestType type; union { LSPRequestDidOpen open; + LSPRequestDidClose close; LSPRequestDidChange change; LSPRequestCompletion completion; // for LSP_SHOW_MESSAGE and LSP_LOG_MESSAGE @@ -1,11 +1,11 @@ /* @TODO: -- send didClose -- don't select the one and only completion when user types stuff +- show detail and type - LSP setting - scroll through completions - figure out under which circumstances backspace should close completions - rename buffer->filename to buffer->path + - make buffer->path NULL for untitled buffers & fix resulting mess - rust-analyzer bug reports: - bad json can give "Unexpected error: client exited without proper shutdown sequence" - rust-analyzer should wait until cargo metadata/check is done before sending initialize response |