Skip to content

Commit

Permalink
refactor: opts.results.* -> opts.*, preview.win => preview, `…
Browse files Browse the repository at this point in the history
…preview.auto_open` => `auto_preview`
  • Loading branch information
folke committed Mar 29, 2024
1 parent 151ef73 commit 9c7f0a6
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 116 deletions.
101 changes: 53 additions & 48 deletions README.md
Expand Up @@ -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

Expand Down Expand Up @@ -73,6 +73,11 @@ Install the plugin with your preferred package manager:
"<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>",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -582,50 +587,50 @@ The table below shows all the highlight groups defined for Trouble.

<!-- colors:start -->

| 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_** | |

<!-- colors:end -->

Expand Down
28 changes: 12 additions & 16 deletions docs/examples.md
Expand Up @@ -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,
},
},
},
Expand All @@ -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,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion lua/trouble/api.lua
Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions lua/trouble/command.lua
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions lua/trouble/config/actions.lua
Expand Up @@ -34,17 +34,17 @@ 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()
end
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)
Expand Down
36 changes: 15 additions & 21 deletions lua/trouble/config/init.lua
Expand Up @@ -13,26 +13,22 @@ local M = {}
---@field sorters? table<string, trouble.SorterFn> 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<string, number|{ms:number, debounce?:boolean}>
throttle = {
Expand Down Expand Up @@ -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" },
Expand Down
2 changes: 1 addition & 1 deletion lua/trouble/spec.lua
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions lua/trouble/view/init.lua
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lua/trouble/view/preview.lua
Expand Up @@ -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")
Expand Down

0 comments on commit 9c7f0a6

Please sign in to comment.