Skip to content

feature: LSP workspace diagnostics (native pull) #682

Description

@disrupted

Did you check the docs?

  • I have read all the trouble.nvim docs

Is your feature request related to a problem? Please describe.

  1. Neovim added native support for workspace diagnostics feat(lsp): workspace diagnostic support neovim/neovim#34262
  2. but Trouble never calls vim.lsp.buf.workspace_diagnostics()
  3. Without that, pull-based servers never deliver workspace results
  4. DiagnosticChanged does fire correctly for unloaded buffers once the pull is triggered

Describe the solution you'd like

add support for both push-based (already exists) and pull-based LSP diagnostics (natively supported by Neovim now) in :Trouble workspace_diagnostics

Describe alternatives you've considered

Today it is only possible to use pull-based workspace diagnostics like this in Neovim:

vim.lsp.buf.workspace_diagnostics()
vim.diagnostic.setqflist({ open = true })

as a workaround I added this custom Trouble source to my config

lua/trouble/sources/diagnostics_pull.lua

---@type trouble.Source
local M = {}

local function diagnostics()
    return require 'trouble.sources.diagnostics'
end

M.highlights = {
    Message = 'TroubleText',
    ItemSource = 'Comment',
    Code = 'Comment',
}

function M.setup()
    diagnostics().setup()
end

---@param cb trouble.Source.Callback
---@param ctx trouble.Source.ctx
function M.get(cb, ctx)
    -- Always trigger a pull so results stay fresh.
    -- DiagnosticChanged will fire and trigger auto_refresh when results arrive.
    vim.lsp.buf.workspace_diagnostics()
    diagnostics().get(cb, ctx)
end

return M

Trouble config

opts = {
  modes = {
    workspace_diagnostics = {
      mode = 'diagnostics',
      source = 'diagnostics_pull',
      title = 'Workspace Diagnostics',
      auto_refresh = true,
      auto_close = false,
    }
  }
}

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions