Update UI for code lens

neovim_0_5
ray-x 3 years ago
parent 58ac955777
commit a200c1db2b

@ -97,15 +97,17 @@ function M.run_action()
end end
local width = 40 local width = 40
local data = {"  Auto Fix <C-o> Apply <C-e> Exit"} local data = {"  CodeLens Action <C-o> Apply <C-e> Exit"}
local idx = 1
for i, lens in pairs(lenses) do for i, lens in pairs(lenses) do
if lens.range.start.line == (line - 1) then if lens.range.start.line == (line - 1) then
local title = lens.command.title:gsub("\r\n", "\\r\\n") local title = lens.command.title:gsub("\r\n", "\\r\\n")
title = title:gsub("\n", "\\n") title = title:gsub("\n", "\\n")
title = string.format("[%d] %s", i, title) title = string.format("[%d] %s", idx, title)
table.insert(data, title) table.insert(data, title)
lenses[i].display_title = title lenses[i].display_title = title
width = math.max(width, #lens.command.title) width = math.max(width, #lens.command.title)
idx = idx + 1
end end
end end
local apply = require('navigator.lspwrapper').apply_action local apply = require('navigator.lspwrapper').apply_action
@ -122,24 +124,24 @@ function M.run_action()
end end
apply(action_chosen) apply(action_chosen)
end end
if #data > 0 then
gui.new_list_view { gui.new_list_view {
items = data, items = data,
width = width + 4, width = width + 4,
loc = "top_center", loc = "top_center",
relative = "cursor", relative = "cursor",
rawdata = true, rawdata = true,
data = data, data = data,
on_confirm = function(pos) on_confirm = function(pos)
log(pos) log(pos)
apply_action(pos) apply_action(pos)
end, end,
on_move = function(pos) on_move = function(pos)
log(pos) log(pos)
return pos return pos
end end
} }
end
end end
return M return M

@ -319,10 +319,7 @@ end
function M.apply_action(action_chosen) function M.apply_action(action_chosen)
assert(action_chosen ~= nil, "action must not be nil") assert(action_chosen ~= nil, "action must not be nil")
if action_chosen == nil then local bufnr = api.nvim_get_current_buf()
log("no match for ", action, lenses)
return
end
local switch = string.format("silent b %d", bufnr) local switch = string.format("silent b %d", bufnr)
if action_chosen.edit or type(action_chosen.command) == "table" then if action_chosen.edit or type(action_chosen.command) == "table" then
if action_chosen.edit then if action_chosen.edit then

Loading…
Cancel
Save