diff options
-rw-r--r-- | ide-definitions.c | 9 | ||||
-rw-r--r-- | lsp-parse.c | 7 | ||||
-rw-r--r-- | lsp.c | 2 | ||||
-rw-r--r-- | lsp.h | 3 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | test/lsp/multidef.cpp | 45 |
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; } @@ -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; @@ -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 { @@ -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) { + } } |