From 78a2cd6b62643d53deb876b1e8bf6a9d60128d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sat, 22 Jun 2024 23:55:26 +0200 Subject: [PATCH] Make progress reporting configurable --- lsp/data/lsp.conf | 3 +++ lsp/src/lsp-progress.c | 22 +++++++++++++++------- lsp/src/lsp-progress.h | 4 ---- lsp/src/lsp-rpc.c | 2 +- lsp/src/lsp-server.c | 2 ++ lsp/src/lsp-server.h | 2 ++ 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lsp/data/lsp.conf b/lsp/data/lsp.conf index f6c27b010..d08a09631 100644 --- a/lsp/data/lsp.conf +++ b/lsp/data/lsp.conf @@ -198,6 +198,9 @@ formatting_options={ "tabSize": 4, "insertSpaces": false } # on every save format_on_save=false +# Allow reporting progress information from LSP servers in the status bar. +progress_enable=true + # This is a dummy language server configuration describing the available # language-specific options diff --git a/lsp/src/lsp-progress.c b/lsp/src/lsp-progress.c index b8366bff9..a5cfebfef 100644 --- a/lsp/src/lsp-progress.c +++ b/lsp/src/lsp-progress.c @@ -45,7 +45,12 @@ static void progress_free(LspProgress *p) void lsp_progress_create(LspServer *server, LspProgressToken token) { - LspProgress *p = g_new0(LspProgress, 1); + LspProgress *p; + + if (!server->config.progress_enable) + return; + + p = g_new0(LspProgress, 1); p->token.token_str = g_strdup(token.token_str); p->token.token_int = token.token_int; @@ -62,7 +67,7 @@ static gboolean token_equal(LspProgressToken t1, LspProgressToken t2) } -void lsp_progress_begin(LspServer *server, LspProgressToken token, const gchar *title, const gchar *message) +static void progress_begin(LspServer *server, LspProgressToken token, const gchar *title, const gchar *message) { GSList *node; @@ -82,7 +87,7 @@ void lsp_progress_begin(LspServer *server, LspProgressToken token, const gchar * } -void lsp_progress_report(LspServer *server, LspProgressToken token, const gchar *message) +static void progress_report(LspServer *server, LspProgressToken token, const gchar *message) { GSList *node; @@ -98,7 +103,7 @@ void lsp_progress_report(LspServer *server, LspProgressToken token, const gchar } -void lsp_progress_end(LspServer *server, LspProgressToken token, const gchar *message) +static void progress_end(LspServer *server, LspProgressToken token, const gchar *message) { GSList *node; @@ -147,6 +152,9 @@ void lsp_progress_process_notification(LspServer *srv, GVariant *params) const gchar *message = NULL; gchar buf[50]; + if (!srv->config.progress_enable) + return; + have_token = JSONRPC_MESSAGE_PARSE(params, "token", JSONRPC_MESSAGE_GET_STRING(&token_str) ); @@ -191,10 +199,10 @@ void lsp_progress_process_notification(LspServer *srv, GVariant *params) { LspProgressToken token = {token_int, (gchar *)token_str}; if (g_strcmp0(kind, "begin") == 0) - lsp_progress_begin(srv, token, title, message); + progress_begin(srv, token, title, message); else if (g_strcmp0(kind, "report") == 0) - lsp_progress_report(srv, token, message); + progress_report(srv, token, message); else if (g_strcmp0(kind, "end") == 0) - lsp_progress_end(srv, token, message); + progress_end(srv, token, message); } } diff --git a/lsp/src/lsp-progress.h b/lsp/src/lsp-progress.h index bb6895f63..534de6a42 100644 --- a/lsp/src/lsp-progress.h +++ b/lsp/src/lsp-progress.h @@ -33,10 +33,6 @@ typedef struct void lsp_progress_create(LspServer *server, LspProgressToken token); -void lsp_progress_begin(LspServer *server, LspProgressToken token, const gchar *title, const gchar *message); -void lsp_progress_report(LspServer *server, LspProgressToken token, const gchar *message); -void lsp_progress_end(LspServer *server, LspProgressToken token, const gchar *message); - void lsp_progress_process_notification(LspServer *srv, GVariant *params); void lsp_progress_free_all(LspServer *server); diff --git a/lsp/src/lsp-rpc.c b/lsp/src/lsp-rpc.c index cc1e3f794..bfdd1d7a0 100644 --- a/lsp/src/lsp-rpc.c +++ b/lsp/src/lsp-rpc.c @@ -111,7 +111,7 @@ static void handle_notification(JsonrpcClient *client, gchar *method, GVariant * { log_message(params); } - else if (g_str_has_prefix(method, "$/")) + else if (g_strcmp0(method, "$/progress") == 0) { lsp_progress_process_notification(srv, params); } diff --git a/lsp/src/lsp-server.c b/lsp/src/lsp-server.c index 210fe54f9..855f87b8b 100644 --- a/lsp/src/lsp-server.c +++ b/lsp/src/lsp-server.c @@ -843,6 +843,8 @@ static void load_config(GKeyFile *kf, const gchar *section, LspServer *s) get_int(&s->config.command_keybinding_num, kf, section, "command_keybinding_num"); s->config.command_keybinding_num = CLAMP(s->config.command_keybinding_num, 1, 1000); + get_bool(&s->config.progress_enable, kf, section, "progress_enable"); + // create for the first time, then just update if (!s->config.command_regexes) { diff --git a/lsp/src/lsp-server.h b/lsp/src/lsp-server.h index 008cfba91..d471339e3 100644 --- a/lsp/src/lsp-server.h +++ b/lsp/src/lsp-server.h @@ -99,6 +99,8 @@ typedef struct LspServerConfig gboolean range_formatting_enable; gboolean format_on_save; + gboolean progress_enable; + gboolean execute_command_enable; gboolean code_action_enable; gchar *command_on_save_regex;