From 2a9118b60c64283701a641764284b32915f1fd40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Mon, 20 May 2024 20:24:28 +0200 Subject: [PATCH] Allow disabling diagnostic messages only for some files --- lsp/data/lsp.conf | 3 +++ lsp/src/lsp-diagnostics.c | 27 ++++++++++++++++++++++++++- lsp/src/lsp-server.c | 2 ++ lsp/src/lsp-server.h | 1 + 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lsp/data/lsp.conf b/lsp/data/lsp.conf index 3085a7523..3c859a300 100644 --- a/lsp/data/lsp.conf +++ b/lsp/data/lsp.conf @@ -77,6 +77,9 @@ autocomplete_apply_additional_edits=false # Whether LSP should be used to display diagnostic messages. Typically these are # compiler errors or warnings diagnostics_enable=true +# Semicolon-separated glob patterns specifying files for which diagnostic +# messages are not shown. Useful when the server has a problem with some files +#diagnostics_disable_for=*/scintilla/*/*.h # Defines the style of error diagnostics - visual style such as underline, and # its color. # The first number is the "indicator index" of Scintilla - each style should diff --git a/lsp/src/lsp-diagnostics.c b/lsp/src/lsp-diagnostics.c index 9a558a09e..b4eb29eff 100644 --- a/lsp/src/lsp-diagnostics.c +++ b/lsp/src/lsp-diagnostics.c @@ -180,14 +180,36 @@ void lsp_diagnostics_goto_prev_diag(gint pos) } +static gboolean is_diagnostics_disabled_for(GeanyDocument *doc, LspServerConfig *cfg) +{ + gchar **comps = g_strsplit(cfg->diagnostics_disable_for, ";", -1); + gchar *fname = utils_get_utf8_from_locale(doc->real_path); + gboolean is_disabled = FALSE; + gint i = 0; + + for (i = 0; comps && comps[i] && !is_disabled; i++) + { + // TODO: possibly precompile the glob and store somewhere if performance is a problem + if (g_pattern_match_simple(comps[i], fname)) + is_disabled = TRUE; + } + + g_strfreev(comps); + g_free(fname); + + return is_disabled; +} + + void lsp_diagnostics_show_calltip(gint pos) { GeanyDocument *doc = document_get_current(); + LspServerConfig *cfg = lsp_server_get_config(doc); LspDiag *diag = get_diag(pos, 0); gchar *first = NULL; gchar *second; - if (!doc || !diag) + if (!doc || !diag || !cfg || is_diagnostics_disabled_for(doc, cfg)) return; second = diag->message; @@ -245,6 +267,9 @@ void lsp_diagnostics_redraw(GeanyDocument *doc) if (!doc || !doc->real_path || !cfg) return; + if (is_diagnostics_disabled_for(doc, cfg)) + return; + sci = doc->editor->sci; clear_indicators(sci); diff --git a/lsp/src/lsp-server.c b/lsp/src/lsp-server.c index 238ed8d18..13f098825 100644 --- a/lsp/src/lsp-server.c +++ b/lsp/src/lsp-server.c @@ -56,6 +56,7 @@ static void free_config(LspServerConfig *cfg) g_free(cfg->ref_lang); g_strfreev(cfg->autocomplete_trigger_sequences); g_free(cfg->semantic_tokens_type_style); + g_free(cfg->diagnostics_disable_for); g_free(cfg->diagnostics_error_style); g_free(cfg->diagnostics_warning_style); g_free(cfg->diagnostics_info_style); @@ -668,6 +669,7 @@ static void load_config(GKeyFile *kf, const gchar *section, LspServer *s) get_bool(&s->config.autocomplete_use_label, kf, section, "autocomplete_use_label"); get_bool(&s->config.autocomplete_apply_additional_edits, kf, section, "autocomplete_apply_additional_edits"); get_bool(&s->config.diagnostics_enable, kf, section, "diagnostics_enable"); + get_str(&s->config.diagnostics_disable_for, kf, section, "diagnostics_disable_for"); get_str(&s->config.diagnostics_error_style, kf, section, "diagnostics_error_style"); get_str(&s->config.diagnostics_warning_style, kf, section, "diagnostics_warning_style"); diff --git a/lsp/src/lsp-server.h b/lsp/src/lsp-server.h index 672b61c7c..358d8722b 100644 --- a/lsp/src/lsp-server.h +++ b/lsp/src/lsp-server.h @@ -52,6 +52,7 @@ typedef struct gint autocomplete_window_max_width; gboolean diagnostics_enable; + gchar *diagnostics_disable_for; gchar *diagnostics_error_style; gchar *diagnostics_warning_style; gchar *diagnostics_info_style;