Skip to content

Commit

Permalink
feat: allow proper passing of plugin options
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 26, 2021
1 parent c94cc59 commit 79513ed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions lua/trouble/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ M.namespace = vim.api.nvim_create_namespace("Trouble")
-- TODO: make it possible to have multiple trouble lists open at the same time
local defaults = {
debug = false,
cmd_options = {},
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
Expand Down
28 changes: 20 additions & 8 deletions lua/trouble/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,29 @@ function Trouble.close()
end
end

local function get_opts(opts)
opts = opts or {}
if type(opts) == "string" then
opts = { mode = opts }
local function get_opts(...)
local args = { ... }
local opts = {}
for key, value in pairs(args) do
if type(key) == "number" then
local k, v = value:match("^(.*)=(.*)$")
if k then
opts[k] = v
elseif opts.mode then
util.error("unknown option " .. value)
else
opts.mode = value
end
end
end
opts = opts or {}
config.fix_mode(opts)
config.options.cmd_options = opts
return opts
end

function Trouble.open(opts)
opts = get_opts(opts)
function Trouble.open(...)
local opts = get_opts(...)
if opts.mode and (opts.mode ~= config.options.mode) then
config.options.mode = opts.mode
end
Expand All @@ -47,8 +59,8 @@ function Trouble.open(opts)
end
end

function Trouble.toggle(opts)
opts = get_opts(opts)
function Trouble.toggle(...)
local opts = get_opts(...)

if opts.mode and (opts.mode ~= config.options.mode) then
config.options.mode = opts.mode
Expand Down

0 comments on commit 79513ed

Please sign in to comment.