2021-04-19 02:56:32 +00:00
|
|
|
local M = {}
|
2021-12-12 23:42:53 +00:00
|
|
|
local ListView = require('guihua.listview')
|
|
|
|
local TextView = require('guihua.textview')
|
|
|
|
local util = require('navigator.util')
|
2021-12-13 06:43:51 +00:00
|
|
|
local log = util.log
|
2021-12-12 23:42:53 +00:00
|
|
|
local trace = require('navigator.util').trace
|
2021-04-20 07:42:03 +00:00
|
|
|
local api = vim.api
|
2021-12-30 05:05:25 +00:00
|
|
|
local active_list_view -- only one listview at a time
|
2021-04-19 02:56:32 +00:00
|
|
|
|
|
|
|
function M.new_list_view(opts)
|
2022-06-01 15:41:26 +00:00
|
|
|
-- log(opts)
|
2021-12-12 23:42:53 +00:00
|
|
|
local config = require('navigator').config_values()
|
2021-04-25 02:43:18 +00:00
|
|
|
|
2021-12-30 05:05:25 +00:00
|
|
|
if active_list_view ~= nil then
|
2022-02-17 11:21:34 +00:00
|
|
|
trace(active_list_view)
|
2021-12-30 05:05:25 +00:00
|
|
|
local winnr = active_list_view.win
|
|
|
|
local bufnr = active_list_view.buf
|
|
|
|
|
|
|
|
if bufnr and vim.api.nvim_buf_is_valid(bufnr) and winnr and vim.api.nvim_win_is_valid(winnr) then
|
|
|
|
log('list view already present')
|
2022-01-09 14:52:32 +00:00
|
|
|
return active_list_view
|
2021-12-30 05:05:25 +00:00
|
|
|
end
|
|
|
|
end
|
2021-04-19 02:56:32 +00:00
|
|
|
local items = opts.items
|
2021-06-25 10:18:55 +00:00
|
|
|
|
2021-12-12 23:42:53 +00:00
|
|
|
opts.min_width = opts.min_width or 0.3
|
|
|
|
opts.min_height = opts.min_height or 0.3
|
|
|
|
|
|
|
|
opts.height_ratio = config.height
|
|
|
|
opts.width_ratio = config.width
|
|
|
|
opts.preview_height_ratio = _NgConfigValues.preview_height or 0.3
|
|
|
|
opts.preview_lines = _NgConfigValues.preview_lines
|
2021-05-17 03:15:15 +00:00
|
|
|
if opts.rawdata then
|
2021-12-12 23:42:53 +00:00
|
|
|
opts.data = items
|
2021-05-17 03:15:15 +00:00
|
|
|
else
|
2021-12-12 23:42:53 +00:00
|
|
|
opts.data = require('navigator.render').prepare_for_render(items, opts)
|
2021-05-17 03:15:15 +00:00
|
|
|
end
|
2021-12-12 23:42:53 +00:00
|
|
|
opts.border = _NgConfigValues.border or 'shadow'
|
2022-06-01 15:41:26 +00:00
|
|
|
if vim.fn.hlID('TelescopePromptBorder') > 0 then
|
|
|
|
opts.border_hl = 'TelescopePromptBorder'
|
|
|
|
end
|
2021-12-12 23:42:53 +00:00
|
|
|
if not items or vim.tbl_isempty(items) then
|
|
|
|
log('empty data return')
|
2021-09-13 13:18:54 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2021-12-12 23:42:53 +00:00
|
|
|
opts.transparency = _NgConfigValues.transparency
|
2022-01-08 11:47:43 +00:00
|
|
|
if #items >= _NgConfigValues.lines_show_prompt then
|
|
|
|
opts.prompt = true
|
|
|
|
end
|
|
|
|
|
2021-12-12 23:42:53 +00:00
|
|
|
opts.external = _NgConfigValues.external
|
|
|
|
opts.preview_lines_before = 3
|
2022-06-01 15:41:26 +00:00
|
|
|
log(opts)
|
2021-12-30 05:05:25 +00:00
|
|
|
active_list_view = require('guihua.gui').new_list_view(opts)
|
|
|
|
return active_list_view
|
2021-04-19 02:56:32 +00:00
|
|
|
end
|
|
|
|
|
2021-12-16 21:54:36 +00:00
|
|
|
function M.select(items, opts, on_choice)
|
|
|
|
end
|
|
|
|
|
2021-04-19 02:56:32 +00:00
|
|
|
return M
|
2021-05-17 03:15:15 +00:00
|
|
|
|
|
|
|
-- Doc
|
|
|
|
|
|
|
|
--[[
|
|
|
|
-- each item should look like this
|
|
|
|
-- update if API changes
|
|
|
|
{
|
|
|
|
call_by = { <table 1> },
|
|
|
|
col = 40,
|
|
|
|
display_filename = "./curry.js",
|
2021-08-10 05:27:20 +00:00
|
|
|
filename = "/Users/username/lsp_test/js/curry.js",
|
2021-05-17 03:15:15 +00:00
|
|
|
lnum = 4,
|
|
|
|
range = {
|
|
|
|
end = {
|
|
|
|
character = 46,
|
|
|
|
line = 3 -- note: C index
|
|
|
|
},
|
|
|
|
start = {
|
|
|
|
character = 39,
|
|
|
|
line = 3
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rpath = "js/curry.js",
|
|
|
|
text = " (sum, element, index) => (sum += element * vector2[index]),",
|
2021-08-10 05:27:20 +00:00
|
|
|
uri = "file:///Users/username/lsp_test/js/curry.js"
|
2021-05-17 03:15:15 +00:00
|
|
|
}
|
|
|
|
--]]
|
|
|
|
|
|
|
|
-- on move item:
|
|
|
|
--[[
|
|
|
|
|
|
|
|
call_by = { {
|
|
|
|
kind = " ",
|
|
|
|
node_scope = {
|
|
|
|
end = {
|
|
|
|
character = 1,
|
|
|
|
line = 7
|
|
|
|
},
|
|
|
|
start = {
|
|
|
|
character = 0,
|
|
|
|
line = 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
node_text = "curriedDot",
|
|
|
|
type = "var"
|
|
|
|
} },
|
|
|
|
col = 22,
|
|
|
|
display_filename = "./curry.js",
|
2021-08-10 05:27:20 +00:00
|
|
|
filename = "/Users/username/lsp_test/js/curry.js",
|
2021-05-17 03:15:15 +00:00
|
|
|
lnum = 4,
|
|
|
|
range = {
|
|
|
|
end = {
|
|
|
|
character = 26,
|
|
|
|
line = 3
|
|
|
|
},
|
|
|
|
start = {
|
|
|
|
character = 21,
|
|
|
|
line = 3
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rpath = "js/curry.js",
|
|
|
|
text = " 4: (sum, element, index) => (sum += element * vector curriedDot()",
|
2021-08-10 05:27:20 +00:00
|
|
|
uri = "file:///Users/username/lsp_test/js/curry.js"
|
2021-05-17 03:15:15 +00:00
|
|
|
--
|
|
|
|
]]
|