Giter VIP home page Giter VIP logo

trouble.nvim's Introduction

🚦 Trouble

A pretty list for showing diagnostics, references, telescope results, quickfix and location lists to help you solve all the trouble your code is causing.

image

✨ Features

  • Diagnostics
  • LSP references
  • LSP implementations
  • LSP definitions
  • LSP type definitions
  • LSP Document Symbols
  • LSP Incoming/Outgoing calls
  • quickfix list
  • location list
  • Telescope search results
  • fzf-lua results

📰 What's new?

This is a full rewrite of the original trouble.nvim.

The new version is much more flexible and powerful, with a lot of new features and improvements:

  • multiple trouble windows at the same time
  • LSP document symbols
  • LSP incoming/outgoing calls
  • lots of options to configure trouble windows (floats or splits)
  • focus option to focus the trouble window when opened (or not)
  • follow option to follow the item under the cursor
  • pinned option to pin the buffer as the source for the opened trouble window
  • full tree views of anything
  • highly configurable views with custom formatters, filters, and sorters
  • show multiple sections in the same view
  • multi-line messages
  • prettier and configurable indent guides
  • tree view that follows the natural hierarchy of the items (like document symbols, or file structure)
  • expansive API and Trouble command
  • trouble modes to define custom views
  • statusline component (useful with document symbols)

⚡️ Requirements

  • Neovim >= 0.9.2
  • Neovim >= 0.10.0 OR the markdown and markdown_inline nvim-treesitter parsers
  • Properly configured Neovim LSP client
  • nvim-web-devicons is optional to enable file icons
  • a theme with properly configured highlight groups for Neovim Diagnostics
  • a patched font for the default severity and fold icons

📦 Installation

Install the plugin with your preferred package manager:

{
  "folke/trouble.nvim",
  opts = {}, -- for default options, refer to the configuration section for custom setup.
  cmd = "Trouble",
  keys = {
    {
      "<leader>xx",
      "<cmd>Trouble diagnostics toggle<cr>",
      desc = "Diagnostics (Trouble)",
    },
    {
      "<leader>xX",
      "<cmd>Trouble diagnostics toggle filter.buf=0<cr>",
      desc = "Buffer Diagnostics (Trouble)",
    },
    {
      "<leader>cs",
      "<cmd>Trouble symbols toggle focus=false<cr>",
      desc = "Symbols (Trouble)",
    },
    {
      "<leader>cl",
      "<cmd>Trouble lsp toggle focus=false win.position=right<cr>",
      desc = "LSP Definitions / references / ... (Trouble)",
    },
    {
      "<leader>xL",
      "<cmd>Trouble loclist toggle<cr>",
      desc = "Location List (Trouble)",
    },
    {
      "<leader>xQ",
      "<cmd>Trouble qflist toggle<cr>",
      desc = "Quickfix List (Trouble)",
    },
  },
}

⚙️ Configuration

Setup

Trouble is highly configurable. Please refer to the default settings below.

Default Settings
---@class trouble.Mode: trouble.Config,trouble.Section.spec
---@field desc? string
---@field sections? string[]

---@class trouble.Config
---@field mode? string
---@field config? fun(opts:trouble.Config)
---@field formatters? table<string,trouble.Formatter> custom formatters
---@field filters? table<string, trouble.FilterFn> custom filters
---@field sorters? table<string, trouble.SorterFn> custom sorters
local defaults = {
  auto_close = false, -- auto close when there are no items
  auto_open = false, -- auto open when there are items
  auto_preview = true, -- automatically open preview when on an item
  auto_refresh = true, -- auto refresh when open
  auto_jump = false, -- auto jump to the item when there's only one
  focus = false, -- Focus the window when opened
  restore = true, -- restores the last location in the list when opening
  follow = true, -- Follow the current item
  indent_guides = true, -- show indent guides
  max_items = 200, -- limit number of items that can be displayed per section
  multiline = true, -- render multi-line messages
  pinned = false, -- When pinned, the opened trouble window will be bound to the current buffer
  warn_no_results = true, -- show a warning when there are no results
  open_no_results = false, -- open the trouble window when there are no results
  ---@type trouble.Window.opts
  win = {}, -- window options for the results window. Can be a split or a floating window.
  -- Window options for the preview window. Can be a split, floating window,
  -- or `main` to show the preview in the main editor window.
  ---@type trouble.Window.opts
  preview = {
    type = "main",
    -- when a buffer is not yet loaded, the preview window will be created
    -- in a scratch buffer with only syntax highlighting enabled.
    -- Set to false, if you want the preview to always be a real loaded buffer.
    scratch = true,
  },
  -- Throttle/Debounce settings. Should usually not be changed.
  ---@type table<string, number|{ms:number, debounce?:boolean}>
  throttle = {
    refresh = 20, -- fetches new data when needed
    update = 10, -- updates the window
    render = 10, -- renders the window
    follow = 100, -- follows the current item
    preview = { ms = 100, debounce = true }, -- shows the preview for the current item
  },
  -- Key mappings can be set to the name of a builtin action,
  -- or you can define your own custom action.
  ---@type table<string, trouble.Action.spec>
  keys = {
    ["?"] = "help",
    r = "refresh",
    R = "toggle_refresh",
    q = "close",
    o = "jump_close",
    ["<esc>"] = "cancel",
    ["<cr>"] = "jump",
    ["<2-leftmouse>"] = "jump",
    ["<c-s>"] = "jump_split",
    ["<c-v>"] = "jump_vsplit",
    -- go down to next item (accepts count)
    -- j = "next",
    ["}"] = "next",
    ["]]"] = "next",
    -- go up to prev item (accepts count)
    -- k = "prev",
    ["{"] = "prev",
    ["[["] = "prev",
    dd = "delete",
    d = { action = "delete", mode = "v" },
    i = "inspect",
    p = "preview",
    P = "toggle_preview",
    zo = "fold_open",
    zO = "fold_open_recursive",
    zc = "fold_close",
    zC = "fold_close_recursive",
    za = "fold_toggle",
    zA = "fold_toggle_recursive",
    zm = "fold_more",
    zM = "fold_close_all",
    zr = "fold_reduce",
    zR = "fold_open_all",
    zx = "fold_update",
    zX = "fold_update_all",
    zn = "fold_disable",
    zN = "fold_enable",
    zi = "fold_toggle_enable",
    gb = { -- example of a custom action that toggles the active view filter
      action = function(view)
        view:filter({ buf = 0 }, { toggle = true })
      end,
      desc = "Toggle Current Buffer Filter",
    },
    s = { -- example of a custom action that toggles the severity
      action = function(view)
        local f = view:get_filter("severity")
        local severity = ((f and f.filter.severity or 0) + 1) % 5
        view:filter({ severity = severity }, {
          id = "severity",
          template = "{hl:Title}Filter:{hl} {severity}",
          del = severity == 0,
        })
      end,
      desc = "Toggle Severity Filter",
    },
  },
  ---@type table<string, trouble.Mode>
  modes = {
    -- sources define their own modes, which you can use directly,
    -- or override like in the example below
    lsp_references = {
      -- some modes are configurable, see the source code for more details
      params = {
        include_declaration = true,
      },
    },
    -- The LSP base mode for:
    -- * lsp_definitions, lsp_references, lsp_implementations
    -- * lsp_type_definitions, lsp_declarations, lsp_command
    lsp_base = {
      params = {
        -- don't include the current location in the results
        include_current = false,
      },
    },
    -- more advanced example that extends the lsp_document_symbols
    symbols = {
      desc = "document symbols",
      mode = "lsp_document_symbols",
      focus = false,
      win = { position = "right" },
      filter = {
        -- remove Package since luals uses it for control flow structures
        ["not"] = { ft = "lua", kind = "Package" },
        any = {
          -- all symbol kinds for help / markdown files
          ft = { "help", "markdown" },
          -- default set of symbol kinds
          kind = {
            "Class",
            "Constructor",
            "Enum",
            "Field",
            "Function",
            "Interface",
            "Method",
            "Module",
            "Namespace",
            "Package",
            "Property",
            "Struct",
            "Trait",
          },
        },
      },
    },
  },
  -- stylua: ignore
  icons = {
    ---@type trouble.Indent.symbols
    indent = {
      top           = "",
      middle        = "├╴",
      last          = "└╴",
      -- last          = "-╴",
      -- last       = "╰╴", -- rounded
      fold_open     = "",
      fold_closed   = "",
      ws            = "  ",
    },
    folder_closed   = "",
    folder_open     = "",
    kinds = {
      Array         = "",
      Boolean       = "󰨙 ",
      Class         = "",
      Constant      = "󰏿 ",
      Constructor   = "",
      Enum          = "",
      EnumMember    = "",
      Event         = "",
      Field         = "",
      File          = "",
      Function      = "󰊕 ",
      Interface     = "",
      Key           = "",
      Method        = "󰊕 ",
      Module        = "",
      Namespace     = "󰦮 ",
      Null          = "",
      Number        = "󰎠 ",
      Object        = "",
      Operator      = "",
      Package       = "",
      Property      = "",
      String        = "",
      Struct        = "󰆼 ",
      TypeParameter = "",
      Variable      = "󰀫 ",
    },
  },
}

Make sure to check the Examples!

🚀 Usage

Commands

The Trouble command is a wrapper around the Trouble API. It can do anything the regular API can do.

  • Trouble [mode] [action] [options]

Some examples:

  • Toggle diagnostics for the current buffer and stay in the current window:
    • Trouble diagnostics toggle focus=false filter.buf=0
  • Show document symbols on the right of the current window. Keep the document symbols in sync with the buffer you started the command in.
    • Trouble symbols toggle pinned=true results.win.relative=win results.win.position=right
  • You can use lua code in the options for the Trouble command. The examples below all do the same thing.
    • Trouble diagnostics filter.severity=vim.diagnostic.severity.ERROR
    • Trouble diagnostics filter.severity = vim.diagnostic.severity.ERROR
    • Trouble diagnostics filter = { severity=vim.diagnostic.severity.ERROR }
  • Merging of nested options, with or without quoting strings:
    • Trouble diagnostics results.win.type = split result.win.position=right
    • Trouble diagnostics results.win = { type = split, position=right}
    • Trouble diagnostics results.win = { type = "split", position='right'}

Please refer to the API section for more information on the available actions and options.

Modes:

  • diagnostics: diagnostics
  • fzf: FzfLua results previously opened with require('trouble.sources.fzf').open().
  • fzf_files: FzfLua results previously opened with require('trouble.sources.fzf').open().
  • loclist: Location List
  • lsp: LSP definitions, references, implementations, type definitions, and declarations
  • lsp_command: command
  • lsp_declarations: declarations
  • lsp_definitions: definitions
  • lsp_document_symbols: document symbols
  • lsp_implementations: implementations
  • lsp_incoming_calls: Incoming Calls
  • lsp_outgoing_calls: Outgoing Calls
  • lsp_references: references
  • lsp_type_definitions: type definitions
  • qflist: Quickfix List
  • quickfix: Quickfix List
  • symbols: document symbols
  • telescope: Telescope results previously opened with require('trouble.sources.telescope').open().
  • telescope_files: Telescope results previously opened with require('trouble.sources.telescope').open().

Filters

Please refer to the filter docs for more information examples on filters.

API

You can use the following functions in your keybindings:

API
-- Opens trouble with the given mode.
-- If a view is already open with the same mode,
-- it will be focused unless `opts.focus = false`.
-- When a view is already open and `opts.new = true`,
-- a new view will be created.
---@param opts? trouble.Mode | { new?: boolean, refresh?: boolean } | string
---@return trouble.View?
require("trouble").open(opts)

-- Closes the last open view matching the filter.
---@param opts? trouble.Mode|string
---@return trouble.View?
require("trouble").close(opts)

-- Toggle the view with the given mode.
---@param opts? trouble.Mode|string
---@return trouble.View?
require("trouble").toggle(opts)

-- Returns true if there is an open view matching the mode.
---@param opts? trouble.Mode|string
require("trouble").is_open(opts)

-- Refresh all open views. Normally this is done automatically,
-- unless you disabled auto refresh.
---@param opts? trouble.Mode|string
require("trouble").refresh(opts)

-- Get all items from the active view for a given mode.
---@param opts? trouble.Mode|string
require("trouble").get_items(opts)

-- Renders a trouble list as a statusline component.
-- Check the docs for examples.
---@param opts? trouble.Mode|string|{hl_group?:string}
---@return {get: (fun():string), has: (fun():boolean)}
require("trouble").statusline(opts)

-- Closes the preview and goes to the main window.
-- The Trouble window is not closed.
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").cancel(opts)

-- Open the preview
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").delete(opts)

-- filter
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").filter(opts)

-- Go to the first item
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").first(opts)

-- Focus the trouble window
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").focus(opts)

-- Fold close 
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_close(opts)

-- fold close all
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_close_all(opts)

-- Fold close recursive
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_close_recursive(opts)

-- fold disable
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_disable(opts)

-- fold enable
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_enable(opts)

-- fold more
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_more(opts)

-- Fold open 
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_open(opts)

-- fold open all
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_open_all(opts)

-- Fold open recursive
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_open_recursive(opts)

-- fold reduce
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_reduce(opts)

-- Fold toggle 
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_toggle(opts)

-- fold toggle enable
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_toggle_enable(opts)

-- Fold toggle recursive
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_toggle_recursive(opts)

-- fold update
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_update(opts)

-- fold update all
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").fold_update_all(opts)

-- Show the help
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").help(opts)

-- Dump the item to the console
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").inspect(opts)

-- Jump to the item if on an item, otherwise fold the node
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").jump(opts)

-- Jump to the item and close the trouble window
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").jump_close(opts)

-- Jump to the item if on an item, otherwise do nothing
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").jump_only(opts)

-- Open the item in a split
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").jump_split(opts)

-- Open the item in a vsplit
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").jump_vsplit(opts)

-- Go to the last item
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").last(opts)

-- Go to the next item
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").next(opts)

-- Go to the previous item
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").prev(opts)

-- Open the preview
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").preview(opts)

-- Refresh the trouble source
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").refresh(opts)

-- Toggle the preview
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").toggle_preview(opts)

-- Toggle the auto refresh
---@param opts? trouble.Mode | { new? : boolean } | string
---@return trouble.View
require("trouble").toggle_refresh(opts)

Telescope

You can easily open any search results in Trouble, by defining a custom action:

local actions = require("telescope.actions")
local open_with_trouble = require("trouble.sources.telescope").open

-- Use this to add more results without clearing the trouble list
local add_to_trouble = require("trouble.sources.telescope").add

local telescope = require("telescope")

telescope.setup({
  defaults = {
    mappings = {
      i = { ["<c-t>"] = open_with_trouble },
      n = { ["<c-t>"] = open_with_trouble },
    },
  },
})

When you open telescope, you can now hit <c-t> to open the results in Trouble

fzf-lua

You can easily open any search results in Trouble, by defining a custom action:

local config = require("fzf-lua.config")
local actions = require("trouble.sources.fzf").actions
config.defaults.actions.files["ctrl-t"] = actions.open

When you open fzf-lua, you can now hit <c-t> to open the results in Trouble

Statusline Component

Example for lualine.nvim:

{
  "nvim-lualine/lualine.nvim",
  opts = function(_, opts)
    local trouble = require("trouble")
    local symbols = trouble.statusline({
      mode = "lsp_document_symbols",
      groups = {},
      title = false,
      filter = { range = true },
      format = "{kind_icon}{symbol.name:Normal}",
      -- The following line is needed to fix the background color
      -- Set it to the lualine section you want to use
      hl_group = "lualine_c_normal",
    })
    table.insert(opts.sections.lualine_c, {
      symbols.get,
      cond = symbols.has,
    })
  end,
}

🎨 Colors

The table below shows all the highlight groups defined for Trouble.

Highlight Groups
Highlight Group Default Group Description
TroubleBasename TroubleFilename
TroubleCode Special
TroubleCount TabLineSel
TroubleDirectory Directory
TroubleFilename Directory
TroubleIconArray @punctuation.bracket
TroubleIconBoolean @boolean
TroubleIconClass @type
TroubleIconConstant @constant
TroubleIconConstructor @constructor
TroubleIconDirectory Special
TroubleIconEnum @lsp.type.enum
TroubleIconEnumMember @lsp.type.enumMember
TroubleIconEvent Special
TroubleIconField @variable.member
TroubleIconFile Normal
TroubleIconFunction @function
TroubleIconInterface @lsp.type.interface
TroubleIconKey @lsp.type.keyword
TroubleIconMethod @function.method
TroubleIconModule @module
TroubleIconNamespace @module
TroubleIconNull @constant.builtin
TroubleIconNumber @number
TroubleIconObject @constant
TroubleIconOperator @operator
TroubleIconPackage @module
TroubleIconProperty @property
TroubleIconString @string
TroubleIconStruct @lsp.type.struct
TroubleIconTypeParameter @lsp.type.typeParameter
TroubleIconVariable @variable
TroubleIndent LineNr
TroubleIndentFoldClosed CursorLineNr
TroubleIndentFoldOpen TroubleIndent
TroubleIndentLast TroubleIndent
TroubleIndentMiddle TroubleIndent
TroubleIndentTop TroubleIndent
TroubleIndentWs TroubleIndent
TroubleNormal NormalFloat
TroubleNormalNC NormalFloat
TroublePos LineNr
TroublePreview Visual
TroubleSource Comment
TroubleText Normal

trouble.nvim's People

Contributors

0x7a7a avatar abusch avatar augustocdias avatar bellini666 avatar deecewan avatar eatgrass avatar echasnovski avatar elkowar avatar feiyoug avatar folke avatar github-actions[bot] avatar hanspinckaers avatar igorassuncao avatar jasonrhansen avatar jgoguen avatar jmbaur avatar jnalley avatar jordelver avatar jrnxf avatar lanej avatar lewis6991 avatar logarithmus avatar lvim-tech avatar mariasolos avatar runiq avatar saecki avatar shortcuts avatar unrealapex avatar yodaembedding avatar zidhuss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trouble.nvim's Issues

Invalid buffer id on opening Trouble

Hi,

I've been getting an intermittent error using trouble for quite a while now when running
Trouble lsp_workspace_diagnostics ever so often the command will fail with the following error

E5108: Error executing lua ...m/site/pack/packer/opt/trouble.nvim/lua/trouble/util.lua:72: Invalid buffer id: 13

This error also seems to take down Telescope's workspace diagnostics once it happens. I can still access the diagnostics using the lsp's set loclist function on LspDiagnosticsChanged. I'm not really sure what is happening exactly since it only happens from time to time.

Looking at the code the process_items function seems to be where it's happening i.e. a bufnr is being passed to nvim_buf_get_name but the number is no longer valid. Seems to have been unloaded, when I check for the buffer number using ls! it is not in the list.

Tbh I'm not sure why/how it has reference to a buffer that has since vanished but I guess a naive fix would be to check the bufnr is valid before using it.

As the logic is borrowed from telescope and it also errors it seems somewhere/somehow in my config or some plugin a buffer is being created which this plugin gets a reference to then being removed but I can't identify what is doing it because by the time this error occurs all traces of this buffer are gone

Multi-line diagnostics

Hey, would you consider supporting multi-line diagnostics? Right now all lines are concatenated and displayed in a single line, while vim.lsp.diagnostic.show_line_diagnostics() displays them correctly.

screenshot-210427-094654

Turn a window into the trouble list

Hi. I've spent minimal time with trouble so far, so apologies if this is somewhere I haven't found yet.

I want a way to turn an existing (empty) buffer into the trouble list. (Ideally I'd love to also have trouble use part of a buffer that is also being used for other things, but that I assume is more complex).

Does at least the former exist? What I see so far just looks like allowing trouble to do the split itself via LspTroubleOpen/Toggle, but I haven't fully read through the Lua API yet.

And thanks!

Feature request: Support more actions

Thanks for the cool plugin.

In some case, I want to open the buffer in a new tab or a split window instead of the current window. It would be nice that the plugin has tabe, vsplit and split actions.

Diagnostic Icons

Hi, how do i get the diagnostic icons in the gutter?

image

Plug 'kyazdani42/nvim-web-devicons'
Plug 'folke/trouble.nvim'

Focus current line when opening Trouble

If my cursor is on a line with an error when I open Trouble, I'd like trouble to show the errors on that line.

Prerequisite:
Have your cursor on a line that has an error on it. Then run :Trouble

Current behaviour:
Trouble will open, and select the first error in the workspace. Your cursor will jump away from its current position to the file/location of the first error listed in Trouble.

Desired behaviour:
Trouble should recognize that there is an error on the current line, and initially focus that error. If not too difficult, it would be nice if it found the nearest error to the cursor, so if you were next to an error but not on it, Trouble would still jump to that error. But that's not quite as important to me.

No Highlighting When Jumping to Diagnostics with auto_preview off

Hi there!

Very cool plugin - happy to see you've borrowed from the telescope diagnostics code (as I see some of my comments in the code base) :) glad you've found it useful!

One thing I noticed when playing around with it with these settings

require("trouble").setup {
  use_lsp_diagnostic_signs = true,
  auto_preview = false,
}

unlike with auto previewing, highlighting (= tree-sitter) does not attach to the buffer when jumping to the diagnostic as can be seen in the video.

lsp_trouble-2021-04-22_20.37.35.mp4

I was able to reproduce this issue with a minimal config that only loads my nvim-treesitter config, my nvim-lsp config and LSP Trouble

From the initial looks of it, in my scenario vim.cmd "e" is skipped? I'm happy to further explore the code base and see if I can submit a PR but probably won't have time before Sunday evening.

Jump to next warning or next error

There are next and previous functions, it would be great to have an option to jump a trouble with a specific type. It allows to focus on more severe troubles without distracting to non-significant troubles at the moment.

Errors recognized only after files are visited

Hey, thanks for the really cool plugin.

I noticed that when I open a project and do lsp_workspace_diagnostics search, the list will be empty even if there are errors in the project.

Only after I visit the files with errors in them, will they show up in trouble.

Is this a limitation of nvim's LSP or intended behavior?

Workspace diagnostics only includes open buffers

I can't figure out how to get all workspace diagnostics to show up.

I have lsp_extensions.nvim installed and overridden the publishDiagnostics handler in my config like so:

vim.lsp.handlers['textDocument/publishDiagnostics'] =
    vim.lsp.with(require('lsp_extensions.workspace.diagnostic').handler, {
        underline = false,
        signs = true,
        update_in_insert = false -- delay update
    })

When I run

:lua require('lsp_extensions.workspace.diagnostic').set_qf_list()

the quickfix list contains all diagnostics of files in the workspace. However when I run

:LspTroubleToggle lsp_workspace_diagnostics

it is empty. update: I actually just figured out it only shows diagnostics of currently open buffers.

How can I configure Trouble to pick up all workspace diagnostics?

Auto open throws nil self error

Hi, thanks for your work on this plugin 🚀 , it's very swanky which I'm a big fan of.

I just hit an issue I thought I'd mention. When setting auto open to true I see the following error

executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/lsp/diagnostic.lua:1078: Vim(lua):E5108: Error executing lua .../pack/packer/start/lsp-trouble.nvim
/lua/trouble/view.lua:230: attempt to index local 'self' (a nil value)

LspInfo shows

Configured servers: graphql, lua, diagnosticls, vim
Neovim logs at: /home/akin/.cache/nvim/lsp.log

2 client(s) attached to this buffer: diagnosticls, lua

  Client: diagnosticls (id 1)
  	root:      /home/akin/.dotfiles/.config/nvim/lua/as/plugins
  	filetypes: yaml, json, html, css, markdown, lua, graphql
  	cmd:       /home/akin/.local/share/nvim/lspinstall/diagnosticls/./node_modules/.bin/diagnostic-languageserver --stdio
  	


  Client: lua (id 2)
  	root:      /home/akin/.dotfiles
  	filetypes: lua
  	cmd:       /home/akin/.local/share/nvim/lspinstall/lua/./sumneko-lua-language-server
  	


3 active client(s): 

  Client: diagnosticls (id 1)
  	root:      /home/akin/.dotfiles/.config/nvim/lua/as/plugins
  	filetypes: yaml, json, html, css, markdown, lua, graphql
  	cmd:       /home/akin/.local/share/nvim/lspinstall/diagnosticls/./node_modules/.bin/diagnostic-languageserver --stdio
  	


  Client: lua (id 2)
  	root:      /home/akin/.dotfiles
  	filetypes: lua
  	cmd:       /home/akin/.local/share/nvim/lspinstall/lua/./sumneko-lua-language-server
  	


  Client: diagnosticls (id 3)
  	root:      /home/akin/.dotfiles/.config/nvim/lua/as/globals
  	filetypes: yaml, json, html, css, markdown, lua, graphql
  	cmd:       /home/akin/.local/share/nvim/lspinstall/diagnosticls/./node_modules/.bin/diagnostic-languageserver --stdio
  	


Clients that match the filetype lua:
  
  Config: lua
  	cmd:               /home/akin/.local/share/nvim/lspinstall/lua/./sumneko-lua-language-server
  	cmd is executable: True
  	identified root:   /home/akin/.dotfiles
  	custom handlers:   
  
  Config: diagnosticls
  	cmd:               /home/akin/.local/share/nvim/lspinstall/diagnosticls/./node_modules/.bin/diagnostic-languageserver --stdio
  	cmd is executable: True
  	identified root:   /home/akin/.dotfiles/.config/nvim/lua/as
  	custom handlers:   

Lemme know if you need anymore info.

Option to auto-close error-list after confirming a jump

I'd love to have the error list automatically close once I jump to one of the errors (i.e. hit enter). Currently, if i want to close it again after jumping, i have to <C-w><C-w>q, which is rather anoying. having a close_on_jump option would be nice, and is the main thing keeping me from using this right now

Auto open and auto close doesn't work

Hi, thank you for making such an awesome plugin. I notice that the auto_open and auto_close doesn't work.

This is my configuration

local function init(paq)
	paq{'folke/trouble.nvim'}
	require'trouble'.setup{
		position = "left",
		width = 30,
		use_lsp_diagnostic_signs = true,
		indent_lines = false,
		auto_open = true, 
		auto_close = true,
	}
	vim.api.nvim_set_keymap("n", "<C-l>", "<cmd>Trouble lsp_document_diagnostics<cr>",
	{silent = true, noremap = true}
	)
end

return {
	init = init
}

No errors shown in list

I installed lsp-trouble.nvim with Vim-Plug
nvim version: 0.5 nightly
I use your tokyonight colorscheme

I created a file to test the LspTrouble.
Then I used :LspTroubleOpen

Screen Shot 2021-04-29 at 14 59 46

The list is just empty even though, there are errors

Ability to ignore certain errors

I have a Python project that uses the attrs library. The language server pyright doesn't support attrs and always reports errors when an attrs class is used. Therefore, the list provided in this plugin always contains a known set of things that I simply can't change. Having some kind of filtering possibility to ignore known errors would help very much in this situation.

Can this be made to work with coc-nvim?

From what I can gather from the Readme, it looks like this only works with the neovim LSP client? Any chance this could be expanded to work with coc-nvim (probably other popular LSP clients too?)

I could be totally misunderstanding how this works though...

Execute commands on each line/file?

Hello! Trouble looks great, the only thing stopping me using it is the ability to execute commands on each file in the list.

My primary usecase is project-wide search and replace, example workflow:

  1. Execute a project-wide search (using e.g. Telescope or fzf)
  2. Open the results in a quickfix window
  3. Use cdo or cfdo to do a find/replace on each file or each result

Is anything like this possible with Trouble, or would you consider it a useful feature? Thanks ✌️

(side note: also open to hearing about other workflows for project wide find/replace!)

Highlight group for EndOfBuffer

Hi 👋🏾 ,

I just started customising my LspTroubleNormal background and noticed that it doesn't include the EndOfBuffer highlight so things looks like this.

image

The first line is the darkened highlight and the bottom is the EndOfBuffer. I think it should default link to LspTroubleNormal so it would be something like.

setlocal winhighlight=Normal:LspTroubleNormal,EndOfBuffer:LspTroubleNormal,SignColumn:LspTroubleNormal

This way a user can change the color of the full window not just part of it.

Send results to telescope

Hey,

I know there is a way to send telescope results to trouble.

But is there a way to send trouble results to telescope?

I find It easier to navigate telescope's picker when there are a lot of files in the project.

Thanks!

is there a way to prevent auto_open from stealing focus?

First off, this is a great plugin. Thank you!

I have auto_open = true in my config. When I open up a file with errors, the trouble window opens... and steals focus from the main editing buffer.

Is there a way to disable that, or return focus to the editor window?

Is there a way to disable folding?

Folding is causing me some grief - I inadvertently fold/unfold items and then it's difficult to switch back to editing. Is there an easy way to disable folding? It's ok (preferred, actually) to have the errors grouped by filename; I just don't want that list to collapse. Thank you.

Make list UI more generically usable

Currently, this is one of the, if not the best UIs for a location-jump list interface. Especially once #15 is implemented, the UX here will be pretty much perfect!

Given that fact, I'd love to use the same UI in other places, too - such as a list references menu, stuff like that.

It would be amazing if it was possible to provide a more generic API for the list UI that can be used from outside of the plugin (such that I could manually implement this as my find-references provider, too), and, optimally, if this would just support these other use-cases out of the box.

Thanks for making an amazing plugin!

Configurable diagnostics sorting

I'd like to sort diagnostics by line number. I see that right now diagnostics are sorted by severity here:

provider(win, buf, function(items)
table.sort(items, function(a, b)
if a.severity == b.severity then
return a.lnum < b.lnum
else
return a.severity < b.severity
end
end)
cb(items)
end, options)
end

That's done in an anonymous function. Do you think it would be reasonable to make this function configurable (so I can pass in my custom sorter)?

Errors from BufEnter/BufWinEnter Autocommands on opening after installing trouble

I'm getting the following errors after installing this plugin. I'm still in the process of learning lua and all the new stuff in 0.5 so apologies if this is user error. I have plenty of other stuff going on in my config but i'm not doing anything explicitly with these autocommands.

Thanks for all the work you've put into this!

Error detected while processing BufWinEnter Autocommands for "*":
E5108: Error executing lua [string ":lua"]:1: attempt to index a boolean value
Error detected while processing BufEnter Autocommands for "*":
E5108: Error executing lua [string ":lua"]:1: attempt to index a boolean value
Error executing vim.schedule lua callback: ...ovim/0.5.0/share/nvim/runtime/lua/vim/lsp/diagnostic.lua:1091: Vim(lua):E5108: Error executing lua [string ":lua"]:1: attempt to index a boolean value

closing trouble gives focus back to the wrong window

Suppose you have two windows open, and . is current cursor position

|--------------|-------------|
|              | .           |
|              |             |
|      1       |      2      |
|              |             |
|              |             |
|--------------|-------------|

running :Trouble opens the window and gives focus to the window (new . below)

|--------------|-------------|
|              |             |
|              |             |
|      1       |      2      |
|              |             |
|              |             |
|--------------|-------------|
| .                          |
|           trouble          |
|----------------------------|

now, pressing q (default keymap) results in the cursor going back to window 1

|--------------|-------------|
| .            |             |
|              |             |
|      1       |      2      |
|              |             |
|              |             |
|--------------|-------------|

where i feel it should probably go back to it's previous position in window 2

vim.schedule lua callback error

I'm getting this error constantly, lsp trouble work with no problem but it's kinda annoying

Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/lsp/diagnostic.lua:1078: Vim(lua):E5108: Error executing lua ...onfig/nvim/plugged/lsp-trouble.nvim/lua/trouble/init.lua:32: attempt to call method 'match' (a nil value)

neovim version: NVIM v0.5.0-dev+1233-g82ac44d01 (I installed it using aur)

Can't configure signs

I've tried different symbols and plain text. Doesn't seem to make any difference. The action_keys config works.

use {
  'folke/lsp-trouble.nvim',
  requires = {
    'kyazdani42/nvim-web-devicons'
  },
  config = function()
    require( 'trouble' ).setup {
      action_keys = {
        toggle_fold = { '<Space>' }
      },
      signs = {
        error = ' ',
        warning = ' ',
        hint = ' ',
        information = ' '
      }
    }
  end
}

Feature request: possibility of different grouping

Currently, when using with 'trouble.nvim' all found keyword comments are grouped by file. I often find myself wanting to look only at all TODOs. I can do that by unfolding everything and using built-in search, but it is a bit troublesome. Maybe there is a way to incorporate different grouping? So that folds represent different keywords and not files. Maybe a keymapping inside Trouble window?

Or is it better to open this issue in 'trouble.nvim'?

Command I am currently using: TroubleToggle todo.

Semantic highlight gets messed up when used with ccls + vim-lsp-cxx-highlight

I'm trying to use this plugin on c++ development which uses ccls as the language server and vim-lsp-cxx-highlight as the plugin that does the semantic highlighting.

When I get the all references of some function through TroubleToggle lsp_references it pops up a separate buffer giving the correct occurrences accurately. Also I can hover through the suggestions where it opens up temporary buffers displaying the files. But when I quit the list I could observe all the highlights on the original file which I started with is all messed up

I'm not entirely sure if this is an issue in this plugin or the lsp cxx highlight plugin.

Option to exclude files / directories

Lsp needs to parse dependent libraries (e.g. vendored modules in go), but any issues reported with the code are most likely not relevant to the Trouble user. It would be nice if files / directories can be excluded based on e.g. a glob pattern.

Cursor position outside buffer (telescope into qfix)

First things first: YOU ARE AWESOME! Ty for your work!

Currently my workflow involves telescoping into quickfix. With trouble ill get lua exceptions, because telescope adds files with position [0, 0] to qfix.

image

After navigating on one entry with preview set to true, nvim fires:

image

Clear telescope search results

After populating the Trouble list with Telescope search results, is it possible to clear them somehow? Otherwise they continue to clutter up the list and there seems to be no way to "resolve" them.

[Feature request] Add lsp_document_symbols

I like the UI of this plugin and would love to be able to integrate into my LSP environment. One thing I think would work well is adding the ability to show symbols so that one can keep the menu open on one side to reference assignments

Directly jump on single results

I find myself "troubled" when I have to interact with trouble when there is only singular implementation or definition. I would prefer if I only jump to the definition or to the implementation instead of having to press <CR> or q to confirm the singular result or quit trouble.

Trouble highlight links aren't updated since rename

Hi @folke,

I've been tweaking the colors for my trouble window, and according to the docs TroubleText is supposed to be a base for a few other text highlight groups. So I tried tweaking trouble text hoping it would affect the colours of the linked groups but it didn't. Inspecting those groups it seems that most of them link to the old highlight groups e.g. TroubleText -> LspTroubleText, I think somewhere along the linking highlight groups aren't being linked correctly?

Sorry that felt rambly so TLDR.
I've set TroubleText to guifg=x guibg=x but this doesn't update the highlights for TroubleErrorText for example. I tried sequencing things a bit differently but didn't see a difference.

Question: Possible to Target the Trouble buffer?

I can't seem to figure out how I target the Trouble buffer, so I can run certain commands automatically from autocmd. Is it possible to create an autocmd that triggers when you open the Trouble buffer?

[Feature] some external function

How do I move to the next item on trouble but my current buffer is not in trouble? If i use quick fix i can do that.
I want display the total error warning and hint in my custom statusline for filetype. Can you expose some function to get that data.
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.