folke / trouble.nvim

🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Apache License 2.0
5.15k stars 173 forks source link

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

Closed xfzv closed 3 months ago

xfzv commented 6 months ago

Did you check docs and existing issues?

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

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
  },
}
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

gpanders commented 6 months ago

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.

suliatis commented 3 months ago

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.

xfzv commented 3 months ago

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
folke commented 3 months ago

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

fgr1986 commented 1 month ago

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

folke commented 1 month ago

Trouble now always uses the configured Neovim diagnostic signs.

fgr1986 commented 1 month ago

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

folke commented 1 month ago

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

fgr1986 commented 1 month ago

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

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

folke commented 1 month ago

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

fgr1986 commented 1 month ago

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
folke commented 1 month ago

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