summaryrefslogtreecommitdiff
path: root/ide-definitions.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-29 18:44:37 -0500
committerpommicket <pommicket@gmail.com>2022-12-29 18:44:37 -0500
commitd77782564bf0a090a4e7fa4f4c4bb685383275dc (patch)
treea4bc3c0bf142c663ea7f293b4381927adc896f1c /ide-definitions.c
parent5f7af06a9085835a3d1ad3a51374c245859d7d97 (diff)
textDocument/definition for ctrl+click
Diffstat (limited to 'ide-definitions.c')
-rw-r--r--ide-definitions.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/ide-definitions.c b/ide-definitions.c
new file mode 100644
index 0000000..3a36a96
--- /dev/null
+++ b/ide-definitions.c
@@ -0,0 +1,41 @@
+void definition_goto(Ted *ted, LSP *lsp, const char *name, LSPDocumentPosition position) {
+ if (lsp) {
+ // send that request
+ LSPRequest request = {.type = LSP_REQUEST_DEFINITION};
+ request.data.definition.position = position;
+ lsp_send_request(lsp, &request);
+ } else {
+ // just go to the tag
+ tag_goto(ted, name);
+ }
+}
+
+void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *response) {
+ if (response->request.type != LSP_REQUEST_DEFINITION)
+ return;
+
+ const LSPResponseDefinition *response_def = &response->data.definition;
+ Definitions *defs = &ted->definitions;
+
+ if (defs->last_response_lsp == lsp->id
+ && response->request.id < defs->last_response_id) {
+ // we just processed a later response, so let's ignore this
+ return;
+ }
+ defs->last_response_lsp = lsp->id;
+ defs->last_response_id = response->request.id;
+
+ if (!arr_len(response_def->locations)) {
+ // no definition. do the error cursor.
+ ted_flash_error_cursor(ted);
+ return;
+ }
+ LSPLocation location = response_def->locations[0];
+ const char *path = lsp_document_path(lsp, location.document);
+ if (!ted_open_file(ted, path)) {
+ ted_flash_error_cursor(ted);
+ return;
+ }
+ LSPDocumentPosition position = lsp_location_start_position(location);
+ ted_go_to_lsp_document_position(ted, lsp, position);
+}