summaryrefslogtreecommitdiffstats
path: root/.config/nvim/lua/diagnostic.lua
blob: 0eb4e91183580ea5e16e99bfb0ac36591e2cef17 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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,
  },
}
remember that computers suck.