diff options
author | pommicket <pommicket@gmail.com> | 2022-12-31 12:31:33 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-31 12:31:33 -0500 |
commit | 2a9f03edf21f8d6d0392a74eb0a6b2507c261a55 (patch) | |
tree | 115f07dc855100b088b4507f072f97ac71753cf1 /lsp-parse.c | |
parent | c1c684c2346042022ba1b4fa86ca0983ad2f32a1 (diff) |
ted_get_buffer_with_file, sort usages
Diffstat (limited to 'lsp-parse.c')
-rw-r--r-- | lsp-parse.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lsp-parse.c b/lsp-parse.c index 719b8c6..cf590d3 100644 --- a/lsp-parse.c +++ b/lsp-parse.c @@ -798,6 +798,20 @@ static bool parse_highlight(LSP *lsp, const JSON *json, LSPResponse *response) { return true; } +static int references_location_cmp(void *context, const void *av, const void *bv) { + LSP *lsp = context; + const LSPLocation *a = av, *b = bv; + const char *a_path = lsp_document_path(lsp, a->document); + const char *b_path = lsp_document_path(lsp, b->document); + int cmp = strcmp(a_path, b_path); + if (cmp) return cmp; + u32 a_line = a->range.start.line; + u32 b_line = b->range.start.line; + if (a_line < b_line) return -1; + if (a_line > b_line) return +1; + return 0; +} + static bool parse_references(LSP *lsp, const JSON *json, LSPResponse *response) { LSPResponseReferences *refs = &response->data.references; JSONArray result = json_force_array(json_get(json, "result")); @@ -807,6 +821,7 @@ static bool parse_references(LSP *lsp, const JSON *json, LSPResponse *response) if (!parse_location(lsp, json, location_in, location_out)) return false; } + qsort_with_context(refs->locations, arr_len(refs->locations), sizeof *refs->locations, references_location_cmp, lsp); return true; } |