Skip to content

Commit

Permalink
fix: initialize auto_open. Fixes #489
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 8, 2024
1 parent 3891502 commit 0793267
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lua/trouble/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,23 @@ function M.setup(opts)
return
end
opts = opts or {}

if opts.auto_open then
require("trouble.util").warn({
"You specified `auto_open = true` in your global config.",
"This is probably not what you want.",
"Add it to the mode you want to auto open instead.",
"```lua",
"opts = {",
" modes = {",
" diagnostics = { auto_open = true },",
" }",
"}",
"```",
"Disabling global `auto_open`.",
})
opts.auto_open = nil
end
opts.mode = nil
options = {}
options = M.get(opts)
Expand All @@ -232,6 +249,13 @@ function M.setup(opts)
desc = "Trouble",
})
require("trouble.view.main").setup()
vim.schedule(function()
for mode, mode_opts in pairs(options.modes) do
if mode_opts.auto_open then
require("trouble.view").new(M.get(mode))
end
end
end)
return options
end

Expand Down
5 changes: 5 additions & 0 deletions lua/trouble/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ local _idx = 0
---@type table<trouble.View, number>
M._views = setmetatable({}, { __mode = "k" })

---@type trouble.View[]
M._auto = {}

---@type table<string, trouble.Render.Location>
M._last = {}

Expand Down Expand Up @@ -80,6 +83,8 @@ function M.new(opts)
self.follow = Util.throttle(M.follow, Util.throttle_opts(self.opts.throttle.follow, { ms = 100 }))

if self.opts.auto_open then
-- add to a table, so that the view doesn't gc
table.insert(M._auto, self)
self:listen()
self:refresh()
end
Expand Down

0 comments on commit 0793267

Please sign in to comment.