summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ide-definitions.c12
-rw-r--r--lsp.c12
-rw-r--r--lsp.h2
-rw-r--r--main.c6
-rw-r--r--ted.c10
5 files changed, 35 insertions, 7 deletions
diff --git a/ide-definitions.c b/ide-definitions.c
index 4dbe9d2..fa4d999 100644
--- a/ide-definitions.c
+++ b/ide-definitions.c
@@ -194,7 +194,10 @@ void definitions_send_request_if_needed(Ted *ted) {
void definitions_selector_open(Ted *ted) {
Definitions *defs = &ted->definitions;
definitions_clear_entries(defs);
- LSP *lsp = buffer_lsp(ted->prev_active_buffer);
+ LSP *lsp = ted->prev_active_buffer
+ ? buffer_lsp(ted->prev_active_buffer)
+ : ted_active_lsp(ted);
+
if (lsp) {
definitions_send_request_if_needed(ted);
} else {
@@ -231,12 +234,17 @@ void definitions_selector_update(Ted *ted) {
arr_foreach_ptr(defs->selector_all_definitions, SymbolInfo, info) {
if (strcmp(info->name, chosen) == 0) {
if (info->from_lsp) {
+ // NOTE: we need to get this before calling menu_close,
+ // since that clears selector_all_definitions
+ LSPDocumentPosition position = info->position;
+
menu_close(ted);
- ted_go_to_lsp_document_position(ted, NULL, info->position);
+ ted_go_to_lsp_document_position(ted, NULL, position);
} else {
menu_close(ted);
tag_goto(ted, chosen);
}
+ break;
}
}
diff --git a/lsp.c b/lsp.c
index c8de1a7..60dd4d1 100644
--- a/lsp.c
+++ b/lsp.c
@@ -563,3 +563,15 @@ LSPDocumentPosition lsp_location_end_position(LSPLocation location) {
};
}
+bool lsp_covers_path(LSP *lsp, const char *path) {
+ bool ret = false;
+ SDL_LockMutex(lsp->workspace_folders_mutex);
+ arr_foreach_ptr(lsp->workspace_folders, LSPDocumentID, folder) {
+ if (str_has_path_prefix(path, lsp_document_path(lsp, *folder))) {
+ ret = true;
+ break;
+ }
+ }
+ SDL_UnlockMutex(lsp->workspace_folders_mutex);
+ return ret;
+}
diff --git a/lsp.h b/lsp.h
index b80fbb2..90f70d7 100644
--- a/lsp.h
+++ b/lsp.h
@@ -440,6 +440,8 @@ LSP *lsp_create(const char *root_dir, Language language, const char *analyzer_co
bool lsp_try_add_root_dir(LSP *lsp, const char *new_root_dir);
// report that this document has changed
void lsp_document_changed(LSP *lsp, const char *document, LSPDocumentChangeEvent change);
+// is this path in the LSP's workspace folders?
+bool lsp_covers_path(LSP *lsp, const char *path);
bool lsp_next_message(LSP *lsp, LSPMessage *message);
bool lsp_position_eq(LSPPosition a, LSPPosition b);
bool lsp_document_position_eq(LSPDocumentPosition a, LSPDocumentPosition b);
diff --git a/main.c b/main.c
index f010f91..18379f5 100644
--- a/main.c
+++ b/main.c
@@ -3,13 +3,9 @@
- show location in definitions menu
- handle multiple symbols with same name
- cancelling requests e.g. in ide-definitions.c
-- sort symbols by score (clangd extension?)
- more LSP stuff:
- - go to definition using LSP
- find usages
- refactoring?
-- ted_active_lsp should return something even when buffer isn't open
-- some way of opening + closing all C files in directory for clangd workspace/symbols to work
- test full unicode position handling
- check if there are any other non-optional/nice-to-have-support-for server-to-client requests
- better non-error window/showMessage(Request)
@@ -28,6 +24,8 @@
--- LSP MERGE ---
- improve structure of ted source code to make LSP completions better
(make every c file a valid translation unit)
+ - some way of opening + closing all C files in directory for clangd workspace/symbols to work?
+ is this still necessary?
- CSS highlighting
- styles ([color] sections)
- more documentation generally (development.md or something?)
diff --git a/ted.c b/ted.c
index e98348d..7e14d0a 100644
--- a/ted.c
+++ b/ted.c
@@ -144,8 +144,16 @@ LSP *ted_get_lsp(Ted *ted, const char *path, Language language) {
}
LSP *ted_active_lsp(Ted *ted) {
- if (!ted->active_buffer)
+ if (!ted->active_buffer) {
+ char *root = ted_get_root_dir(ted);
+ for (int i = 0; ted->lsps[i]; ++i) {
+ LSP *lsp = ted->lsps[i];
+ if (lsp_covers_path(lsp, root))
+ return lsp;
+ }
+ free(root);
return NULL;
+ }
return buffer_lsp(ted->active_buffer);
}