Skip to content

Commit

Permalink
Allow disabling diagnostic messages only for some files
Browse files Browse the repository at this point in the history
  • Loading branch information
techee committed May 20, 2024
1 parent eb5a749 commit 2a9118b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lsp/data/lsp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion lsp/src/lsp-diagnostics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
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 @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions lsp/src/lsp-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2a9118b

Please sign in to comment.