Skip to content

dmmulroy/tiny-inline-diagnostic.nvim

 
 

Repository files navigation

🩺 tiny-inline-diagnostic.nvim

CI Neovim Stars

A Neovim plugin for displaying inline diagnostic messages with customizable styles and icons.

Table of Contents

Requirements

  • Neovim >= 0.10

Installation

Lazy.nvim

{
    "rachartier/tiny-inline-diagnostic.nvim",
    event = "VeryLazy",
    priority = 1000,
    config = function()
        require("tiny-inline-diagnostic").setup()
        vim.diagnostic.config({ virtual_text = false }) -- Disable Neovim's default virtual text diagnostics
    end,
}

LazyVim

{
  {
      "rachartier/tiny-inline-diagnostic.nvim",
      event = "VeryLazy",
      priority = 1000,
      opts = {},
  },
  {
    "neovim/nvim-lspconfig",
    opts = { diagnostics = { virtual_text = false } },
  },
}

Important

This disables Neovim's built-in virtual text diagnostics to prevent conflicts and duplicate displays. The plugin provides its own inline diagnostic display.

Examples

Multiline Diagnostics

tiny_inline_1

Configuration
require("tiny-inline-diagnostic").setup({
    options = {
        multilines = {
            enabled = true,
        },
    },
})

Overflow Handling (by default)

tiny_inline_2-ezgif com-speed

With Sources

tiny_inline_4
Configuration
require("tiny-inline-diagnostic").setup({
    options = {
        show_source = {
            enabled = true,
        },
    },
})

Diagnotics count

tiny_inline_3
Configuration
require("tiny-inline-diagnostic").setup({
    options = {
        add_messages = {
            display_count = true,
        },
        multilines = {
            enabled = true,
        },
    },
})

Related Diagnostics (by default)

tiny_inline_5

Configuration

require("tiny-inline-diagnostic").setup({
    -- Choose a preset style for diagnostic appearance
    -- Available: "modern", "classic", "minimal", "powerline", "ghost", "simple", "nonerdfont", "amongus"
    preset = "modern",

    -- Make diagnostic background transparent
    transparent_bg = false,

    -- Make cursorline background transparent for diagnostics
    transparent_cursorline = true,

    -- Customize highlight groups for colors
    -- Use Neovim highlight group names or hex colors like "#RRGGBB"
    hi = {
        error = "DiagnosticError",     -- Highlight for error diagnostics
        warn = "DiagnosticWarn",       -- Highlight for warning diagnostics
        info = "DiagnosticInfo",       -- Highlight for info diagnostics
        hint = "DiagnosticHint",       -- Highlight for hint diagnostics
        arrow = "NonText",             -- Highlight for the arrow pointing to diagnostic
        background = "CursorLine",     -- Background highlight for diagnostics
        mixing_color = "Normal",       -- Color to blend background with (or "None")
    },

    -- List of filetypes to disable the plugin for
    disabled_ft = {},

    options = {
        -- Display the source of diagnostics (e.g., "lua_ls", "pyright")
        show_source = {
            enabled = false,           -- Enable showing source names
            if_many = false,           -- Only show source if multiple sources exist for the same diagnostic
        },

        -- Use icons from vim.diagnostic.config instead of preset icons
        use_icons_from_diagnostic = false,

        -- Color the arrow to match the severity of the first diagnostic
        set_arrow_to_diag_color = false,


        -- Throttle update frequency in milliseconds to improve performance
        -- Higher values reduce CPU usage but may feel less responsive
        -- Set to 0 for immediate updates (may cause lag on slow systems)
        throttle = 20,

        -- Minimum number of characters before wrapping long messages
        softwrap = 30,

        -- Control how diagnostic messages are displayed
        -- NOTE: When using display_count = true, you need to enable multiline diagnostics with multilines.enabled = true
        --       If you want them to always be displayed, you can also set multilines.always_show = true.
        add_messages = {
            messages = true,           -- Show full diagnostic messages
            display_count = false,     -- Show diagnostic count instead of messages when cursor not on line
            use_max_severity = false,  -- When counting, only show the most severe diagnostic
            show_multiple_glyphs = true, -- Show multiple icons for multiple diagnostics of same severity
        },

        -- Settings for multiline diagnostics
        multilines = {
            enabled = false,           -- Enable support for multiline diagnostic messages
            always_show = false,       -- Always show messages on all lines of multiline diagnostics
            trim_whitespaces = false,  -- Remove leading/trailing whitespace from each line
            tabstop = 4,               -- Number of spaces per tab when expanding tabs
            severity = nil,            -- Filter multiline diagnostics by severity (e.g., { vim.diagnostic.severity.ERROR })
          },

        -- Show all diagnostics on the current cursor line, not just those under the cursor
        show_all_diags_on_cursorline = false,

        -- Only show diagnostics when the cursor is directly over them, no fallback to line diagnostics
        show_diags_only_under_cursor = false,

        -- Display related diagnostics from LSP relatedInformation
        show_related = {
            enabled = true,           -- Enable displaying related diagnostics
            max_count = 3,             -- Maximum number of related diagnostics to show per diagnostic
        },

        -- Enable diagnostics display in insert mode
        -- May cause visual artifacts; consider setting throttle to 0 if enabled
        enable_on_insert = false,

        -- Enable diagnostics display in select mode (e.g., during auto-completion)
        enable_on_select = false,

        -- Handle messages that exceed the window width
        overflow = {
            mode = "wrap",             -- "wrap": split into lines, "none": no truncation, "oneline": keep single line
            padding = 0,               -- Extra characters to trigger wrapping earlier
        },

        -- Break long messages into separate lines
        break_line = {
            enabled = false,           -- Enable automatic line breaking
            after = 30,                -- Number of characters before inserting a line break
        },

        -- Custom function to format diagnostic messages
        -- Receives diagnostic object, returns formatted string
        -- Example: function(diag) return diag.message .. " [" .. diag.source .. "]" end
        format = nil,

        -- Virtual text display priority
        -- Higher values appear above other plugins (e.g., GitBlame)
        virt_texts = {
            priority = 2048,
        },

        -- Filter diagnostics by severity levels
        -- Remove severities you don't want to display
        severity = {
            vim.diagnostic.severity.ERROR,
            vim.diagnostic.severity.WARN,
            vim.diagnostic.severity.INFO,
            vim.diagnostic.severity.HINT,
        },

        -- Events that trigger attaching diagnostics to buffers
        -- Default is {"LspAttach"}; change only if plugin doesn't work with your LSP setup
        overwrite_events = nil,

        -- Automatically disable diagnostics when opening diagnostic float windows
        override_open_float = false,
    },
})

Custom Styling

Override preset signs and blending:

require("tiny-inline-diagnostic").setup({
    signs = {
        left = "",
        right = "",
        diag = "",
        arrow = "    ",
        up_arrow = "    ",
        vertical = "",
        vertical_end = "",
    },
    blend = {
        factor = 0.22,
    },
})

Note

Providing signs or blend tables will completely replace the preset defaults. If you want to use a preset's styling, only set the preset option and do not include signs or blend in your configuration. Mixing presets with custom signs/blend is not supported.

Presets

modern

modern

classic

classic

minimal

minimal

powerline

powerline

simple

simple

nonerdfont

nonerdfont

ghost

ghost

amongus

amongus

API

local diag = require("tiny-inline-diagnostic")

-- Change settings dynamically
diag.change(blend_opts, highlight_opts)

-- Get diagnostic under cursor
local diag_under_cursor = diag.get_diagnostic_under_cursor()

-- Control visibility
diag.enable()
diag.disable()
diag.toggle()

-- Filter severities
diag.change_severities({ vim.diagnostic.severity.ERROR, vim.diagnostic.severity.WARN })

Commands

The plugin provides a user command for controlling diagnostic display:

:TinyInlineDiag enable   " Enable inline diagnostics
:TinyInlineDiag disable  " Disable inline diagnostics
:TinyInlineDiag toggle   " Toggle inline diagnostics on/off

You can map these to keybindings for quick access:

vim.keymap.set("n", "<leader>de", "<cmd>TinyInlineDiag enable<cr>", { desc = "Enable diagnostics" })
vim.keymap.set("n", "<leader>dd", "<cmd>TinyInlineDiag disable<cr>", { desc = "Disable diagnostics" })
vim.keymap.set("n", "<leader>dt", "<cmd>TinyInlineDiag toggle<cr>", { desc = "Toggle diagnostics" })

Auto-Disable on Float

To automatically hide inline diagnostics when opening Neovim's diagnostic float windows, override the function to disable diagnostics before opening the float and re-enable them after closing.

vim.diagnostic.open_float = require("tiny-inline-diagnostic.override").open_float

This wrapper function temporarily disables the plugin when a diagnostic float is opened, preventing overlap or visual interference, and restores the diagnostics once the float is closed. It's a lightweight override that doesn't modify the original open_float behavior beyond adding the disable/enable logic.

Integrations

sidekick.nvim

The plugin integrates with sidekick.nvim to automatically disable diagnostics when the sidekick NES is shown and re-enable them when hidden. This prevents visual clutter...

local disabled = false
return {
  {
    "folke/sidekick.nvim",
    opts = { nes = { enabled = true } },
    config = function(_, opts)
      require("sidekick").setup(opts)
      vim.api.nvim_create_autocmd("User", {
        pattern = "SidekickNesHide",
        callback = function()
          if disabled then
            disabled = false
            require("tiny-inline-diagnostic").enable()
          end
        end,
      })
      vim.api.nvim_create_autocmd("User", {
        pattern = "SidekickNesShow",
        callback = function()
          disabled = true
          require("tiny-inline-diagnostic").disable()
        end,
      })
    end,
  },
}

This setup listens for SidekickNesShow and SidekickNesHide events to toggle the diagnostics accordingly.

Comparison with Neovim's Built-in virtual_lines

As of Neovim 0.11, the diagnostic system supports a virtual_lines option (see neovim/neovim#31959). This built-in feature renders diagnostics as virtual lines below the affected code. However, there differences :

Built-in virtual_lines: Inserts virtual lines into the buffer, which shifts all subsequent text down. This can be distracting during navigation, as the visible text "jumps" whenever diagnostics appear or disappear.

tiny-inline-diagnostic.nvim: Renders diagnostics as inline virtual text that overlays the code without moving any lines. This approach eliminates visual disruption, maintaining a good editing experience. Additionally, this plugin is highly configurable with multiple presets, extensive display options (overflow handling, multiline support, diagnostic counts, related information), custom formatting, and fine control over when and how diagnostics appear.

For users who prefer diagnostics to remain unobtrusive and non-intrusive while having extensive customization options, tiny-inline-diagnostic.nvim provides a cleaner, more flexible alternative.

Troubleshooting

  • Colors wrong: Adjust hi table or mixing_color
  • Default diagnostics show: Add vim.diagnostic.config({ virtual_text = false })
  • Overridden by plugins: Increase virt_texts.priority
  • No diagnostics: Check LSP config and disabled_ft

About

A Neovim plugin for displaying inline diagnostic messages with customizable styles and icons.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 99.6%
  • Shell 0.4%