Skip to content

Commit

Permalink
Make progress reporting configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
techee committed Jun 22, 2024
1 parent d50c6c6 commit 78a2cd6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
3 changes: 3 additions & 0 deletions lsp/data/lsp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 15 additions & 7 deletions lsp/src/lsp-progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -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);
}
}
4 changes: 0 additions & 4 deletions lsp/src/lsp-progress.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lsp/src/lsp-rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions lsp/src/lsp-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions lsp/src/lsp-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 78a2cd6

Please sign in to comment.