diff options
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/lsp.c | 12 | ||||
| -rw-r--r-- | src/main/lsp/actions.c | 4 | ||||
| -rw-r--r-- | src/main/lsp/diagnostics.c | 51 | ||||
| -rw-r--r-- | src/main/lsp/diagnostics.h | 11 |
4 files changed, 41 insertions, 37 deletions
diff --git a/src/main/lsp.c b/src/main/lsp.c index de7f553..a8e806b 100644 --- a/src/main/lsp.c +++ b/src/main/lsp.c @@ -50,7 +50,6 @@ struct lsp_server { enum position_encoding_kind position_encoding; struct lsp_diagnostics *diagnostics; - layer_id diagnostics_layer_id; struct completion_ctx *completion_ctx; }; @@ -193,15 +192,15 @@ request_response_received(struct lsp_server *server, uint64_t id, static void buffer_updated(struct buffer *buffer, void *userdata) { struct lsp_server *server = (struct lsp_server *)userdata; - buffer_clear_text_property_layer(buffer, server->diagnostics_layer_id); - - diagnostic_vec *diagnostics = + struct lsp_buffer_diagnostics *diagnostics = diagnostics_for_buffer(server->diagnostics, buffer); if (diagnostics == NULL) { return; } - VEC_FOR_EACH(diagnostics, struct diagnostic * diag) { + buffer_clear_text_property_layer(buffer, diagnostics->layer); + + VEC_FOR_EACH(&diagnostics->diagnostics, struct diagnostic * diag) { struct text_property prop; prop.type = TextProperty_Colors; uint32_t color = diag_severity_color(diag->severity); @@ -217,7 +216,7 @@ static void buffer_updated(struct buffer *buffer, void *userdata) { diag->region.begin, buffer_previous_char(buffer, diag->region.end)); buffer_add_text_property_to_layer(buffer, reg.begin, reg.end, prop, - server->diagnostics_layer_id); + diagnostics->layer); if (window_buffer(windows_get_active()) == buffer) { struct buffer_view *bv = window_buffer_view(windows_get_active()); @@ -593,7 +592,6 @@ static void create_lsp_client(struct buffer *buffer, void *userdata) { } new->value.diagnostics = diagnostics_create(); - new->value.diagnostics_layer_id = buffer_add_text_property_layer(buffer); // support for this is determined later new->value.completion_ctx = NULL; diff --git a/src/main/lsp/actions.c b/src/main/lsp/actions.c index ea792a1..884cef7 100644 --- a/src/main/lsp/actions.c +++ b/src/main/lsp/actions.c @@ -108,10 +108,10 @@ int32_t code_actions_cmd(struct command_ctx ctx, int argc, const char **argv) { VEC_INIT(¶ms.context.diagnostics, 8); - diagnostic_vec *d = + struct lsp_buffer_diagnostics *d = diagnostics_for_buffer(lsp_server_diagnostics(server), bv->buffer); if (d != NULL) { - VEC_FOR_EACH(d, struct diagnostic * diag) { + VEC_FOR_EACH(&d->diagnostics, struct diagnostic * diag) { if (location_is_between(bv->dot, diag->region.begin, diag->region.end)) { VEC_PUSH(¶ms.context.diagnostics, *diag); } diff --git a/src/main/lsp/diagnostics.c b/src/main/lsp/diagnostics.c index fbab4c0..db71fa3 100644 --- a/src/main/lsp/diagnostics.c +++ b/src/main/lsp/diagnostics.c @@ -11,11 +11,6 @@ #include "main/bindings.h" #include "main/lsp.h" -struct lsp_buffer_diagnostics { - struct buffer *buffer; - diagnostic_vec diagnostics; -}; - #define DIAGNOSTIC_BUFNAME "*lsp-diagnostics*" typedef VEC(struct lsp_buffer_diagnostics) buffer_diagnostics_vec; @@ -40,11 +35,12 @@ static struct s8 diagnostics_modeline(struct buffer_view *view, void *userdata) { struct lsp_diagnostics *diag = (struct lsp_diagnostics *)userdata; - diagnostic_vec *diags = diagnostics_for_buffer(diag, view->buffer); + struct lsp_buffer_diagnostics *diags = + diagnostics_for_buffer(diag, view->buffer); size_t nerrs = 0, nwarn = 0; if (diags != NULL) { - VEC_FOR_EACH(diags, struct diagnostic * d) { + VEC_FOR_EACH(&diags->diagnostics, struct diagnostic * d) { if (d->severity == LspDiagnostic_Error) { ++nerrs; } else if (d->severity == LspDiagnostic_Warning) { @@ -81,11 +77,11 @@ void diagnostics_destroy(struct lsp_diagnostics *d) { free(d); } -diagnostic_vec *diagnostics_for_buffer(struct lsp_diagnostics *d, - struct buffer *buffer) { +struct lsp_buffer_diagnostics *diagnostics_for_buffer(struct lsp_diagnostics *d, + struct buffer *buffer) { VEC_FOR_EACH(&d->buffer_diagnostics, struct lsp_buffer_diagnostics * diag) { if (diag->buffer == buffer) { - return &diag->diagnostics; + return diag; } } @@ -254,26 +250,28 @@ void handle_publish_diagnostics(struct lsp_server *server, if (b != NULL) { struct lsp_diagnostics *ld = lsp_server_diagnostics(server); - diagnostic_vec *diagnostics = diagnostics_for_buffer(ld, b); + struct lsp_buffer_diagnostics *diagnostics = + diagnostics_for_buffer(ld, b); if (diagnostics == NULL) { VEC_APPEND(&ld->buffer_diagnostics, struct lsp_buffer_diagnostics * new_diag); new_diag->buffer = b; + new_diag->layer = buffer_add_text_property_layer(b); new_diag->diagnostics.nentries = 0; new_diag->diagnostics.capacity = 0; new_diag->diagnostics.temp = NULL; new_diag->diagnostics.entries = NULL; - diagnostics = &new_diag->diagnostics; + diagnostics = new_diag; } - VEC_FOR_EACH(diagnostics, struct diagnostic * diag) { + VEC_FOR_EACH(&diagnostics->diagnostics, struct diagnostic * diag) { diagnostic_free(diag); } - VEC_DESTROY(diagnostics); + VEC_DESTROY(&diagnostics->diagnostics); - *diagnostics = params.diagnostics; - update_diagnostics_buffer(server, buffers, *diagnostics, b); + diagnostics->diagnostics = params.diagnostics; + update_diagnostics_buffer(server, buffers, diagnostics->diagnostics, b); } else { VEC_FOR_EACH(¶ms.diagnostics, struct diagnostic * diag) { diagnostic_free(diag); @@ -307,25 +305,25 @@ int32_t next_diagnostic_cmd(struct command_ctx ctx, int argc, return 0; } - diagnostic_vec *diagnostics = + struct lsp_buffer_diagnostics *diagnostics = diagnostics_for_buffer(lsp_diagnostics_from_server(server), bv->buffer); if (diagnostics == NULL) { return 0; } - if (VEC_EMPTY(diagnostics)) { + if (VEC_EMPTY(&diagnostics->diagnostics)) { minibuffer_echo_timeout(4, "no more diagnostics"); return 0; } - VEC_FOR_EACH(diagnostics, struct diagnostic * diag) { + VEC_FOR_EACH(&diagnostics->diagnostics, struct diagnostic * diag) { if (location_compare(bv->dot, diag->region.begin) < 0) { buffer_view_goto(bv, diag->region.begin); return 0; } } - buffer_view_goto(bv, VEC_FRONT(diagnostics)->region.begin); + buffer_view_goto(bv, VEC_FRONT(&diagnostics->diagnostics)->region.begin); return 0; } @@ -342,26 +340,26 @@ int32_t prev_diagnostic_cmd(struct command_ctx ctx, int argc, return 0; } - diagnostic_vec *diagnostics = + struct lsp_buffer_diagnostics *diagnostics = diagnostics_for_buffer(lsp_diagnostics_from_server(server), bv->buffer); if (diagnostics == NULL) { return 0; } - if (VEC_EMPTY(diagnostics)) { + if (VEC_EMPTY(&diagnostics->diagnostics)) { minibuffer_echo_timeout(4, "no more diagnostics"); return 0; } - VEC_FOR_EACH(diagnostics, struct diagnostic * diag) { + VEC_FOR_EACH(&diagnostics->diagnostics, struct diagnostic * diag) { if (location_compare(bv->dot, diag->region.begin) > 0) { buffer_view_goto(bv, diag->region.begin); return 0; } } - buffer_view_goto(bv, VEC_BACK(diagnostics)->region.begin); + buffer_view_goto(bv, VEC_BACK(&diagnostics->diagnostics)->region.begin); return 0; } @@ -377,9 +375,10 @@ int32_t diagnostics_cmd(struct command_ctx ctx, int argc, const char **argv) { return 0; } - diagnostic_vec *d = + struct lsp_buffer_diagnostics *d = diagnostics_for_buffer(lsp_diagnostics_from_server(server), b); - struct buffer *db = update_diagnostics_buffer(server, ctx.buffers, *d, b); + struct buffer *db = + update_diagnostics_buffer(server, ctx.buffers, d->diagnostics, b); window_set_buffer(ctx.active_window, db); return 0; diff --git a/src/main/lsp/diagnostics.h b/src/main/lsp/diagnostics.h index 4357b8e..a5bb5d9 100644 --- a/src/main/lsp/diagnostics.h +++ b/src/main/lsp/diagnostics.h @@ -2,6 +2,7 @@ #define _DIAGNOSTICS_H #include "dged/command.h" +#include "dged/text.h" #include "main/lsp/types.h" struct lsp_server; @@ -10,11 +11,17 @@ struct lsp_notification; struct lsp_diagnostics; +struct lsp_buffer_diagnostics { + struct buffer *buffer; + layer_id layer; + diagnostic_vec diagnostics; +}; + struct lsp_diagnostics *diagnostics_create(void); void diagnostics_destroy(struct lsp_diagnostics *); -diagnostic_vec *diagnostics_for_buffer(struct lsp_diagnostics *, - struct buffer *); +struct lsp_buffer_diagnostics *diagnostics_for_buffer(struct lsp_diagnostics *, + struct buffer *); void handle_publish_diagnostics(struct lsp_server *, struct buffers *, struct lsp_notification *); |
