summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-03 23:50:50 -0500
committerpommicket <pommicket@gmail.com>2023-01-03 23:50:50 -0500
commit3756a3e47221c3b0133724a482341a9010076a9e (patch)
tree7ad68fd0b76bd0e132fd86cd5044c3e08d581d22
parent4e73c6a204383667aad6ce3905e16aee2a172fb6 (diff)
read workspace/symbols containerName
-rw-r--r--ide-definitions.c9
-rw-r--r--lsp-parse.c7
-rw-r--r--lsp.c2
-rw-r--r--lsp.h3
-rw-r--r--main.c1
-rw-r--r--test/lsp/multidef.cpp45
6 files changed, 52 insertions, 15 deletions
diff --git a/ide-definitions.c b/ide-definitions.c
index 67ac51d..1518515 100644
--- a/ide-definitions.c
+++ b/ide-definitions.c
@@ -206,8 +206,13 @@ void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *res
def->color = colors[color_for_symbol_kind(kind)];
def->from_lsp = true;
def->position = lsp_location_start_position(symbol->location);
- def->detail = a_sprintf("%s:%" PRIu32,
- path_filename(lsp_document_path(lsp, def->position.document)),
+ const char *container_name = lsp_response_string(response, symbol->container);
+ const char *filename = path_filename(lsp_document_path(lsp, def->position.document));
+ bool has_container = *container_name != 0;
+ def->detail = a_sprintf("%s%s%s:%" PRIu32,
+ container_name,
+ has_container ? ", " : "",
+ filename,
def->position.pos.line + 1);
}
diff --git a/lsp-parse.c b/lsp-parse.c
index 4c3e95f..c6c15ff 100644
--- a/lsp-parse.c
+++ b/lsp-parse.c
@@ -32,6 +32,9 @@ static WarnUnusedResult bool lsp_expect_number(LSP *lsp, JSONValue value, const
static LSPString lsp_response_add_json_string(LSPResponse *response, const JSON *json, JSONString string) {
+ if (string.len == 0) {
+ return (LSPString){0};
+ }
u32 offset = arr_len(response->string_data);
arr_set_len(response->string_data, offset + string.len + 1);
json_string_get(json, string, response->string_data + offset, string.len + 1);
@@ -608,6 +611,10 @@ static bool parse_symbol_information(LSP *lsp, const JSON *json, JSONValue value
if (!parse_location(lsp, json, location, &info->location))
return false;
+ // get container name
+ JSONString container = json_object_get_string(json, object, "containerName");
+ info->container = lsp_response_add_json_string(response, json, container);
+
return true;
}
diff --git a/lsp.c b/lsp.c
index 583c822..0b3b44b 100644
--- a/lsp.c
+++ b/lsp.c
@@ -439,6 +439,8 @@ const char *lsp_document_path(LSP *lsp, LSPDocumentID document) {
assert(0);
return "";
}
+ // it's okay to keep a pointer to this around without the mutex locked
+ // we'll never change the path of a document ID.
const char *path = lsp->document_data[document].path;
SDL_UnlockMutex(lsp->document_mutex);
return path;
diff --git a/lsp.h b/lsp.h
index f65004f..e3f3bcf 100644
--- a/lsp.h
+++ b/lsp.h
@@ -392,6 +392,9 @@ typedef struct {
LSPSymbolKind kind;
bool deprecated;
LSPLocation location;
+ // the "symbol containing this symbol"
+ // e.g. multiple classes might have a "foo" method, so this can be used to distinguish them.
+ LSPString container;
} LSPSymbolInformation;
typedef struct {
diff --git a/main.c b/main.c
index 231177f..a3af116 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,6 @@
/*
@TODO:
+- handle mouse clicks in "go to definition..." menu
- ted.h documentation
- document lsp.h and lsp.c.
- debug-lsp option (which logs LSP messages)
diff --git a/test/lsp/multidef.cpp b/test/lsp/multidef.cpp
index 6cd5e1a..b9511d0 100644
--- a/test/lsp/multidef.cpp
+++ b/test/lsp/multidef.cpp
@@ -1,16 +1,35 @@
-
-void f(int x, int y) {
-}
-
-
-void f(int x) {
+class V {
+ void f(int x, int y) {
+ }
+
+
+ void f(int x) {
+ }
+
+ void f(const char *s) {
+ }
+
+
+ void g() {
+ }
+ void g(int y) {
+ }
}
-void f(const char *s) {
-}
-
-
-void g() {
-}
-void g(int y) {
+class W {
+ void f(int x, int y) {
+ }
+
+
+ void f(int x) {
+ }
+
+ void f(const char *s) {
+ }
+
+
+ void g() {
+ }
+ void g(int y) {
+ }
}