diff --git a/README.md b/README.md index 1588f938..ebe6c788 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 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](https://github.com/folke/trouble.nvim/assets/292349/dd04ebdb-e964-4cfe-a9b1-f694084ca54a) +![image](https://github.com/folke/trouble.nvim/assets/292349/481bc1f7-cb93-432d-8ab6-f54044334b96) ## ✨ Features @@ -73,6 +73,11 @@ Install the plugin with your preferred package manager: "Trouble symbols toggle focus=false", desc = "Symbols (Trouble)", }, + { + "cl", + "Trouble lsp toggle focus=false win.position=right", + desc = "LSP Definitions / references / ... (Trouble)", + }, { "xL", "Trouble loclist toggle", @@ -378,7 +383,7 @@ require("trouble").first(opts) ---@return trouble.View require("trouble").focus(opts) --- Fold close +-- Fold close ---@param opts? trouble.Mode | { new? : boolean } | string ---@return trouble.View require("trouble").fold_close(opts) @@ -408,7 +413,7 @@ require("trouble").fold_enable(opts) ---@return trouble.View require("trouble").fold_more(opts) --- Fold open +-- Fold open ---@param opts? trouble.Mode | { new? : boolean } | string ---@return trouble.View require("trouble").fold_open(opts) @@ -428,7 +433,7 @@ require("trouble").fold_open_recursive(opts) ---@return trouble.View require("trouble").fold_reduce(opts) --- Fold toggle +-- Fold toggle ---@param opts? trouble.Mode | { new? : boolean } | string ---@return trouble.View require("trouble").fold_toggle(opts) @@ -582,50 +587,50 @@ The table below shows all the highlight groups defined for Trouble. -| Highlight Group | Default Group | Description | -| --- | --- | --- | -| **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*** | | -| **TroublePos** | ***LineNr*** | | -| **TroublePreview** | ***Visual*** | | -| **TroubleSource** | ***Comment*** | | -| **TroubleText** | ***Normal*** | | +| Highlight Group | Default Group | Description | +| ---------------------------- | ----------------------------- | ----------- | +| **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_** | | +| **TroublePos** | **_LineNr_** | | +| **TroublePreview** | **_Visual_** | | +| **TroubleSource** | **_Comment_** | | +| **TroubleText** | **_Normal_** | | diff --git a/docs/examples.md b/docs/examples.md index 6ec51283..dd6f9856 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -12,16 +12,14 @@ preview_float = { mode = "diagnostics", preview = { - win = { - type = "float", - relative = "editor", - border = "rounded", - title = "Preview", - title_pos = "center", - position = { 0, -2 }, - size = { width = 0.3, height = 0.3 }, - zindex = 200, - }, + type = "float", + relative = "editor", + border = "rounded", + title = "Preview", + title_pos = "center", + position = { 0, -2 }, + size = { width = 0.3, height = 0.3 }, + zindex = 200, }, }, }, @@ -38,12 +36,10 @@ test = { mode = "diagnostics", preview = { - win = { - type = "split", - relative = "win", - position = "right", - size = 0.3, - }, + type = "split", + relative = "win", + position = "right", + size = 0.3, }, }, }, diff --git a/lua/trouble/api.lua b/lua/trouble/api.lua index 890361e0..78c0602b 100644 --- a/lua/trouble/api.lua +++ b/lua/trouble/api.lua @@ -132,7 +132,7 @@ function M.statusline(opts) local Section = require("trouble.view.section") local Render = require("trouble.view.render") opts = Config.get(opts) - opts.results.indent_guides = false + opts.indent_guides = false opts.icons.indent.ws = "" local renderer = Render.new(opts, { multiline = false, diff --git a/lua/trouble/command.lua b/lua/trouble/command.lua index 66d5f29b..e8305489 100644 --- a/lua/trouble/command.lua +++ b/lua/trouble/command.lua @@ -51,16 +51,16 @@ function M.complete_opts() vim.list_extend(candidates, { "new=true", }) - for _, w in ipairs({ "results", "preview" }) do + for _, w in ipairs({ "win", "preview" }) do local winopts = { - "win.type=float", - "win.type=split", - "win.position=top", - "win.position=bottom", - "win.position=left", - "win.position=right", - "win.relative=editor", - "win.relative=win", + "type=float", + "type=split", + "position=top", + "position=bottom", + "position=left", + "position=right", + "relative=editor", + "relative=win", } vim.list_extend( candidates, diff --git a/lua/trouble/config/actions.lua b/lua/trouble/config/actions.lua index 6becefbf..256854e6 100644 --- a/lua/trouble/config/actions.lua +++ b/lua/trouble/config/actions.lua @@ -34,9 +34,9 @@ local M = { end, -- Toggle the preview toggle_preview = function(self) - self.opts.preview.auto_open = not self.opts.preview.auto_open + self.opts.auto_preview = not self.opts.auto_preview local Preview = require("trouble.view.preview") - if self.opts.preview.auto_open then + if self.opts.auto_preview then self:preview() else Preview.close() @@ -44,7 +44,7 @@ local M = { end, -- Toggle the auto refresh toggle_refresh = function(self) - self.opts.results.auto_refresh = not self.opts.results.auto_refresh + self.opts.auto_refresh = not self.opts.auto_refresh end, -- Show the help help = function(self) diff --git a/lua/trouble/config/init.lua b/lua/trouble/config/init.lua index f0fb538c..630bb8ba 100644 --- a/lua/trouble/config/init.lua +++ b/lua/trouble/config/init.lua @@ -13,26 +13,22 @@ local M = {} ---@field sorters? table custom sorters local defaults = { debug = false, - pinned = false, -- When pinned, the opened trouble window will be bound to the current buffer + 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 focus = false, -- Focus the window when opened follow = true, -- Follow the current item - results = { - ---@type trouble.Window.opts - win = {}, -- window options for the results window. Can be a split or a floating window. - indent_guides = true, -- show indent guides - multiline = true, -- render multi-line messages - max_items = 200, -- limit number of items that can be displayed per section - auto_open = false, -- auto open when there are items - auto_close = false, -- auto close when there are no items - auto_refresh = true, -- auto refresh when open - }, - preview = { - -- 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 - win = { type = "main" }, - auto_open = true, -- automatically open preview when on an 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 + ---@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" }, -- Throttle/Debounce settings. Should usually not be changed. ---@type table throttle = { @@ -89,9 +85,7 @@ local defaults = { desc = "document symbols", mode = "lsp_document_symbols", focus = false, - results = { - win = { position = "right" }, - }, + win = { position = "right" }, filter = { -- remove Package since luals uses it for control flow structures ["not"] = { ft = "lua", kind = "Package" }, diff --git a/lua/trouble/spec.lua b/lua/trouble/spec.lua index 40049456..f5b35665 100644 --- a/lua/trouble/spec.lua +++ b/lua/trouble/spec.lua @@ -94,7 +94,7 @@ function M.sections(mode) end else local section = M.section(mode) - section.max_items = section.max_items or mode.results.max_items + section.max_items = section.max_items or mode.max_items ret[#ret + 1] = section end return ret diff --git a/lua/trouble/view/init.lua b/lua/trouble/view/init.lua index 14c61762..c5e688e9 100644 --- a/lua/trouble/view/init.lua +++ b/lua/trouble/view/init.lua @@ -26,8 +26,8 @@ function M.new(opts) _idx = _idx + 1 M._views[self] = _idx self.opts = opts or {} - self.opts.results.win = self.opts.results.win or {} - self.opts.results.win.on_mount = function() + self.opts.win = self.opts.win or {} + self.opts.win.on_mount = function() self:on_mount() end @@ -40,20 +40,20 @@ function M.new(opts) table.insert(self.sections, section) end - self.win = Window.new(self.opts.results.win) - self.opts.results.win = self.win.opts + self.win = Window.new(self.opts.win) + self.opts.win = self.win.opts - self.preview_win = Window.new(self.opts.preview.win) or nil + self.preview_win = Window.new(self.opts.preview) or nil self.renderer = Render.new(self.opts, { - padding = vim.tbl_get(self.opts.results.win, "padding", "left") or 0, - multiline = self.opts.results.multiline, + padding = vim.tbl_get(self.opts.win, "padding", "left") or 0, + multiline = self.opts.multiline, }) self.update = Util.throttle(M.update, Util.throttle_opts(self.opts.throttle.update, { ms = 10 })) self.render = Util.throttle(M.render, Util.throttle_opts(self.opts.throttle.render, { ms = 10 })) self.follow = Util.throttle(M.follow, Util.throttle_opts(self.opts.throttle.follow, { ms = 10 })) - if self.opts.results.auto_open then + if self.opts.auto_open then self:listen() self:refresh() end @@ -69,7 +69,7 @@ function M.get(filter) local ret = {} for view, idx in pairs(M._views) do local is_open = view.win:valid() - local ok = is_open or view.opts.results.auto_open + local ok = is_open or view.opts.auto_open ok = ok and (not filter.mode or filter.mode == view.opts.mode) ok = ok and (not filter.open or is_open) if ok then @@ -108,7 +108,7 @@ function M:on_mount() if not this then return true end - if this.opts.preview.auto_open then + if this.opts.auto_preview then local loc = this:at() if loc and loc.item then preview(this, loc.item) @@ -317,7 +317,7 @@ end function M:refresh() local is_open = self.win:valid() - if not is_open and not self.opts.results.auto_open then + if not is_open and not self.opts.auto_open then return end for _, section in ipairs(self.sections) do @@ -387,10 +387,10 @@ function M:count() end function M:update() - if self.opts.results.auto_close and self:count() == 0 then + if self.opts.auto_close and self:count() == 0 then return self:close() end - if self.opts.results.auto_open and not self.win:valid() then + if self.opts.auto_open and not self.win:valid() then if self:count() == 0 then return end @@ -408,7 +408,7 @@ function M:render() -- render sections self.renderer:clear() self.renderer:nl() - for _ = 1, vim.tbl_get(self.opts.results.win, "padding", "top") or 0 do + for _ = 1, vim.tbl_get(self.opts.win, "padding", "top") or 0 do self.renderer:nl() end self.renderer:sections(self.sections) diff --git a/lua/trouble/view/preview.lua b/lua/trouble/view/preview.lua index 8f1c31f7..8c00e329 100644 --- a/lua/trouble/view/preview.lua +++ b/lua/trouble/view/preview.lua @@ -102,7 +102,7 @@ end ---@param buf number ---@param view trouble.View function M.preview_win(buf, view) - if view.opts.preview.win.type == "main" then + if view.opts.preview.type == "main" then local main = view:main() if not main then Util.debug("No main window") diff --git a/lua/trouble/view/render.lua b/lua/trouble/view/render.lua index cd7837d7..0d1c6cdf 100644 --- a/lua/trouble/view/render.lua +++ b/lua/trouble/view/render.lua @@ -193,7 +193,7 @@ function M:item(node, section, indent) ---@type TextSegment[]? local segments = not is_group and item.cache[cache_key] - if not self.opts.results.indent_guides then + if not self.opts.indent_guides then indent = indent:indent() end if self._opts.indent ~= false then diff --git a/lua/trouble/view/section.lua b/lua/trouble/view/section.lua index 9549d48f..af41f9f0 100644 --- a/lua/trouble/view/section.lua +++ b/lua/trouble/view/section.lua @@ -124,7 +124,7 @@ function M:listen() if not this then return true end - if not this.opts.results.auto_refresh then + if not this.opts.auto_refresh then return end if event.main then