trouble.nvim icon indicating copy to clipboard operation
trouble.nvim copied to clipboard

bug: `use_diagnostic_signs = true` no longer works due to a recent Neovim change (0.10+)

Open xfzv opened this issue 1 year ago • 1 comments

Did you check docs and existing issues?

  • [X] I have read all the trouble.nvim docs
  • [X] I have searched the existing issues of trouble.nvim
  • [X] I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.10.0-dev-1856+gf4f7e2946-dirty

Operating system/version

Gentoo Linux

Describe the bug

Due to a recent change in Neovim (https://github.com/neovim/neovim/pull/26193 I believe), diagnostics signs are now configured differently.

As a result, trouble displays "E" ; "W" ; "H" ; "I" letters instead of respective configured signs, despite using use_diagnostic_signs = true.

Steps To Reproduce

  • trouble config:
return {
  "folke/trouble.nvim",
  cmd = { "Trouble", "TroubleToggle" },
  dependencies = "nvim-tree/nvim-web-devicons",
  opts = {
    use_diagnostic_signs = true, -- Use the signs already defined in LSP
  },
}
  • neovim/nvim-lspconfig config:
return {
  "neovim/nvim-lspconfig",
  event = { "BufReadPre", "BufNewFile" },
  config = function()
    vim.diagnostic.config({
      signs = {
        text = {
          [vim.diagnostic.severity.ERROR] = " ",
          [vim.diagnostic.severity.WARN] = " ",
          [vim.diagnostic.severity.INFO] = " ",
          [vim.diagnostic.severity.HINT] = " ",
        },
      },
    })
  end,
}
  1. Using Neovim nightly, trigger a diagnostic in any file
  2. The diagnostic sign is correctly displayed in the SignColumn
  3. Open trouble with :Trouble
  4. The default letter is displayed in trouble instead of the configured sign: image

Expected Behavior

trouble displays signs instead of letters

Repro

No response

xfzv avatar Dec 16 '23 17:12 xfzv

Note that with https://github.com/neovim/neovim/pull/26618, https://github.com/neovim/neovim/pull/26193 is no longer a breaking change. Plugins should still migrate to the new configuration format, but there is no immediate need to do so.

gpanders avatar Dec 19 '23 15:12 gpanders

I have a neovim config only using the new way to define diagnostic signs, so I decided to fix this by myself. You can see my pr above. Feel free to checkout and give your feedback.

suliatis avatar Mar 24 '24 14:03 suliatis

I have a neovim config only using the new way to define diagnostic signs, so I decided to fix this by myself. You can see my pr above. Feel free to checkout and give your feedback.

Thanks for the PR. I've just tried it, works fine here:

image

% nvim --version
NVIM v0.10.0-dev-2678+g3d9c028a4-dirty

xfzv avatar Mar 24 '24 16:03 xfzv

Development on the main branch is EOL.

Trouble has been rewritten and will be merged in main soon.

This issue/feature either no longer exists or has been implemented on dev.

For more info, see https://github.com/folke/trouble.nvim/tree/dev

folke avatar Mar 29 '24 08:03 folke

Dear @folke is it possible that it is not yet enabled on dev branch? (I still see the E/W letters instead of icons).

Thanks

fgr1986 avatar May 16 '24 13:05 fgr1986

Trouble now always uses the configured Neovim diagnostic signs.

folke avatar May 16 '24 13:05 folke

I configured neovim diagnostics, but somehow they are not picked up (just moved to dev today) image

fgr1986 avatar May 16 '24 13:05 fgr1986

Did you use vim.diagnostic.config? And not sign_define? sign_define is deprecated

folke avatar May 16 '24 14:05 folke

No, could find that in the dev docs. Could you point me there?

In the lsp handlers I have vim.diagnostic.config(lsp.diagnostic)

fgr1986 avatar May 16 '24 15:05 fgr1986

Can you show me the exact table you pass to diagnostics config?

folke avatar May 16 '24 19:05 folke

Interestingly, everything works on NVIM v0.9.5 Build type: Release LuaJIT 2.1.1713773202,

but it fails on NVIM v0.10.0-dev Build type: RelWithDebInfo, LuaJIT 2.1.0-beta3.

The table you asked for:

local M = {}

function M.setup()
  -- LSP handlers configuration
  local lsp = {
    float = {
      focusable = true,
      style = "minimal",
      border = "rounded",
    },
    diagnostic = {
      -- virtual_text = true,
      virtual_text = { spacing = 4, prefix = "●" },
      underline = true,
      update_in_insert = false,
      severity_sort = true,
      float = {
        focusable = true,
        style = "minimal",
        border = "rounded",
      },
    },
  }

  -- Diagnostic signs
  local diagnostic_signs = {
    {
      name = "DiagnosticSignError",
      text = ""
    },
    {
      name = "DiagnosticSignWarn",
      -- text = ""
      text = ""
    },
    {
      name = "DiagnosticSignHint",
      text = ""
    },
    {
      name = "DiagnosticSignInfo",
      text = ""
    },
  }
  for _, sign in ipairs(diagnostic_signs) do
    vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name })
  end

  -- Diagnostic configuration
  vim.diagnostic.config(lsp.diagnostic)

  -- Hover configuration
  vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, lsp.float)

  -- Signature help configuration
  vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, lsp.float)
end

return M

fgr1986 avatar May 16 '24 21:05 fgr1986

like I said, on 0.10, you need to pass signs as an option to vim.diagnostic.config. Please check the docs.

So no sign_define

folke avatar May 16 '24 21:05 folke