local original_diagnostic_set = vim.diagnostic.set local disabled_diagnostics_patterns = { -- { 'mypy', 'Library stubs not installed' }, -- { 'mypy', 'Cannot find implementation or library stub' }, -- { 'mypy', 'Skipping analyzing' } } local function is_diagnostic_disabled(diagnostic, disabled_diagnostic_patterns) return string.find(diagnostic.source, disabled_diagnostic_patterns[1]) and string.find(diagnostic.message, disabled_diagnostic_patterns[2]) end local function is_diagnostic_enabled(diagnostic, disabled_diagnostic_patterns) local found_diagnostic = true for _, disabled_diagnostic_patterns in pairs(disabled_diagnostics_patterns) do if is_diagnostic_disabled(diagnostic, disabled_diagnostic_patterns) then found_diagnostic = false end end return found_diagnostic end vim.diagnostic.set = function(namespace, bufnr, diagnostics, opts) local filtered_diagnostics = {} for _, diagnostic in pairs(diagnostics) do if is_diagnostic_enabled(diagnostic, disabled_diagnostics_patterns) then table.insert(filtered_diagnostics, diagnostic) end end original_diagnostic_set(namespace, bufnr, filtered_diagnostics, opts) end vim.diagnostic.config{ underline = false, signs = true, severity_sort = true, update_in_insert = false, float = { source = 'always', }, virtual_text = { prefix = '▒ ', spacing = 8, }, }