• Stars
    star
    4,726
  • Rank 8,496 (Top 0.2 %)
  • Language
    Lua
  • License
    Apache License 2.0
  • Created about 3 years ago
  • Updated 13 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

🚦 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.

LSP Trouble Screenshot

✨ Features

  • pretty list of:
    • Diagnostics
    • LSP references
    • LSP implementations
    • LSP definitions
    • LSP type definitions
    • quickfix list
    • location list
    • Telescope search results
  • automatically updates on new diagnostics
  • toggle diagnostics mode between workspace or document
  • interactive preview in your last accessed window
  • cancel preview or jump to the location
  • configurable actions, signs, highlights,...

⚑️ Requirements

  • Neovim >= 0.7.2
  • Properly configured Neovim LSP client
  • nvim-web-devicons is optional to enable file icons
  • a theme with properly configured highlight groups for Neovim Diagnostics
  • or install 🌈 lsp-colors to automatically create the missing highlight groups
  • a patched font for the default severity and fold icons

πŸ“¦ Installation

Install the plugin with your preferred package manager:

lazy.nvim

return {
 "folke/trouble.nvim",
 dependencies = { "nvim-tree/nvim-web-devicons" },
 opts = {
  -- your configuration comes here
  -- or leave it empty to use the default settings
  -- refer to the configuration section below
 },
}

βš™οΈ Configuration

Setup

Trouble comes with the following defaults:

{
    position = "bottom", -- position of the list can be: bottom, top, left, right
    height = 10, -- height of the trouble list when position is top or bottom
    width = 50, -- width of the list when position is left or right
    icons = true, -- use devicons for filenames
    mode = "workspace_diagnostics", -- "workspace_diagnostics", "document_diagnostics", "quickfix", "lsp_references", "loclist"
    severity = nil, -- nil (ALL) or vim.diagnostic.severity.ERROR | WARN | INFO | HINT
    fold_open = "ο‘Ό", -- icon used for open folds
    fold_closed = "ο‘ ", -- icon used for closed folds
    group = true, -- group results by file
    padding = true, -- add an extra new line on top of the list
    action_keys = { -- key mappings for actions in the trouble list
        -- map to {} to remove a mapping, for example:
        -- close = {},
        close = "q", -- close the list
        cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor
        refresh = "r", -- manually refresh
        jump = {"<cr>", "<tab>"}, -- jump to the diagnostic or open / close folds
        open_split = { "<c-x>" }, -- open buffer in new split
        open_vsplit = { "<c-v>" }, -- open buffer in new vsplit
        open_tab = { "<c-t>" }, -- open buffer in new tab
        jump_close = {"o"}, -- jump to the diagnostic and close the list
        toggle_mode = "m", -- toggle between "workspace" and "document" diagnostics mode
        switch_severity = "s", -- switch "diagnostics" severity filter level to HINT / INFO / WARN / ERROR
        toggle_preview = "P", -- toggle auto_preview
        hover = "K", -- opens a small popup with the full multiline message
        preview = "p", -- preview the diagnostic location
        close_folds = {"zM", "zm"}, -- close all folds
        open_folds = {"zR", "zr"}, -- open all folds
        toggle_fold = {"zA", "za"}, -- toggle fold of current file
        previous = "k", -- previous item
        next = "j" -- next item
    },
    indent_lines = true, -- add an indent guide below the fold icons
    auto_open = false, -- automatically open the list when you have diagnostics
    auto_close = false, -- automatically close the list when you have no diagnostics
    auto_preview = true, -- automatically preview the location of the diagnostic. <esc> to close preview and go back to last window
    auto_fold = false, -- automatically fold a file trouble list at creation
    auto_jump = {"lsp_definitions"}, -- for the given modes, automatically jump if there is only a single result
    signs = {
      -- icons / text used for a diagnostic
      error = "ξͺ‡",
      warning = "",
      hint = "ξ©‘",
      information = "",
      other = "ξ©΄",
    },
    use_diagnostic_signs = false -- enabling this will use the signs defined in your lsp client
}

πŸ’‘ if you don't want to use icons or a patched font, you can use the settings below

-- settings without a patched font or icons
{
    icons = false,
    fold_open = "v", -- icon used for open folds
    fold_closed = ">", -- icon used for closed folds
    indent_lines = false, -- add an indent guide below the fold icons
    signs = {
        -- icons / text used for a diagnostic
        error = "error",
        warning = "warn",
        hint = "hint",
        information = "info"
    },
    use_diagnostic_signs = false -- enabling this will use the signs defined in your lsp client
}

πŸš€ Usage

Commands

Trouble comes with the following commands:

  • Trouble [mode]: open the list
  • TroubleClose [mode]: close the list
  • TroubleToggle [mode]: toggle the list
  • TroubleRefresh: manually refresh the active list

Modes:

  • document_diagnostics: document diagnostics from the builtin LSP client
  • workspace_diagnostics: workspace diagnostics from the builtin LSP client
  • lsp_references: references of the word under the cursor from the builtin LSP client
  • lsp_definitions: definitions of the word under the cursor from the builtin LSP client
  • lsp_type_definitions: type definitions of the word under the cursor from the builtin LSP client

Example keybindings:

" Vim Script
nnoremap <leader>xx <cmd>TroubleToggle<cr>
nnoremap <leader>xw <cmd>TroubleToggle workspace_diagnostics<cr>
nnoremap <leader>xd <cmd>TroubleToggle document_diagnostics<cr>
nnoremap <leader>xq <cmd>TroubleToggle quickfix<cr>
nnoremap <leader>xl <cmd>TroubleToggle loclist<cr>
nnoremap gR <cmd>TroubleToggle lsp_references<cr>
-- Lua
vim.keymap.set("n", "<leader>xx", "<cmd>TroubleToggle<cr>",
  {silent = true, noremap = true}
)
vim.keymap.set("n", "<leader>xw", "<cmd>TroubleToggle workspace_diagnostics<cr>",
  {silent = true, noremap = true}
)
vim.keymap.set("n", "<leader>xd", "<cmd>TroubleToggle document_diagnostics<cr>",
  {silent = true, noremap = true}
)
vim.keymap.set("n", "<leader>xl", "<cmd>TroubleToggle loclist<cr>",
  {silent = true, noremap = true}
)
vim.keymap.set("n", "<leader>xq", "<cmd>TroubleToggle quickfix<cr>",
  {silent = true, noremap = true}
)
vim.keymap.set("n", "gR", "<cmd>TroubleToggle lsp_references<cr>",
  {silent = true, noremap = true}
)

API

You can use the following functions in your keybindings:

-- jump to the next item, skipping the groups
require("trouble").next({skip_groups = true, jump = true});

-- jump to the previous item, skipping the groups
require("trouble").previous({skip_groups = true, jump = true});

-- jump to the first item, skipping the groups
require("trouble").first({skip_groups = true, jump = true});

-- jump to the last item, skipping the groups
require("trouble").last({skip_groups = true, jump = true});

Telescope

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

local actions = require("telescope.actions")
local trouble = require("trouble.providers.telescope")

local telescope = require("telescope")

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

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

🎨 Colors

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

Highlight Group
TroubleCount
TroubleError
TroubleNormal
TroubleTextInformation
TroubleSignWarning
TroubleLocation
TroubleWarning
TroublePreview
TroubleTextError
TroubleSignInformation
TroubleIndent
TroubleSource
TroubleSignHint
TroubleSignOther
TroubleFoldIcon
TroubleTextWarning
TroubleCode
TroubleInformation
TroubleSignError
TroubleFile
TroubleHint
TroubleTextHint
TroubleText

More Repositories

1

lazy.nvim

πŸ’€ A modern plugin manager for Neovim
Lua
11,573
star
2

tokyonight.nvim

πŸ™ A clean, dark Neovim theme written in Lua, with support for lsp, treesitter and lots of plugins. Includes additional themes for Kitty, Alacritty, iTerm and Fish.
Lua
5,173
star
3

which-key.nvim

πŸ’₯ Create key bindings that stick. WhichKey is a lua plugin for Neovim 0.5 that displays a popup with possible keybindings of the command you started typing.
Lua
4,441
star
4

noice.nvim

πŸ’₯ Highly experimental plugin that completely replaces the UI for messages, cmdline and the popupmenu.
Lua
3,677
star
5

todo-comments.nvim

βœ… Highlight, list and search todo comments in your projects
Lua
2,711
star
6

flash.nvim

Navigate your code with search labels, enhanced character motions and Treesitter integration
Lua
1,965
star
7

neodev.nvim

πŸ’» Neovim setup for init.lua and plugin development with full signature help, docs and completion for the nvim lua API.
Lua
1,935
star
8

zen-mode.nvim

🧘 Distraction-free coding for Neovim
Lua
1,442
star
9

ultra-runner

πŸƒβ›° Ultra fast monorepo script runner and build tool
TypeScript
1,188
star
10

twilight.nvim

πŸŒ… Twilight is a Lua plugin for Neovim 0.5 that dims inactive portions of the code you're editing using TreeSitter.
Lua
1,130
star
11

esbuild-runner

⚑️ Super-fast on-the-fly transpilation of modern JS, TypeScript and JSX using esbuild
TypeScript
701
star
12

dot

β˜•οΈ My Dot Files
Lua
670
star
13

edgy.nvim

Easily create and manage predefined window layouts, bringing a new edge to your workflow
Lua
665
star
14

neoconf.nvim

πŸ’Ό Neovim plugin to manage global and project-local settings
Lua
605
star
15

persistence.nvim

πŸ’Ύ Simple session management for Neovim
Lua
533
star
16

lsp-colors.nvim

🌈 Plugin that creates missing LSP diagnostics highlight groups for color schemes that don't yet support the Neovim 0.5 builtin LSP client.
Lua
434
star
17

devmoji

πŸ€– πŸš€ ✨ Emojify your conventional commits with Devmoji
TypeScript
286
star
18

styler.nvim

Simple Neovim plugin to set a different colorscheme per filetype.
Lua
247
star
19

drop.nvim

🍁 Fun little plugin that can be used as a screensaver and on your dashboard
Lua
190
star
20

polydock

✨ A shiny and hackable application dock
TypeScript
179
star
21

paint.nvim

Easily add additional highlights to your buffers
Lua
152
star
22

vscode-monorepo-workspace

πŸ“¦βœ¨Manage monorepos with multi-root workspaces. Supports Lerna, Yarn, Pnpm, Rushjs and recursive package directories.
TypeScript
138
star
23

splashcii

Simple cli tool that shows a random ascii art from https://www.asciiur.com/
TypeScript
35
star
24

semantic-release-commit-filter

πŸ“¦πŸ•΅οΈβ€β™€οΈ Semantic-release plugin that filters git commits based on the current working directory
JavaScript
25
star
25

zmk-config

Folke's ZMK config
C++
21
star
26

lovelace-styler

Custom styling for lovelace cards
TypeScript
18
star
27

folke

7
star
28

phpintel

Accurate autocompletion / code checking / .... framework for PHP
PHP
3
star
29

adventofcode

πŸŽ… πŸŽ„ β›„ ✨ Solutions for Advent of Code 2020 in TypeScript
TypeScript
2
star
30

chess

C#
2
star
31

adventofcode2019

Advent of Code 2019 in TypeScript
TypeScript
2
star