Skip to content

Latest commit

History

History
111 lines (95 loc) 路 2.24 KB

examples.md

File metadata and controls

111 lines (95 loc) 路 2.24 KB

Examples

Window Options

Preview in small float top right

image

{
  modes = {
    preview_float = {
      mode = "diagnostics",
      preview = {
        type = "float",
        relative = "editor",
        border = "rounded",
        title = "Preview",
        title_pos = "center",
        position = { 0, -2 },
        size = { width = 0.3, height = 0.3 },
        zindex = 200,
      },
    },
  },
}

Preview in a split to the right of the trouble list

image

{
  modes = {
    test = {
      mode = "diagnostics",
      preview = {
        type = "split",
        relative = "win",
        position = "right",
        size = 0.3,
      },
    },
  },
}

Filtering

Diagnostics for the current buffer only

{
  modes = {
    diagnostics_buffer = {
      mode = "diagnostics", -- inherit from diagnostics mode
      filter = { buf = 0 }, -- filter diagnostics to the current buffer
    },
  }
}

Diagnostics for the current buffer and errors from the current project

{
  modes = {
    mydiags = {
      mode = "diagnostics", -- inherit from diagnostics mode
      filter = {
        any = {
          buf = 0, -- current buffer
          {
            severity = vim.diagnostic.severity.ERROR, -- errors only
            -- limit to files in the current project
            function(item)
              return item.filename:find(vim.loop.cwd(), 1, true)
            end,
          },
        },
      },
    }
}

Diagnostics Cascade

The following example shows how to create a new mode that shows only the most severe diagnostics.

Once those are resolved, less severe diagnostics will be shown.

{
  modes = {
    cascade = {
      mode = "diagnostics", -- inherit from diagnostics mode
      filter = function(items)
        local severity = vim.diagnostic.severity.HINT
        for _, item in ipairs(items) do
          severity = math.min(severity, item.severity)
        end
        return vim.tbl_filter(function(item)
          return item.severity == severity
        end, items)
      end,
    },
  },
}