diff options
-rw-r--r-- | ide-definitions.c | 8 | ||||
-rw-r--r-- | lsp.c | 18 | ||||
-rw-r--r-- | lsp.h | 16 | ||||
-rw-r--r-- | ted.h | 11 |
4 files changed, 30 insertions, 23 deletions
diff --git a/ide-definitions.c b/ide-definitions.c index 8648325..a748173 100644 --- a/ide-definitions.c +++ b/ide-definitions.c @@ -5,7 +5,6 @@ void definition_goto(Ted *ted, LSP *lsp, const char *name, LSPDocumentPosition p LSPRequest request = {.type = LSP_REQUEST_DEFINITION}; request.data.definition.position = position; LSPRequestID id = lsp_send_request(lsp, &request); - defs->last_request_lsp = lsp->id; defs->last_request_id = id; defs->last_request_time = ted->frame_time; } else { @@ -16,7 +15,6 @@ void definition_goto(Ted *ted, LSP *lsp, const char *name, LSPDocumentPosition p void definition_cancel_lookup(Ted *ted) { Definitions *defs = &ted->definitions; - defs->last_request_lsp = 0; defs->last_request_id = 0; } @@ -27,13 +25,11 @@ void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *res const LSPResponseDefinition *response_def = &response->data.definition; Definitions *defs = &ted->definitions; - if (defs->last_request_lsp != lsp->id - || response->request.id != defs->last_request_id) { + if (response->request.id != defs->last_request_id) { // response to an old request return; } - defs->last_request_lsp = 0; defs->last_request_id = 0; if (!arr_len(response_def->locations)) { @@ -53,7 +49,7 @@ void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *res void definitions_frame(Ted *ted) { Definitions *defs = &ted->definitions; - if (defs->last_request_lsp && timespec_sub(ted->frame_time, defs->last_request_time) > 0.2) { + if (defs->last_request_id && timespec_sub(ted->frame_time, defs->last_request_time) > 0.2) { ted->cursor = ted->cursor_wait; } } @@ -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); @@ -301,6 +301,18 @@ typedef struct { LSPLocation *locations; } LSPResponseDefinition; +// SymbolInformation in the LSP spec +typedef struct { + LSPString name; + LSPSymbolKind kind; + bool deprecated; + LSPLocation location; +} LSPSymbolInformation; + +typedef struct { + LSPSymbolInformation *symbols; +} LSPResponseWorkspaceSymbols; + typedef LSPRequestType LSPResponseType; typedef struct { LSPRequest request; // the request which this is a response to @@ -356,10 +368,6 @@ typedef struct LSP { // thread-safety: created in lsp_create, then only accessed by the communication thread Process process; - // Which ID number the next request will get - // thread-safety: atomic, all that matters is `LSPRequestID id = ++lsp->request_id;` works - _Atomic LSPRequestID request_id; - SDL_mutex *document_mutex; // for our purposes, folders are "documents" // the spec kinda does this too: WorkspaceFolder has a `uri: DocumentUri` member. @@ -242,8 +242,8 @@ typedef struct { u32 nlines; u32 lines_capacity; - // which LSP this document is open in (this is a LSPID) - u32 lsp_opened_in; + // which LSP this document is open in + LSPID lsp_opened_in; u32 undo_history_write_pos; // where in the undo history was the last write? used by buffer_unsaved_changes u32 first_line_on_screen, last_line_on_screen; // which lines are on screen? updated when buffer_render is called. @@ -414,12 +414,11 @@ typedef struct { } Hover; typedef struct { - // LSPID and ID of the last request which was sent out. + // ID of the last request which was sent out. // used to process responses in chronological order (= ID order). // if we got a response for the last request, or no requests have been made, - // last_request_lsp is set to 0. - LSPID last_request_lsp; - u32 last_request_id; + // last_request_id is set to 0. + LSPRequestID last_request_id; struct timespec last_request_time; } Definitions; |