Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

folke/trouble.nvim

Repository files navigation

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 originaltrouble.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 andTrouble command
  • troublemodes to define custom views
  • statusline component (useful with document symbols)

⚡️ Requirements

  • Neovim >= 0.9.2
  • Neovim >= 0.10.0OR themarkdown andmarkdown_inlinenvim-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
  • apatched 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
---@classtrouble.Mode:trouble.Config,trouble.Section.spec---@fielddesc?string---@fieldsections?string[]---@classtrouble.Config---@fieldmode?string---@fieldconfig?fun(opts:trouble.Config)---@fieldformatters?table<string,trouble.Formatter> custom formatters---@fieldfilters?table<string,trouble.FilterFn> custom filters---@fieldsorters?table<string,trouble.SorterFn> custom sorterslocaldefaults= {auto_close=false,-- auto close when there are no itemsauto_open=false,-- auto open when there are itemsauto_preview=true,-- automatically open preview when on an itemauto_refresh=true,-- auto refresh when openauto_jump=false,-- auto jump to the item when there's only onefocus=false,-- Focus the window when openedrestore=true,-- restores the last location in the list when openingfollow=true,-- Follow the current itemindent_guides=true,-- show indent guidesmax_items=200,-- limit number of items that can be displayed per sectionmultiline=true,-- render multi-line messagespinned=false,-- When pinned, the opened trouble window will be bound to the current bufferwarn_no_results=true,-- show a warning when there are no resultsopen_no_results=false,-- open the trouble window when there are no results---@typetrouble.Window.optswin= {},-- 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.---@typetrouble.Window.optspreview= {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.---@typetable<string,number|{ms:number,debounce?:boolean}>throttle= {refresh=20,-- fetches new data when neededupdate=10,-- updates the windowrender=10,-- renders the windowfollow=100,-- follows the current itempreview= {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.---@typetable<string,trouble.Action.spec|false>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 filteraction=function(view)view:filter({buf=0 }, {toggle=true })end,desc="Toggle Current Buffer Filter",    },s= {-- example of a custom action that toggles the severityaction=function(view)localf=view:get_filter("severity")localseverity= ((fandf.filter.severityor0)+1)%5view:filter({severity=severity }, {id="severity",template="{hl:Title}Filter:{hl} {severity}",del=severity==0,        })end,desc="Toggle Severity Filter",    },  },---@typetable<string,trouble.Mode>modes= {-- sources define their own modes, which you can use directly,-- or override like in the example belowlsp_references= {-- some modes are configurable, see the source code for more detailsparams= {include_declaration=true,      },    },-- The LSP base mode for:-- * lsp_definitions, lsp_references, lsp_implementations-- * lsp_type_definitions, lsp_declarations, lsp_commandlsp_base= {params= {-- don't include the current location in the resultsinclude_current=false,      },    },-- more advanced example that extends the lsp_document_symbolssymbols= {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 filesft= {"help","markdown"},-- default set of symbol kindskind= {"Class","Constructor","Enum","Field","Function","Interface","Method","Module","Namespace","Package","Property","Struct","Trait",          },        },      },    },  },icons= {---@typetrouble.Indent.symbolsindent= {top="",middle="├╴",last="└╴",-- last          = "-╴",-- last       = "╰╴", -- roundedfold_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 theExamples!

🚀 Usage

Commands

TheTrouble command is a wrapper around theTrouble 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 win.relative=win win.position=right
  • You can uselua code in the options for theTrouble 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 win.type = split win.position=right
    • Trouble diagnostics win = { type = split, position=right}
    • Trouble diagnostics 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 withrequire('trouble.sources.fzf').open().
  • fzf_files: FzfLua results previously opened withrequire('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
  • snacks: Snacks results previously opened withrequire('trouble.sources.snacks').open().
  • snacks_files: Snacks results previously opened withrequire('trouble.sources.snacks').open().
  • symbols: document symbols
  • telescope: Telescope results previously opened withrequire('trouble.sources.telescope').open().
  • telescope_files: Telescope results previously opened withrequire('trouble.sources.telescope').open().

Filters

Please refer to thefilter 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.---@paramopts?trouble.Mode| {new?:boolean,refresh?:boolean} |string---@returntrouble.View?require("trouble").open(opts)-- Closes the last open view matching the filter.---@paramopts?trouble.Mode|string---@returntrouble.View?require("trouble").close(opts)-- Toggle the view with the given mode.---@paramopts?trouble.Mode|string---@returntrouble.View?require("trouble").toggle(opts)-- Returns true if there is an open view matching the mode.---@paramopts?trouble.Mode|stringrequire("trouble").is_open(opts)-- Refresh all open views. Normally this is done automatically,-- unless you disabled auto refresh.---@paramopts?trouble.Mode|stringrequire("trouble").refresh(opts)-- Get all items from the active view for a given mode.---@paramopts?trouble.Mode|stringrequire("trouble").get_items(opts)-- Renders a trouble list as a statusline component.-- Check the docs for examples.---@paramopts?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.---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").cancel(opts)-- Open the preview---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").delete(opts)-- filter---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").filter(opts)-- Go to the first item---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").first(opts)-- Focus the trouble window---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").focus(opts)-- Fold close---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_close(opts)-- fold close all---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_close_all(opts)-- Fold close recursive---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_close_recursive(opts)-- fold disable---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_disable(opts)-- fold enable---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_enable(opts)-- fold more---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_more(opts)-- Fold open---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_open(opts)-- fold open all---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_open_all(opts)-- Fold open recursive---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_open_recursive(opts)-- fold reduce---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_reduce(opts)-- Fold toggle---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_toggle(opts)-- fold toggle enable---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_toggle_enable(opts)-- Fold toggle recursive---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_toggle_recursive(opts)-- fold update---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_update(opts)-- fold update all---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").fold_update_all(opts)-- Show the help---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").help(opts)-- Dump the item to the console---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").inspect(opts)-- Jump to the item if on an item, otherwise fold the node---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").jump(opts)-- Jump to the item and close the trouble window---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").jump_close(opts)-- Jump to the item if on an item, otherwise do nothing---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").jump_only(opts)-- Open the item in a split---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").jump_split(opts)-- Open the item in a split and close the trouble window---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").jump_split_close(opts)-- Open the item in a vsplit---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").jump_vsplit(opts)-- Open the item in a vsplit and close the trouble window---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").jump_vsplit_close(opts)-- Go to the last item---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").last(opts)-- Go to the next item---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").next(opts)-- Go to the previous item---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").prev(opts)-- Open the preview---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").preview(opts)-- Refresh the trouble source---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").refresh(opts)-- Toggle the preview---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").toggle_preview(opts)-- Toggle the auto refresh---@paramopts?trouble.Mode| {new? :boolean} |string---@returntrouble.Viewrequire("trouble").toggle_refresh(opts)

Telescope

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

localactions=require("telescope.actions")localopen_with_trouble=require("trouble.sources.telescope").open-- Use this to add more results without clearing the trouble listlocaladd_to_trouble=require("trouble.sources.telescope").addlocaltelescope=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 inTrouble

fzf-lua

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

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

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

Statusline Component

Example forlualine.nvim:

{"nvim-lualine/lualine.nvim",opts=function(_,opts)localtrouble=require("trouble")localsymbols=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 usehl_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 GroupDefault GroupDescription
TroubleBasenameTroubleFilename
TroubleCodeSpecial
TroubleCountTabLineSel
TroubleDirectoryDirectory
TroubleFilenameDirectory
TroubleIconArray@punctuation.bracket
TroubleIconBoolean@boolean
TroubleIconClass@type
TroubleIconConstant@constant
TroubleIconConstructor@constructor
TroubleIconDirectorySpecial
TroubleIconEnum@lsp.type.enum
TroubleIconEnumMember@lsp.type.enumMember
TroubleIconEventSpecial
TroubleIconField@variable.member
TroubleIconFileNormal
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
TroubleIndentLineNr
TroubleIndentFoldClosedCursorLineNr
TroubleIndentFoldOpenTroubleIndent
TroubleIndentLastTroubleIndent
TroubleIndentMiddleTroubleIndent
TroubleIndentTopTroubleIndent
TroubleIndentWsTroubleIndent
TroubleNormalNormalFloat
TroubleNormalNCNormalFloat
TroublePosLineNr
TroublePreviewVisual
TroubleSourceComment
TroubleTextNormal

About

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

Topics

Resources

License

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp