Skip to content

Commit

Permalink
Use isSelected property in generate constructor to pre-select selecte…
Browse files Browse the repository at this point in the history
…d properties
  • Loading branch information
mfussenegger committed Jun 30, 2022
1 parent 9eb8758 commit 03f64f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lua/jdtls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,14 @@ local function java_generate_constructors_prompt(_, outer_ctx)

local fields = status.fields
if fields then
local opts = {
is_selected = function(item)
return item.isSelected
end
}
fields = ui.pick_many(status.fields, 'Include field to initialize by constructor(s): ', function(x)
return string.format('%s: %s', x.name, x.type)
end)
end, opts)
end

local params = {
Expand Down
14 changes: 12 additions & 2 deletions lua/jdtls/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,29 @@ local function index_of(xs, term)
end


function M.pick_many(items, prompt, label_f)
function M.pick_many(items, prompt, label_f, opts)
if not items or #items == 0 then
return {}
end

label_f = label_f or function(item)
return item
end
opts = opts or {}

local choices = {}
local selected = {}
local is_selected = opts.is_selected or function(_)
return false
end
for i, item in pairs(items) do
table.insert(choices, string.format("%d. %s", i, label_f(item)))
local label = label_f(item)
local choice = string.format("%d. %s", i, label)
if is_selected(item) then
choice = choice .. " *"
table.insert(selected, item)
end
table.insert(choices, choice)
end

while true do
Expand Down

0 comments on commit 03f64f1

Please sign in to comment.