Skip to content

Commit b718904

Browse files
110yautozimu
authored andcommitted
Add feature to filter diagnostics messages by its source
1 parent c17681c commit b718904

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

doc/LanguageClient.txt

+13-6
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,22 @@ Maximum severity to show diagnostic messages.
414414
Default: "Hint"
415415
Valid options: "Error" | "Warning" | "Information" | "Hint"
416416

417-
2.31 g:LanguageClient_echoProjectRoot *g:LanguageClient_echoProjectRoot*
417+
2.31 g:LanguageClient_diagnosticsIgnoreSources *g:LanguageClient_diagnosticsIgnoreSources*
418+
419+
Does not show the diagnostics message which has the source specified by this
420+
options.
421+
422+
Default: "[]"
423+
424+
2.32 g:LanguageClient_echoProjectRoot *g:LanguageClient_echoProjectRoot*
418425

419426
Whether to echo messages in vim of the form: "Project root: /home/user/myproject" when
420427
the root of a project is detected using g:LanguageClient_rootMarkers.
421428

422429
Default: 1 to display the messages
423430
Valid options: 1 | 0
424431

425-
2.32 g:LanguageClient_semanticHighlightMaps *g:LanguageClient_semanticHighlightMaps*
432+
2.33 g:LanguageClient_semanticHighlightMaps *g:LanguageClient_semanticHighlightMaps*
426433

427434
String to list/map map. Defines the mapping of semantic highlighting "scopes" to
428435
highlight groups. This depends on the LSP server supporting the proposed
@@ -523,14 +530,14 @@ Example configuration for eclipse.jdt.ls:
523530
highlight! JavaMemberVariable ctermfg=White cterm=italic guifg=White gui=italic
524531
525532
526-
2.33 g:LanguageClient_applyCompletionAdditionalTextEdits *g:LanguageClient_applyCompletionAdditionalTextEdits*
533+
2.34 g:LanguageClient_applyCompletionAdditionalTextEdits *g:LanguageClient_applyCompletionAdditionalTextEdits*
527534

528535
Indicates whether completionItem additional text edits should be applied.
529536

530537
Default: 1
531538
Valid options: 1 | 0
532539

533-
2.34 g:LanguageClient_preferredMarkupKind *g:LanguageClient_preferredMarkupKind*
540+
2.35 g:LanguageClient_preferredMarkupKind *g:LanguageClient_preferredMarkupKind*
534541

535542
Sets the preferred markup kind. This value is sent to the server and is
536543
normally used to decide whether to send plaintext or markdown in things like
@@ -562,14 +569,14 @@ This setting may have no effect of the server decides not to honour it.
562569
Default: v:null
563570
Valid options: Array<String>
564571

565-
2.35 g:LanguageClient_floatingWindowStyle *g:LanguageClient_floatingWindowStyle*
572+
2.36 g:LanguageClient_floatingWindowStyle *g:LanguageClient_floatingWindowStyle*
566573

567574
Style of opened Neovim floating window.
568575

569576
Default: 'minimal'
570577
Valid options: 'minimal'
571578

572-
2.36 g:LanguageClient_hideVirtualTextsOnInsert *g:LanguageClient_hideVirtualTextsOnInsert*
579+
2.37 g:LanguageClient_hideVirtualTextsOnInsert *g:LanguageClient_hideVirtualTextsOnInsert*
573580

574581
Hides all virtual texts for the current buffer while editing in insert mode.
575582

src/language_server_protocol.rs

+10
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ impl LanguageClient {
160160
let (
161161
diagnostics_signs_max,
162162
diagnostics_max_severity,
163+
diagnostics_ignore_sources,
163164
document_highlight_display,
164165
selection_ui_auto_open,
165166
use_virtual_text,
@@ -172,6 +173,7 @@ impl LanguageClient {
172173
): (
173174
Option<usize>,
174175
String,
176+
Vec<String>,
175177
Value,
176178
u8,
177179
UseVirtualText,
@@ -185,6 +187,7 @@ impl LanguageClient {
185187
[
186188
"get(g:, 'LanguageClient_diagnosticsSignsMax', v:null)",
187189
"get(g:, 'LanguageClient_diagnosticsMaxSeverity', 'Hint')",
190+
"get(g:, 'LanguageClient_diagnosticsIgnoreSources', [])",
188191
"get(g:, 'LanguageClient_documentHighlightDisplay', {})",
189192
"!!s:GetVar('LanguageClient_selectionUI_autoOpen', 1)",
190193
"s:useVirtualText()",
@@ -290,6 +293,7 @@ impl LanguageClient {
290293
)?;
291294
state.diagnostics_signs_max = diagnostics_signs_max;
292295
state.diagnostics_max_severity = diagnostics_max_severity;
296+
state.diagnostics_ignore_sources = diagnostics_ignore_sources;
293297
state.document_highlight_display = serde_json::from_value(
294298
serde_json::to_value(&state.document_highlight_display)?
295299
.combine(&document_highlight_display),
@@ -2313,10 +2317,16 @@ impl LanguageClient {
23132317
let filename = filename.canonicalize();
23142318

23152319
let diagnostics_max_severity = self.get(|state| state.diagnostics_max_severity)?;
2320+
let ignore_sources = self.get(|state| state.diagnostics_ignore_sources.clone())?;
23162321
let mut diagnostics = params
23172322
.diagnostics
23182323
.iter()
23192324
.filter(|&diagnostic| {
2325+
if let Some(source) = &diagnostic.source {
2326+
if ignore_sources.contains(source) {
2327+
return false;
2328+
}
2329+
}
23202330
diagnostic.severity.unwrap_or(DiagnosticSeverity::Hint) <= diagnostics_max_severity
23212331
})
23222332
.map(Clone::clone)

src/types.rs

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ pub struct State {
192192
pub diagnostics_display: HashMap<u64, DiagnosticsDisplay>,
193193
pub diagnostics_signs_max: Option<usize>,
194194
pub diagnostics_max_severity: DiagnosticSeverity,
195+
pub diagnostics_ignore_sources: Vec<String>,
195196
pub document_highlight_display: HashMap<u64, DocumentHighlightDisplay>,
196197
pub window_log_message_level: MessageType,
197198
pub settings_path: Vec<String>,
@@ -272,6 +273,7 @@ impl State {
272273
diagnostics_display: DiagnosticsDisplay::default(),
273274
diagnostics_signs_max: None,
274275
diagnostics_max_severity: DiagnosticSeverity::Hint,
276+
diagnostics_ignore_sources: vec![],
275277
document_highlight_display: DocumentHighlightDisplay::default(),
276278
window_log_message_level: MessageType::Warning,
277279
settings_path: vec![format!(".vim{}settings.json", std::path::MAIN_SEPARATOR)],

0 commit comments

Comments
 (0)